示例#1
0
        public void Building_collections_using_HavingListOf()
        {
            /*
             * Build an Order that contains two LineItems.
             */
            #region Hint

            /*
             * Use HavingListOf() method on the builder to assign two line items to the order.
             */

            #endregion Hint

            order = __;

            // Assert.
            order.Print();
            order.LineItems.ShouldNotBe( null );
            order.LineItems.Count.ShouldBe( 2 );
            order.LineItems[0].Description.ShouldNotBeEmpty();
            order.LineItems[1].Description.ShouldNotBeEmpty();
        }
示例#2
0
        public void Using_AfterBuild_to_customize_the_object_after_it_is_built()
        {
            /*
             * Ensure that each LineItem in an Order has a reference to the Order.
             */
            #region Hint

            /*
             * Override builder.AfterBuilding() method and in it
             * iterate through the order's line items and set thier Order property.
             */

            #endregion Hint

            order = __;

            // Assert.
            order.Print();
            order.LineItems[0].Order.ShouldBe( order );
            order.LineItems[1].Order.ShouldBe( order );
        }
示例#3
0
        public void Using_a_custom_builder_to_customize_object_creation()
        {
            /*
             * Create a custom OrderBuilder so that by default, it builds an Order with a Customer and two LineItems.
             */
            #region Hint

            /*
             * Create a new class that extends DynamicFluentBuilder<Order>.
             * Set the default values in the constructor of the class.
             *  - Use SetProperty() to populate the customer
             *  - Use AddToList() to populate the line items.
             */

            #endregion Hint

            order = __;

            // Assert.
            order.Print();
            order.Customer.ShouldNotBe( null );
            order.LineItems.ShouldNotBe( null );
            order.LineItems.Count.ShouldBe( 2 );
            order.LineItems[0].Description.ShouldNotBeEmpty();
            order.LineItems[1].Description.ShouldNotBeEmpty();
        }
示例#4
0
        public void Nesting_builders_by_setting_a_property_to_another_builder()
        {
            /*
             * Build an Order object for customer Bob Smith.
             */
            #region Hint

            /*
             * Use the For() method to set the customer property.
             * Use another builder to create the customer.
             * This builder can be nested right inside the Order builder.
             * You can assign a builder directly to the property. You don't have to call build().
             */

            #endregion Hint
            #region Extra Credit

            /*
             * Delegate the creation of the builder to a static class called "Anonymous".
             */

            #endregion Extra Credit

            order = __;

            // Assert.
            order.Print();
            order.Customer.ShouldNotBe( null );
            order.Customer.FirstName.ShouldBe( "Bob" );
            order.Customer.LastName.ShouldBe( "Smith" );
        }