コード例 #1
0
        public static void Run()
        {
            Console.WriteLine($"{Environment.NewLine}*** CHAIN OF RESPONSIBILITY PATTERN ***{Environment.NewLine}");

            // Create the links in the chain
            BikeShop mountainBikes = new MountainBikeShop("Tom's Mountain Bikes");
            BikeShop roadBikes     = new RoadBikeShop("Dick's road bikes");
            BikeShop hybridBikes   = new HybridBikeShop("Harry's hybrid bikes");

            // set up the chain
            mountainBikes.Successor = roadBikes;
            roadBikes.Successor     = hybridBikes;

            List <BikeType> orders = new List <BikeType>
            {
                BikeType.Hybrid,
                BikeType.Mountain,
                BikeType.Road,
                BikeType.Hybrid,
                BikeType.Road,
                BikeType.Mountain
            };

            // Process the order requests

            foreach (BikeType order in orders)
            {
                mountainBikes.FillOrder(order);
            }
        }
コード例 #2
0
        public void BikeShop_FillOrder_PassesRequestAlongChain()
        {
            // Arrange
            BikeShop        mountainBikes = new MountainBikeShop("Tom's Mountain Bikes");
            BikeShop        roadBikes     = new RoadBikeShop("Dick's road bikes");
            Mock <BikeShop> mockShop      = new Mock <BikeShop>("Mock Shop");

            mountainBikes.Successor = roadBikes;
            roadBikes.Successor     = mockShop.Object;

            // Act
            mountainBikes.FillOrder(Common.BikeType.Hybrid);

            // Assert
            mockShop.Verify(m => m.FillOrder(It.IsAny <Common.BikeType>()), Times.Once);
        }