zoukankan      html  css  js  c++  java
  • 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:

     

  • 相关阅读:
    Java实现 蓝桥杯VIP 算法提高 11-2删除重复元素
    Java实现 蓝桥杯VIP 算法提高 11-2删除重复元素
    Java实现 蓝桥杯VIP 算法提高 11-2删除重复元素
    Java实现 蓝桥杯VIP 算法提高 P0401
    Java实现 蓝桥杯VIP 算法提高 P0401
    Java实现 蓝桥杯VIP 算法提高 P0401
    Java实现 蓝桥杯VIP 算法提高 P0401
    Java实现 蓝桥杯VIP 算法提高 P0401
    QApplication::alert 如果窗口不是活动窗口,则会向窗口显示一个警告(非常好用,效果就和TeamViewer一样)
    QString::toWCharArray可以拷贝到宽字符串里
  • 原文地址:https://www.cnblogs.com/jinzhao/p/2233079.html
Copyright © 2011-2022 走看看