Exemplo n.º 1
0
        public static void Run()
        {
            Console.WriteLine($"{Environment.NewLine}*** OBSERVER PATTERN ***{Environment.NewLine}");

            // Make a new bike manufacturer;
            IBikeManufacturer manufacturer = new BikeManufacturer();

            // Make some shops
            IBikeShop roadBikeShop     = new RoadBikeShop();
            IBikeShop mountainBikeShop = new MountainBikeShop();

            // Register the shops for updates
            WeakReference <IBikeShop> roadBikeShopRef    = manufacturer.RegisterShop(roadBikeShop);
            WeakReference <IBikeShop> mountainBikehopRef = manufacturer.RegisterShop(mountainBikeShop);

            // Announce some new bikes
            manufacturer.NotifyShops(new BikeModel
            {
                Name = "Mountain King",
                Type = BikeType.Mountain
            });


            manufacturer.NotifyShops(new BikeModel
            {
                Name = "Road Racer",
                Type = BikeType.Road
            });
        }
        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);
            }
        }
Exemplo n.º 3
0
        public void RoadBikeTemplate_AllValidInput_ReturnsInstanceOfRoadBikeShop()
        {
            // Arrange
            BaseBikeShop shop = new RoadBikeShop();

            // Act
            shop.BuildBike();

            // Assert
            Assert.IsInstanceOfType(shop, typeof(RoadBikeShop));
        }
Exemplo n.º 4
0
        public void RoadBikeShop_OrderBike_ReturnsInstanceOfRoadBike()
        {
            // Arrange
            IBikeShop shop = new RoadBikeShop();

            // Act
            IBike bike = shop.OrderBike("test");

            // Assert
            Assert.IsInstanceOfType(bike, typeof(RoadBike));
        }
Exemplo n.º 5
0
        public static void Run()
        {
            Console.WriteLine($"{Environment.NewLine}*** ABSTRACT FACTORY PATTERN ***{Environment.NewLine}");

            IBikeShop mShop = new MountainBikeShop();
            IBikeShop rShop = new RoadBikeShop();
            IBikeShop hShop = new HybridBikeShop();

            mShop.OrderBike("Muddy");
            rShop.OrderBike("Missile");
            hShop.OrderBike("Cruser");
        }
Exemplo n.º 6
0
        public static void Run()
        {
            Console.WriteLine($"{Environment.NewLine}*** TEMPLATE PATTERN ***{Environment.NewLine}");

            // Make a mountain bike workshop to build some mountain bikes
            MountainBikeShop mountainBikesRUS = new MountainBikeShop();

            mountainBikesRUS.BuildBike();

            // Make a Road bike shop to build some road bikes
            RoadBikeShop weLikeRoadBikes = new RoadBikeShop();

            weLikeRoadBikes.BuildBike();
            weLikeRoadBikes.BuildBike();
        }
        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);
        }