Example #1
0
        public void ShouldBeAbleToSpecifyACustomPropertyNamerForASpecificType()
        {
            try
            {
                IPropertyNamer propertyNamer = mocks.DynamicMock <IPropertyNamer>();

                BuilderSetup.SetPropertyNamerFor <MyClass>(propertyNamer);

                using (mocks.Record())
                {
                    propertyNamer.Expect(x => x.SetValuesOfAllIn(Arg <IList <MyClass> > .Is.TypeOf)).Repeat.Once();
                }

                using (mocks.Playback())
                {
                    Builder <MyClass> .CreateListOfSize(10).Build();

                    Builder <SimpleClass> .CreateListOfSize(10).Build();
                }

                mocks.VerifyAll();
            }
            finally
            {
                BuilderSetup.ResetToDefaults();
            }
        }
Example #2
0
        public void ShouldBeAbleToSpecifyADefaultCustomPropertyNamer()
        {
            try
            {
                BuilderSetup.SetDefaultPropertyNamer(new MockPropertyNamerTests());
                Builder <MyClass> .CreateListOfSize(10).Build();

                Assert.That(MockPropertyNamerTests.SetValuesOfAllInCallCount, Is.EqualTo(1));
            }
            finally
            {
                BuilderSetup.ResetToDefaults();
            }
        }
Example #3
0
        public void ShouldBeAbleToDisableAutomaticPropertyNaming()
        {
            try
            {
                BuilderSetup.AutoNameProperties = false;
                var list = Builder <MyClass> .CreateListOfSize(10).Build();

                Assert.That(list[0].Int, Is.EqualTo(0));
                Assert.That(list[9].Int, Is.EqualTo(0));
            }
            finally
            {
                BuilderSetup.ResetToDefaults();
            }
        }
Example #4
0
        public void SpecifyingACustomPropertyNamerForASpecificType()
        {
            BuilderSetup.SetPropertyNamerFor <Product>(new CustomProductPropertyNamer(new ReflectionUtil()));

            var products = Builder <Product> .CreateListOfSize(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
            BuilderSetup.ResetToDefaults();
        }
Example #5
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 #6
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 #7
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 #8
0
 public void TearDown()
 {
     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();
            }
        }
        public void ShouldBeAbleToDisableAutomaticPropertyNaming()
        {
            BuilderSetup builderSetup = new BuilderSetup();
            try
            {
                builderSetup.AutoNameProperties = false;
                var list = new Builder<MyClass>(builderSetup).CreateListOfSize(10).Build();

                Assert.That(list[0].Int, Is.EqualTo(0));
                Assert.That(list[9].Int, Is.EqualTo(0));
            }
            finally
            {
                builderSetup.ResetToDefaults();
            }
        }
        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 ShouldBeAbleToSpecifyADefaultCustomPropertyNamer()
 {
     BuilderSetup builderSetup = new BuilderSetup();
     try
     {
         builderSetup.SetDefaultPropertyNamer(new MockPropertyNamerTests());
         new Builder<MyClass>(builderSetup).CreateListOfSize(10).Build();
         Assert.That(MockPropertyNamerTests.SetValuesOfAllInCallCount, Is.EqualTo(1));
     }
     finally
     {
         builderSetup.ResetToDefaults();
     }
 }
        public void ShouldBeAbleToSpecifyACustomPropertyNamerForASpecificType()
        {
            BuilderSetup builderSetup = new BuilderSetup();
            try
            {
                   IPropertyNamer propertyNamer = mocks.DynamicMock<IPropertyNamer>();

                builderSetup.SetPropertyNamerFor<MyClass>(propertyNamer);

                using (mocks.Record())
                {
                    propertyNamer.Expect(x => x.SetValuesOfAllIn(Arg<IList<MyClass>>.Is.TypeOf)).Repeat.Once();
                }

                using (mocks.Playback())
                {
                   new Builder<MyClass>(builderSetup).CreateListOfSize(10).Build();
                   new Builder<SimpleClass>(builderSetup).CreateListOfSize(10).Build();
                }

                mocks.VerifyAll();
            }
            finally
            {
                builderSetup.ResetToDefaults();
            }
        }