Beispiel #1
0
        public void UsingAnotherBuilderInSetup_EmployeeMustAtLeastHaveOneAussieAddress()
        {
            var builder = new EmployeeBuilder();

            var actual = builder.WithEmployeeFromAustralia()
                         // mix things up a bit and add another address manually by instantiating a new AddressBuilder
                         .With(e => e.Addresses.Add(new AddressBuilder()
                                                    .WithSouthAfricanAddress()
                                                    .Build())
                               )
                         .Build();

            actual.Addresses.Count().ShouldBeGreaterThan(1);
            actual.Addresses.Any(a => a.PostCode == "6000").ShouldBeTrue("No Aussie address detected.");


            // same test BUT this time request a builder via the .With<TRequestBuilder> instead of instantiating it.
            builder = new EmployeeBuilder();
            actual  = builder.WithEmployeeFromAustralia()
                      .With <AddressBuilder>((e, addressBuilder) => e.Addresses.Add(addressBuilder
                                                                                    .WithSouthAfricanAddress()
                                                                                    .Build())
                                             )
                      .Build();

            actual.Addresses.Count().ShouldBeGreaterThan(1);
            actual.Addresses.Any(a => a.PostCode == "6000").ShouldBeTrue("No Aussie address detected.");
        }
Beispiel #2
0
        public void RemoveManualAddingAnAddressIntoAIntoANiceAddMethod_EmployeeMustAtLeastHaveOneAussieAddressJustAnotherWayToCreateTest()
        {
            var builder = new EmployeeBuilder();

            var actual = builder.WithEmployeeFromAustralia()
                         .AddSouthAfricanAddress()
                         .Build();

            actual.Addresses.Count().ShouldBeGreaterThan(1);
            actual.Addresses.Any(a => a.PostCode == "6000").ShouldBeTrue("No Aussie address detected.");
        }
Beispiel #3
0
        public void AddMethodShouldOnlyAddOnce_EmployeeMustAtLeastHaveOneAussieAddressJustAnotherWayToCreateTest()
        {
            var builder = new EmployeeBuilder();

            var actual = builder.WithEmployeeFromAustralia() //addresses 1 => aus
                         .AddSouthAfricanAddress()           //addresses 2 => aus, south afr. address
                         .AddSouthAfricanAddress()           //must not add a third address
                         .Build();

            actual.Addresses.Count().ShouldNotBe(3);
            actual.Addresses.Count().ShouldBe(2);
            actual.Addresses.Any(a => a.PostCode == "6000").ShouldBeTrue("No Aussie address detected.");
        }
        public void EmployeeValidatorTests_EmployeeAddressShouldBeVALIDWhenAnyPostCodeFromAustraliaDetected()
        {
            //arrange
            var builder = new EmployeeBuilder();

            var employee = builder.WithEmployeeFromAustralia()
                           .Build();

            //act
            //system under test
            var sut = new EmployeeValidator(employee);

            //assert
            sut.IsValidAustralianAddress().ShouldBeTrue();
        }