NBuilder 快速构建测试数据
What is it?
Through a fluent, extensible interface, NBuilder allows you to rapidly create test data, automatically assigning values to properties and public fields that are of type of the built in .NET data types (e.g. ints and strings). NBuilder allows you to override for properties you are interested in using lambda expressions.
NBuilder is an open source project, hosted on google code
Some quick examples
Example #1
1 2 3 4 | var products = Builder<Product>.CreateListOfSize(10) .TheFirst(2) .With(x => x.Title = "special title" ) .Build(); |
Would give you something like this:
Example #2
1 2 3 4 5 6 7 | var products = Builder<Product>.CreateListOfSize(10) .All() .WithConstructor(() => new Product( "my title" )) .Random(5) .WithConstructor(() => new Product( "my other title" )) .And(x => x.Created = August.The17th.At(09, 00)) .Build(); |
Would give you something like this:
Example #3
1 2 3 4 5 6 7 8 9 10 11 12 | var generator = new UniqueRandomGenerator(); var products = Builder<Product>.CreateListOfSize(10) .TheFirst(2) .With(x => x.Title = "special title 1" ) .And(x => x.Description = "special description 1" ) .TheNext(3) .With(x => x.Title = "special title 2" ) .TheNext(5) .With(x => x.Title = "special title 3" ) .And(x => x.Price = generator.Next(0m, 10m)) .Build(); |
Would give you something like this:
作者:today4king
出处:https://www.cnblogs.com/jinzhao/archive/2011/11/02/2233079.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
分类:
学习笔记
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
2009-11-02 接口和类混合继承的问题