Example #1
0
        public RandomContactGenerator()
        {
            BuilderSetup.DisablePropertyNamingFor <Contact, int>(x => x.Id);

            _nameGenerator    = new NameGenerator();
            _surnameGenerator = new SurnameGenerator();
        }
Example #2
0
        public void ShouldBeAbleToDisableAutomaticPropertyNamingForASpecificFieldOfASpecificType()
        {
            BuilderSetup.DisablePropertyNamingFor <MyClass, int>(x => x.Int);

            var obj = Builder <MyClass> .CreateNew().Build();

            Assert.That(obj.Int, Is.EqualTo(0));
            Assert.That(obj.Long, Is.EqualTo(1));
        }
        public void ShouldBeAbleToDisableAutomaticPropertyNamingForASpecificFieldOfASpecificType()
        {
            var builderSetup = new BuilderSetup();
            builderSetup.DisablePropertyNamingFor<MyClass, int>(x => x.Int);

            var obj = new Builder<MyClass>(builderSetup).CreateNew().Build();

            Assert.That(obj.Int, Is.EqualTo(0));
            Assert.That(obj.Long, Is.EqualTo(1));
        }
Example #4
0
        public void ItIsPossibleToSwitchOffAutomaticPropertyNamingForASinglePropertyOfASpecificType()
        {
            BuilderSetup.DisablePropertyNamingFor <Product, int>(x => x.Id);

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

            // The Product.Id will always be its default value
            Assert.That(products[0].Id, Is.EqualTo(0));
            Assert.That(products[9].Id, Is.EqualTo(0));

            // Other properties are still given automatic values as normal
            Assert.That(products[0].QuantityInStock, Is.EqualTo(1));
            Assert.That(products[9].QuantityInStock, Is.EqualTo(10));
        }
Example #5
0
        public void SetValuesOf_IgnoredProperty_HonorsIgnore()
        {
            // Arrange
            var myClass = new MyClass();

            BuilderSetup.DisablePropertyNamingFor <MyClass, long>(x => x.Long);

            target.NameWith <long>(() => 50);

            // Act
            target.SetValuesOf(myClass);

            // Assert
            Assert.That(myClass.Long, Is.EqualTo(default(long)));
        }
Example #6
0
        private List <TestProduct> TestProducts()
        {
            BuilderSetup.DisablePropertyNamingFor <TestProduct, int>(x => x.Id);
            var productList = Builder <TestProduct> .CreateListOfSize(20)
                              .TheFirst(5)
                              .With(x => x.CategoryId = 1)
                              .With(x => x.InStock    = true)
                              .With(x => x.Stock      = 300)
                              .TheNext(5)
                              .With(x => x.InStock    = false)
                              .With(x => x.CategoryId = 2)
                              .With(y => y.Stock      = 0)
                              .Build();

            return(productList.ToList());
        }
Example #7
0
        public void ShouldInsertMultipleProductsByList()
        {
            BuilderSetup.DisablePropertyNamingFor <TestProduct, int>(x => x.Id);
            var products = Builder <TestProduct> .CreateListOfSize(3)
                           .TheFirst(3)
                           .With(x => x.CategoryId = 1)
                           .Build();

            using var uow = new UnitOfWork <TestDbContext>(_fixture.Context);
            var repo = uow.GetRepository <TestProduct>();

            repo.Insert(products);
            uow.Commit();
            var numberOfItems = repo.Select().Count;

            Assert.Equal(23, numberOfItems);
        }
        public async Task ShouldInsertNewProductndReturnCreatedEntity()
        {
            BuilderSetup.DisablePropertyNamingFor <TestProduct, int>(x => x.Id);
            var prod = Builder <TestProduct> .CreateNew().With(x => x.Name = "Cool Product").With(x => x.CategoryId = 1)
                       .Build();

            using var uow = new UnitOfWork <TestDbContext>(_fixture.Context);

            var repo = uow.GetRepositoryAsync <TestProduct>();

            var newProduct = await repo.InsertAsync(prod);

            await uow.CommitAsync();

            Assert.NotNull(newProduct);
            Assert.IsAssignableFrom <TestProduct>(newProduct.Entity);
            Assert.Equal(21, newProduct.Entity.Id);
        }
Example #9
0
        public void should_be_able_to_disable_property_naming_for_an_inherited_property()
        {
            try
            {
                BuilderSetup.DisablePropertyNamingFor <MyConcreteClass, int>(x => x.PropertyInAbstractClass);

                var list = Builder <MyConcreteClass> .CreateListOfSize(10).Build();

                Assert.That(list[0].PropertyInAbstractClass, Is.EqualTo(0));
                Assert.That(list[0].PropertyInInheritedClass, Is.EqualTo(1));

                Assert.That(list[9].PropertyInAbstractClass, Is.EqualTo(0));
                Assert.That(list[9].PropertyInInheritedClass, Is.EqualTo(10));
            }
            finally
            {
                BuilderSetup.ResetToDefaults();
            }
        }
Example #10
0
        public void ShouldBeAbleToDisableAutomaticPropertyNamingForASpecificFieldOfASpecificType()
        {
            try
            {
                BuilderSetup.DisablePropertyNamingFor <MyClass, int>(x => x.Int);

                var list = Builder <MyClass> .CreateListOfSize(10).Build();

                Assert.That(list[0].Int, Is.EqualTo(0));
                Assert.That(list[0].Long, Is.EqualTo(1));

                Assert.That(list[9].Int, Is.EqualTo(0));
                Assert.That(list[9].Long, Is.EqualTo(10));
            }
            finally
            {
                BuilderSetup.ResetToDefaults();
            }
        }
Example #11
0
        public void ShouldInsertMultipleProductsByParams()
        {
            BuilderSetup.DisablePropertyNamingFor <TestProduct, int>(x => x.Id);

            var product1 = Builder <TestProduct> .CreateNew().Build();

            var product2 = Builder <TestProduct> .CreateNew().Build();

            using var uow = new UnitOfWork <TestDbContext>(_fixture.Context);
            var repo = uow.GetRepository <TestProduct>();

            repo.Insert(product1, product2);

            uow.Commit();

            var numberOfItems = repo.Select().Count;

            Assert.Equal(22, numberOfItems);
        }
Example #12
0
        public override void Up()
        {
            Delete.FromTable("Tasks").AllRows();

            BuilderSetup.DisablePropertyNamingFor <Task, int?>(x => x.Id);
            BuilderSetup.SetCreatePersistenceMethod <IList <Task> >(tasks =>
                                                                    tasks.ToList().ForEach(task =>
                                                                                           Insert.IntoTable("Tasks").Row(new
            {
                // NOTE: Add in columns with int conversion
                Name = task.Name,
                //IsCompleted = task.IsCompleted,
                Priority = (int)task.Priority,
                Status   = (int)task.Status,
            })));

            Builder <Task> .CreateListOfSize(5)
            .Persist();
        }
Example #13
0
        public static void SeedData(MetasiteDbContext context)
        {
            if (!context.SiteClients.Any())
            {
                var generator = new RandomGenerator();

                BuilderSetup.DisablePropertyNamingFor <SiteClient, int>(x => x.SiteClientId);
                var siteClients = Builder <SiteClient> .CreateListOfSize(100)
                                  .All()
                                  .With(c => c.Msisdn = (37060000000 + generator.Next(1, 9999999)).ToString())
                                  .Build();

                context.SiteClients.AddRange(siteClients.ToArray());
                context.SaveChanges();

                siteClients = context.SiteClients.ToArray();

                BuilderSetup.DisablePropertyNamingFor <Sms, int>(x => x.SmsId);
                var smss = Builder <Sms> .CreateListOfSize(500)
                           .All()
                           .With(x => x.SiteClient = RandomItemFromSiteClients(siteClients))
                           .With(x => x.Date       = RandomDate(generator))
                           .Build();

                context.SmsMessages.AddRange(smss.ToArray());
                context.SaveChanges();

                BuilderSetup.DisablePropertyNamingFor <Call, int>(x => x.CallId);
                var calls = Builder <Call> .CreateListOfSize(500)
                            .All()
                            .With(x => x.SiteClient = RandomItemFromSiteClients(siteClients))
                            .With(x => x.Date       = RandomDate(generator))
                            .With(x => x.Duration   = generator.Next(5, 1200))
                            .Build();

                context.Calls.AddRange(calls.ToArray());
                context.SaveChanges();
            }
        }
Example #14
0
        public ImportacaoTest()
        {
            BuilderSetup.ResetToDefaults();

            var namer = new RandomValuePropertyNamer(
                new RandomGenerator(),
                new ReflectionUtil(),
                true,
                DateTime.Now,
                DateTime.Now.AddDays(10),
                true,
                new BuilderSettings());

            BuilderSetup.SetPropertyNamerFor <Politico>(namer);
            BuilderSetup.DisablePropertyNamingFor <Politico, Importacao>(_ => _.Importacao);
            var random = new Random();

            politicoBuilder = Builder <Politico> .CreateNew()
                              .With(_ => _.DT_ELEICAO, DateTime.Now.AddDays(random.NextDouble() + 100).Date)
                              .With(_ => _.DT_NASCIMENTO, DateTime.Now.AddDays(random.NextDouble() + 100).Date);

            importacaoBuilder = Builder <Importacao> .CreateNew();
        }
Example #15
0
        public void ItIsPossibleToSwitchOffAutomaticPropertyNamingForASinglePropertyOfASpecificType()
        {
            var builderSetup = new BuilderSetup();
            builderSetup.DisablePropertyNamingFor<Product, int>(x => x.Id);

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

            // The Product.Id will always be its default value
            Assert.That(products[0].Id, Is.EqualTo(0));
            Assert.That(products[9].Id, Is.EqualTo(0));

            // Other properties are still given automatic values as normal
            Assert.That(products[0].QuantityInStock, Is.EqualTo(1));
            Assert.That(products[9].QuantityInStock, Is.EqualTo(10));
        }
        public async Task <IActionResult> GenerateTestData()
        {
            var faker = new Bogus.Faker("en");

            BuilderSetup.DisablePropertyNamingFor <Product, int>(x => x.Id);
            BuilderSetup.DisablePropertyNamingFor <Profile, int>(x => x.Id);
            BuilderSetup.DisablePropertyNamingFor <Transaction, int>(x => x.Id);
            BuilderSetup.DisablePropertyNamingFor <ProductType, int>(x => x.Id);

            int productTypeCount = 3;
            var productTypes     = Builder <ProductType> .CreateListOfSize(productTypeCount)
                                   .All()
                                   .With(p => p.Name      = faker.Commerce.Categories(1)[0])
                                   .With(p => p.SortOrder = faker.Random.Number(0, productTypeCount))
                                   .Build().ToList();

            _context.ProductTypes.AddRange(productTypes);
            await _context.SaveChangesAsync();

            var products = Builder <Product> .CreateListOfSize(20)
                           .All()
                           .With(p => p.ProductTypeId = faker.PickRandom(productTypes.Select(x => x.Id)))
                           .With(p => p.Name          = faker.Commerce.ProductName())
                           .With(p => p.Description   = faker.Commerce.ProductAdjective())
                           .With(p => p.ImageUrl      = $"https://i.picsum.photos/id/" + p.Id + "/400/400.jpg")
                           .Build().ToList();

            _context.Products.AddRange(products);
            await _context.SaveChangesAsync();


            var profiles = Builder <Profile> .CreateListOfSize(300)
                           .All()
                           .With(p => p.FirstName         = faker.Name.FirstName())
                           .With(p => p.LastName          = faker.Name.LastName())
                           .With(p => p.Address           = faker.Address.StreetAddress())
                           .With(p => p.City              = faker.Address.City())
                           .With(p => p.State             = faker.Address.State())
                           .With(p => p.ZipCode           = faker.Address.ZipCode())
                           .With(p => p.Bio               = faker.Name.JobDescriptor())
                           .With(p => p.Email             = faker.Internet.Email())
                           .With(p => p.IsDropOffPoint    = false)
                           .With(p => p.IsSelfQuarantined = false)
                           .With(p => p.Phone             = faker.Phone.PhoneNumber())
                           .With(p => p.Latitude          = faker.Address.Latitude(33.0075, 36.4997))    // min&max of Arkansas
                           .With(p => p.Longitude         = faker.Address.Longitude(-94.6198, -89.6594)) // min&max of Arkansas
                           .With(p => p.Location          = new Point(faker.Address.Longitude(-94.6198, -89.6594), faker.Address.Latitude(33.0075, 36.4997))
            {
                SRID = 4326
            })                                                                                                                                                // min&max of Arkansas
                           .Random(10)
                           .With(p => p.CompanyName == faker.Company.CompanyName())
                           .Random(30)
                           .With(p => p.CompanyName == faker.Company.CompanyName())
                           .With(p => p.IsDropOffPoint == true)
                           .Random(5)
                           .With(p => p.IsSelfQuarantined == true)
                           .Build();

            _context.Profiles.AddRange(profiles);
            await _context.SaveChangesAsync();


            var transactions = Builder <Transaction> .CreateListOfSize(1000)
                               .All()
                               .With(t => t.Product         = faker.PickRandom(products))
                               .With(t => t.Amount          = faker.Random.Number(3, 10000))
                               .With(t => t.Status          = faker.PickRandom <TransactionStatus>())
                               .With(t => t.TransactionType = TransactionType.Stock)
                               .With(t => t.From            = null)
                               .With(t => t.To = faker.PickRandom(profiles))
                               .With(t => t.TransactionDate = faker.Date.Between(new DateTime(2020, 04, 01), DateTime.Now))
                               .With(t => t.NeedId          = null)
                               .Build();

            var transactions2 = Builder <Transaction> .CreateListOfSize(200)
                                .All()
                                .With(t => t.Product         = faker.PickRandom(products))
                                .With(t => t.Amount          = faker.Random.Number(3, 10000))
                                .With(t => t.Status          = faker.PickRandom <TransactionStatus>())
                                .With(t => t.TransactionType = TransactionType.Delivery)
                                .With(t => t.From            = faker.PickRandom(profiles))
                                .With(t => t.To = faker.PickRandom(profiles))
                                .With(t => t.TransactionDate = faker.Date.Between(new DateTime(2020, 04, 01), DateTime.Now))
                                .With(t => t.NeedId          = null)
                                .Build();

            _context.Transactions.AddRange(transactions);
            _context.Transactions.AddRange(transactions2);
            await _context.SaveChangesAsync();

            return(Ok("Populated"));
        }
Example #17
0
 private List <TestCategory> TestCategories()
 {
     BuilderSetup.DisablePropertyNamingFor <TestCategory, int>(x => x.Id);
     return(Builder <TestCategory> .CreateListOfSize(20).Build().ToList());
 }
        public void should_be_able_to_disable_property_naming_for_an_inherited_property()
        {
            BuilderSetup builderSetup = new BuilderSetup();
            try
            {
                builderSetup.DisablePropertyNamingFor<MyConcreteClass, int>(x => x.PropertyInAbstractClass);

                var list = new Builder<MyConcreteClass>(builderSetup).CreateListOfSize(10).Build();

                Assert.That(list[0].PropertyInAbstractClass, Is.EqualTo(0));
                Assert.That(list[0].PropertyInInheritedClass, Is.EqualTo(1));

                Assert.That(list[9].PropertyInAbstractClass, Is.EqualTo(0));
                Assert.That(list[9].PropertyInInheritedClass, Is.EqualTo(10));
            }
            finally
            {
                builderSetup.ResetToDefaults();
            }
        }
        public void ShouldBeAbleToDisableAutomaticPropertyNamingForASpecificFieldOfASpecificType()
        {
            BuilderSetup builderSetup = new BuilderSetup();
            try
            {
                builderSetup.DisablePropertyNamingFor<MyClass, int>(x => x.Int);

                var list = new Builder<MyClass>(builderSetup).CreateListOfSize(10).Build();

                Assert.That(list[0].Int, Is.EqualTo(0));
                Assert.That(list[0].Long, Is.EqualTo(1));

                Assert.That(list[9].Int, Is.EqualTo(0));
                Assert.That(list[9].Long, Is.EqualTo(10));
            }
            finally
            {
                builderSetup.ResetToDefaults();
            }
        }
Example #20
0
 public void Configuration_4()
 {
     BuilderSetup.DisablePropertyNamingFor <Product, int>(x => x.Id);
 }