Пример #1
0
        public void Adding_custom_methods_to_the_builder_builder_to_increase_expressiveness()
        {
            /*
             * Modify the CustomerBuilder to easily specify the customer is a minor (under 21).
             */
            #region Hint

            /*
             * Create CustomerBuilder.WhoIsAMinor() method to generate the birthdate for someone under 21.
             * Don't forget to call that method before buiding.
             */

            #endregion Hint

            customer = __;

            // Assert.
            customer.Print();
            var age = YearsBetween( customer.BirthDate, DateTime.Now );
            age.ShouldBeLessThan( 21 );
        }
Пример #2
0
        public void Using_DynamicFluentBuilder_to_build_an_object()
        {
            /*
             * Use Fluency's DynamicFluentBuilder<> class to build a Customer object.
             * Don't forget to call build() to create the customer.
             */

            customer = __;

            // Assert.
            customer.Print();
            customer.FirstName.ShouldNotBeEmpty();
            customer.MiddleName.ShouldNotBeEmpty();
            customer.LastName.ShouldNotBeEmpty();
        }
Пример #3
0
        public void Using_Having_and_With_to_set_property_values()
        {
            /*
             * Set the Customer's first and last name in the builder.
             */
            #region Hint

            /*
             * Use the With or Having methods.
             */

            #endregion Hint

            customer = __;

            // Assert.
            customer.Print();
            customer.FirstName.ShouldBe( "Bob" );
            customer.LastName.ShouldBe( "Smith" );
        }
Пример #4
0
        public void Customizing_the_builder_to_satisfy_invariants()
        {
            /*
             * Create a customer builder that ensures that:
             *   (1) The CustomerSinceDate is greater than the Birthdate, and
             *   (2) Both dates are in the past.
             */
            #region Hint

            /*
             * Create a CustomerBuilder and set these values in its constructor.
             * Use methods on the ARandom class like ARandom.BirthDate() and ARandom.DateInPastSince( date ) to generate random values.
             * USe GetValue to retrieve property values you have already set.
             *  i.e. use GetValue( x => x.BirthDate) to retrieve the birthdate so you can generate a later CustomerSinceDate.
             */

            #endregion Hint

            #region Extra Credit

            /*
             * Ensure that the customer is 18 years or older.
             */

            #endregion Extra Credit
            #region Extra Credit Hint

            /*
             * Generate an age >18 and using ARandom.IntBetween().
             * Reverse engineer a birthdate from the age using ARandom.BithDateForAge().
             * Generate a CustSinceDate that is after their 18th birthday.
             */

            #endregion Extra Credit Hint

            customer = __;

            // Assert.
            customer.Print();
            customer.BirthDate.ShouldBeLessThan( DateTime.Now );
            customer.CustomerSinceDate.ShouldBeLessThan( DateTime.Now );
            customer.CustomerSinceDate.ShouldBeGreaterThan( customer.BirthDate );
            // Extra Credit. (uncomment the following line to test it)
            // customer.BirthDate.ShouldBeLessThan( DateTime.Now.AddYears( -18 ) );
            // customer.CustomerSinceDate.ShouldBeGreaterThan( customer.BirthDate.AddYears( 18 ) );
        }