Пример #1
0
        public void PersistingAListOfProductsAndCategories()
        {
            var       builderSetup  = new RepositoryBuilderSetup().SetUp();
            const int numProducts   = 500;
            const int numCategories = 50;
            const int numCategoriesForEachProduct = 5;

            var categories = new Builder(builderSetup)
                             .CreateListOfSize <Category>(numCategories)
                             .Persist();

            new Builder(builderSetup)
            .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));
        }
        public void PersistingAListOfProductsAndCategories()
        {
            var builderSetup = new RepositoryBuilderSetup().SetUp();
            const int numProducts = 500;
            const int numCategories = 50;
            const int numCategoriesForEachProduct = 5;

            var categories = new Builder(builderSetup)
                .CreateListOfSize< Category>(numCategories)
                .Persist();

            new Builder(builderSetup)
                 .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));
        }
        public void PersistingASingleTaxTypeAndAListOf100Products()
        {
            var builderSetup = new RepositoryBuilderSetup().SetUp();
            var taxType = new Builder(builderSetup).CreateNew< TaxType>().Persist();

            new Builder(builderSetup).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));
        }
Пример #4
0
        public void PersistingASingleTaxTypeAndAListOf100Products()
        {
            var builderSetup = new RepositoryBuilderSetup().SetUp();
            var taxType      = new Builder(builderSetup).CreateNew <TaxType>().Persist();

            new Builder(builderSetup).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));
        }
        public void PersistingASingleObject()
        {
            var builderSetup =new RepositoryBuilderSetup().SetUp();
            new Builder(builderSetup).CreateNew< Product>().Persist();

            // Go directly to the database to do some asserts
            var dataTable = Database.GetContentsOf(Database.Tables.Product);

            Assert.That(dataTable.Rows.Count, Is.EqualTo(1));

            Assert.That(dataTable.Rows[0]["Title"], Is.EqualTo("Title1"));
            Assert.That(dataTable.Rows[0]["Description"], Is.EqualTo("Description1"));
            Assert.That(dataTable.Rows[0]["PriceBeforeTax"], Is.EqualTo(1m));
            Assert.That(dataTable.Rows[0]["QuantityInStock"], Is.EqualTo(1));
        }
Пример #6
0
        public void PersistingUsingPick_UpTo_AndDoForEach()
        {
            var builderSetup = new RepositoryBuilderSetup().SetUp();
            var categories   = new Builder(builderSetup).CreateListOfSize <Category>(10).Persist();

            new Builder(builderSetup)
            .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));
        }
Пример #7
0
        public void PersistingASingleObject()
        {
            var builderSetup = new RepositoryBuilderSetup().SetUp();

            new Builder(builderSetup).CreateNew <Product>().Persist();

            // Go directly to the database to do some asserts
            var dataTable = Database.GetContentsOf(Database.Tables.Product);

            Assert.That(dataTable.Rows.Count, Is.EqualTo(1));

            Assert.That(dataTable.Rows[0]["Title"], Is.EqualTo("Title1"));
            Assert.That(dataTable.Rows[0]["Description"], Is.EqualTo("Description1"));
            Assert.That(dataTable.Rows[0]["PriceBeforeTax"], Is.EqualTo(1m));
            Assert.That(dataTable.Rows[0]["QuantityInStock"], Is.EqualTo(1));
        }
Пример #8
0
        public void AddingACustom_With_ExtensionForProducts()
        {
            BuilderSettings builderSettings = new RepositoryBuilderSetup().DoSetup();
            var             products        = new Builder(builderSettings)
                                              .CreateListOfSize <Product>(10)
                                              .All()
                                              .WithWarehouseLocations() // This will only appear when using Builder<Product>
                                              .Build();

            Assert.That(products[0].Location.Aisle, Is.EqualTo('A'));
            Assert.That(products[0].Location.Shelf, Is.EqualTo(1));
            Assert.That(products[0].Location.Location, Is.EqualTo(7500));

            Assert.That(products[9].Location.Aisle, Is.EqualTo('J'));
            Assert.That(products[9].Location.Shelf, Is.EqualTo(10));
            Assert.That(products[9].Location.Location, Is.EqualTo(16500));
        }
Пример #9
0
        public void SpecifyingACustomPropertyNamerForASpecificType()
        {
            BuilderSettings builderSettings = new RepositoryBuilderSetup().DoSetup();

            builderSettings.SetPropertyNamerFor <Product>(new CustomProductPropertyNamer(new ReflectionUtil(), builderSettings));

            var products = new Builder(builderSettings).CreateListOfSize <Product>(10).Build();

            Assert.That(products[0].Location.Aisle, Is.EqualTo('A'));
            Assert.That(products[0].Location.Shelf, Is.EqualTo(2));
            Assert.That(products[0].Location.Location, Is.EqualTo(1000));

            Assert.That(products[9].Location.Aisle, Is.EqualTo('J'));
            Assert.That(products[9].Location.Shelf, Is.EqualTo(20));
            Assert.That(products[9].Location.Location, Is.EqualTo(10000));

            // Reset it afterwards so the other tests work as expected
            builderSettings.ResetToDefaults();
        }
Пример #10
0
        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));
                    }
                }
            }
        }
Пример #11
0
        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));
                    }
                }
            }
        }
        public void PersistingUsingPick_UpTo_AndDoForEach()
        {
            var builderSetup = new RepositoryBuilderSetup().SetUp();
            var categories = new Builder(builderSetup).CreateListOfSize< Category>(10).Persist();

            new Builder(builderSetup)
                .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));
        }