本文整理汇总了C#中Builder.CreateListOfSize方法的典型用法代码示例。如果您正苦于以下问题:C# Builder.CreateListOfSize方法的具体用法?C# Builder.CreateListOfSize怎么用?C# Builder.CreateListOfSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Builder
的用法示例。
在下文中一共展示了Builder.CreateListOfSize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PersistingAListOfProductsAndCategories
public void PersistingAListOfProductsAndCategories()
{
const int numProducts = 500;
const int numCategories = 50;
const int numCategoriesForEachProduct = 5;
var builder = new Builder(builderSettings);
var categories = builder
.CreateListOfSize<Category>(numCategories)
.Persist();
builder
.CreateListOfSize<Product>(numProducts)
.All()
.With(x => x.Categories = Pick<Category>.
UniqueRandomList(With.Exactly(numCategoriesForEachProduct).Elements)
.From(categories)
.ToList())
.Persist(); // NB: Persistence is setup in the RepositoryBuilderSetup class
DataTable productsTable = Database.GetContentsOf(Database.Tables.Product);
DataTable categoriesTable = Database.GetContentsOf(Database.Tables.Category);
DataTable productCategoriesTable = Database.GetContentsOf(Database.Tables.ProductCategory);
Assert.That(productsTable.Rows.Count, Is.EqualTo(numProducts), "products");
Assert.That(categoriesTable.Rows.Count, Is.EqualTo(numCategories), "categories");
Assert.That(productCategoriesTable.Rows.Count, Is.EqualTo(numCategoriesForEachProduct * numProducts));
}
示例2: PersistingASingleTaxTypeAndAListOf100Products
public void PersistingASingleTaxTypeAndAListOf100Products()
{
var builder = new Builder(builderSettings);
var taxType = builder.CreateNew<TaxType>().Persist();
builder.CreateListOfSize<Product>(100)
.All()
.With(x => x.TaxType = taxType)
.Persist(); // NB: Persistence is setup in the RepositoryBuilderSetup class
var dbProducts = Database.GetContentsOf(Database.Tables.Product);
Assert.That(dbProducts.Rows.Count, Is.EqualTo(100));
}
示例3: CreatingAHierarchyOfCategoriesUsingRepositories
public void CreatingAHierarchyOfCategoriesUsingRepositories()
{
var builderSetup = new RepositoryBuilderSetup().SetUp();
const int depth = 3;
const int minChildren = 3;
const int maxChildren = 8;
var builder = new Builder(builderSetup);
var hierarchySpec = builder.CreateNew<HierarchySpec<Category>>()
.With(x => x.AddMethod = (parent, child) => parent.AddChild(child))
.With(x => x.Depth = depth)
.With(x => x.MinimumChildren = minChildren)
.With(x => x.MaximumChildren = maxChildren)
.With(x => x.NamingMethod = (parent, child) => parent.Title = "Category " + child)
.With(x => x.NumberOfRoots = 5)
.Build();
var categories = builder
.CreateListOfSize<Category>(10000)
.All()
.PersistHierarchy(hierarchySpec);
foreach (var root in categories)
{
Assert.That(root.Children.Count, Is.AtLeast(minChildren));
Assert.That(root.Children.Count, Is.AtMost(maxChildren));
foreach (var child1 in root.Children)
{
Assert.That(child1.Children.Count, Is.AtLeast(minChildren));
Assert.That(child1.Children.Count, Is.AtMost(maxChildren));
foreach (var child2 in child1.Children)
{
Assert.That(child2.Children.Count, Is.AtLeast(minChildren));
Assert.That(child2.Children.Count, Is.AtMost(maxChildren));
}
}
}
}
示例4: PersistingUsingPick_UpTo_AndDoForEach
public void PersistingUsingPick_UpTo_AndDoForEach()
{
var builder = new Builder(builderSettings);
var categories = builder.CreateListOfSize<Category>(10).Persist();
builder
.CreateListOfSize<Product>(50)
.All()
.DoForEach((x, y) => x.AddToCategory(y), Pick<Category>.UniqueRandomList(With.UpTo(4).Elements).From(categories))
.Persist();
DataTable productCategoriesTable = Database.GetContentsOf(Database.Tables.ProductCategory);
Assert.That(productCategoriesTable.Rows.Count, Is.LessThanOrEqualTo(50 * 4));
}
示例5: UsingMultiFunctions
public void UsingMultiFunctions()
{
var builderSetup = new BuilderSettings();
var builder = new Builder(builderSetup);
var categories = builder.CreateListOfSize< Category>(5).Build();
var product = builder
.CreateNew< Product>()
.DoForAll( (prod, cat) => prod.AddToCategory(cat), categories)
.Build();
// Assertions are intentionally verbose for clarity
Assert.That(product.Categories.Count, Is.EqualTo(5));
Assert.That(product.Categories[0], Is.EqualTo(categories[0]));
Assert.That(product.Categories[1], Is.EqualTo(categories[1]));
Assert.That(product.Categories[2], Is.EqualTo(categories[2]));
Assert.That(product.Categories[3], Is.EqualTo(categories[3]));
Assert.That(product.Categories[4], Is.EqualTo(categories[4]));
}
示例6: CreatingAListOfATypeWithAConstructor
public void CreatingAListOfATypeWithAConstructor()
{
var builderSetup = new BuilderSettings();
// ctor: BasketItem(ShoppingBasket basket, Product product, int quantity)
var builder = new Builder(builderSetup);
var basket = builder.CreateNew<ShoppingBasket>().Build();
var product = builder.CreateNew<Product>().Build();
const int quantity = 5;
var basketItems =
builder.CreateListOfSize<BasketItem>(10)
.All()
.WithConstructor(() => new BasketItem(basket, product, quantity)) // passes these arguments to the constructor
.Build();
foreach (var basketItem in basketItems)
{
Assert.That(basketItem.Basket, Is.EqualTo(basket));
Assert.That(basketItem.Product, Is.EqualTo(product));
Assert.That(basketItem.Quantity, Is.EqualTo(quantity));
}
}
示例7: UsingTheWithBetween_And_SyntaxForGreaterReadability
public void UsingTheWithBetween_And_SyntaxForGreaterReadability()
{
var builderSetup = new BuilderSettings();
var builder = new Builder(builderSetup);
var categories = builder.CreateListOfSize<Category>(50).Build();
var products = builder
.CreateListOfSize<Product>(500)
.All()
.With(x => x.Categories = Pick<Category>.UniqueRandomList(With.Between(5).And(10).Elements).From(categories).ToList())
.Build();
foreach (var product in products)
{
Assert.That(product.Categories.Count, Is.AtLeast(5));
Assert.That(product.Categories.Count, Is.AtMost(10));
}
}
示例8: UsingDo
public void UsingDo()
{
var builder = new Builder();
var children = builder.CreateListOfSize< Category>(3).Build();
var categories = builder
.CreateListOfSize< Category>(10)
.TheFirst(2)
.Do(x => x.AddChild(children[0]))
.And(x => x.AddChild(children[1]))
.TheNext(2)
.Do(x => x.AddChild(children[2]))
.Build();
Assert.That(categories[0].Children[0], Is.EqualTo(children[0]));
Assert.That(categories[0].Children[1], Is.EqualTo(children[1]));
Assert.That(categories[1].Children[0], Is.EqualTo(children[0]));
Assert.That(categories[1].Children[1], Is.EqualTo(children[1]));
Assert.That(categories[2].Children[0], Is.EqualTo(children[2]));
Assert.That(categories[3].Children[0], Is.EqualTo(children[2]));
}
示例9: CreatingAListOfProductsAndAddingThemToCategories
public void CreatingAListOfProductsAndAddingThemToCategories()
{
var builderSetup = new BuilderSettings();
var builder = new Builder(builderSetup);
var categories = builder.CreateListOfSize< Category>(50).Build();
var products = builder
.CreateListOfSize<Product>(500)
.All()
.With(x => x.Categories = Pick<Category>.UniqueRandomList(With.Between(5, 10).Elements).From(categories).ToList())
.Build();
foreach (var product in products)
{
Assert.That(product.Categories.Count, Is.AtLeast(5));
Assert.That(product.Categories.Count, Is.AtMost(10));
}
}