public void GivenListOfBuildersWithNoCustomisation_WhenCallingExtensionMethodToBuildList_ThenListOfTheRightTypeShouldBeReturned()
        {
            var builders = CustomerBuilder.CreateListOfSize(5);

            var entities = builders.BuildList();

            Assert.That(entities, Has.All.TypeOf <Customer>());
        }
        public void GivenListOfBuildersWithNoCustomisation_WhenCallingExtensionMethodToBuildList_ThenAListOfUniqueEntitiesShouldBeReturned()
        {
            var builders = CustomerBuilder.CreateListOfSize(5);

            var entities = builders.BuildList();

            Assert.That(entities, Is.Unique);
        }
        public void GivenListOfBuildersWithCustomisation_WhenCallingExtensionMethodToBuildList_ThenTheCustomisationShouldTakeEffect()
        {
            var generator = new SequentialGenerator <int>();
            var list      = CustomerBuilder.CreateListOfSize(3)
                            .All().With(b => b.WithFirstName(generator.Generate().ToString()));

            var data = list.BuildList();

            Assert.That(data.Select(c => c.FirstName), Is.EqualTo(new[] { "0", "1", "2" }));
        }
예제 #4
0
        public void GivenListOfBuildersWithCustomisation_WhenBuildingEntitiesImplicitly_ThenTheCustomisationShouldTakeEffect()
        {
            var generator = new SequentialGenerator(0, 100);

            List <Customer> data = CustomerBuilder.CreateListOfSize(3)
                                   .All().With(b => b.WithFirstName(generator.Generate().ToString()));

            data.Select(c => c.FirstName).ToArray()
            .ShouldBe(new[] { "0", "1", "2" });
        }
예제 #5
0
        public void WhenBuildingEntitiesImplicitly_ThenTheAnonymousValueFixtureIsSharedAcrossBuilders()
        {
            List <Customer> customers = CustomerBuilder.CreateListOfSize(5);

            customers[0].CustomerClass.ShouldBe(CustomerClass.Normal);
            customers[1].CustomerClass.ShouldBe(CustomerClass.Bronze);
            customers[2].CustomerClass.ShouldBe(CustomerClass.Silver);
            customers[3].CustomerClass.ShouldBe(CustomerClass.Gold);
            customers[4].CustomerClass.ShouldBe(CustomerClass.Platinum);
        }
        public void GivenCreatingAList_WhenUsingNBuilderToChangeTheList_ThenTheChangesAreReflected()
        {
            var generator = new SequentialGenerator <int>();

            var list = CustomerBuilder.CreateListOfSize(3)
                       .All().With(b => b.WithFirstName(generator.Generate().ToString()))
                       .Build();

            Assert.That(list.Select(b => b.Get(x => x.FirstName)), Is.EqualTo(new[] { "0", "1", "2" }));
        }
예제 #7
0
        public void GivenGlobalValueSupplierSet_WhenGeneratingList_UseTheSupplierForTheRelevantPropertyExceptWhereItsOverridden()
        {
            AnonymousValueFixture.GlobalValueSuppliers.Add(new YearValueSupplier());
            var customers = CustomerBuilder.CreateListOfSize(5)
                            .TheLast(1).WhoJoinedIn(1990)
                            .BuildList();

            customers[0].YearJoined.ShouldBe(2000);
            customers[1].YearJoined.ShouldBe(2001);
            customers[2].YearJoined.ShouldBe(2002);
            customers[3].YearJoined.ShouldBe(2003);
            customers[4].YearJoined.ShouldBe(1990);
        }
예제 #8
0
        public void GivenListOfBuildersWithARangeOfCustomisationMethods_WhenBuildingEntitiesImplicitly_ThenThenTheListIsBuiltAndModifiedCorrectly()
        {
            var             i         = 0;
            List <Customer> customers = CustomerBuilder.CreateListOfSize(5)
                                        .TheFirst(1).WithFirstName("First")
                                        .TheNext(1).WithLastName("Next Last")
                                        .TheLast(1).WithLastName("Last Last")
                                        .ThePrevious(2).With(b => b.WithLastName("last" + (++i).ToString()))
                                        .All().WhoJoinedIn(1999);

            customers.ShouldBeAssignableTo <IList <Customer> >();
            customers.Count.ShouldBe(5);
            customers[0].FirstName.ShouldBe("First");
            customers[1].LastName.ShouldBe("Next Last");
            customers[2].LastName.ShouldBe("last1");
            customers[3].LastName.ShouldBe("last2");
            customers[4].LastName.ShouldBe("Last Last");
            customers.ShouldAllBe(c => c.YearJoined == 1999);
        }
예제 #9
0
 public virtual AddressBuilder WithCustomers(int listSize, Func <ListBuilder <Customer, CustomerBuilder>, CustomerBuilder> modifier = null)
 {
     return(Set(x => x.Customers, GetListChildBuilder <Customer, CustomerBuilder, ListBuilder <Customer, CustomerBuilder> >(() => CustomerBuilder.CreateListOfSize(listSize), modifier)));
 }