D:\Unit Testing\MSDN Article\Automated White Box Testing For Legacy Systems\Automated White Box Testing For Legacy Systems\SourceCode\FabrikamSports.Legacy\Warehouse.cs

Modules/Types/MethodsDynamic Coverage (blocks)
User Code Under TestUser Or Test Code
first
// --------------------------------------------------------------------------------------------------------------------- 
// <copyright file="Warehouse.cs" company="Microsoft">
//   warehouse
// </copyright>
// <summary>
//   Defines the Warehouse type.
// </summary>
// ---------------------------------------------------------------------------------------------------------------------
// ==++==
// 
//   Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// ==--==
namespace FabrikamSports
{
    using System.Collections.Generic;

    /// <summary>
    /// Warehouse implemenation
    /// </summary>
    public class Warehouse
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Warehouse"/> class.
        /// </summary>
        top|next0000,1public Warehouse()
        {
            // Initialize Products
            0006,1this.BasketBalls = new List<Product>
                                   {
                                       new Basketball(),
                                       new Basketball(),
                                       new Basketball()
                                   };

            0034,1this.BaseBalls = new List<Product>
                                 {
                                     new Baseball(),
                                     new Baseball(),
                                     new Baseball()
                                 };
        0062,1}

        /// <summary>
        /// Gets the basket balls.
        /// </summary>
        /// <value>The basket balls.</value>
        public List<Product> BasketBalls
        {
            get; private set;
        }

        /// <summary>
        /// Gets the base balls.
        /// </summary>
        /// <value>The base balls.</value>
        public List<Product> BaseBalls
        {
            get; private set;
        }

        /// <summary>
        /// Checks the inventory
        /// </summary>
        /// <param name="product">The product.</param>
        /// <param name="quantity">The quantity.</param>
        /// <returns>Returns <see cref="bool"/></returns>
        public virtual bool HasInventory(Product product, int quantity)
        {
            prev|top|next0000,1bool hasInventory = false;

            // Check the Inventory
            0002,1if (this.GetInventory(product) >= quantity)
            {
                000c,1hasInventory = true;
            }

            000e,2return hasInventory;
        }

        /// <summary>
        /// Removes item from Inventory
        /// </summary>
        /// <param name="product">The product.</param>
        /// <param name="quantity">The quantity.</param>
        public void Remove(Product product, int quantity)
        {
            prev|top|next0000,1switch (product.Name)
            {
                case "Base Ball":
                    0025,1this.BaseBalls.Remove(product);
                    0032,3break;
                case "Basket Ball":
                    0033,1this.BasketBalls.Remove(product);
                    break;
            }
        0040,4}

        /// <summary>
        /// Get the inventory
        /// </summary>
        /// <param name="product">The product.</param>
        /// <returns>Returns <see cref="bool"/></returns>
        private int GetInventory(Product product)
        {
            prev|top0000,1switch (product.Name)
            {
                case "Base Ball":
                    0026,1return this.BaseBalls.Count;
                case "Basket Ball":
                    0032,1return this.BasketBalls.Count;
            }

            003e,2return 0;
        }
    }
}

Copyright (c) Microsoft Corporation. All rights reserved.
Copy full source to clipboard