Пример #1
0
        public static void Run()
        {
            Console.WriteLine($"{Environment.NewLine}*** VISITOR PATTERN ***{Environment.NewLine}");

            BikeShop shop = new BikeShop();

            shop.Attach(new MountainBike("Rocky"));
            shop.Attach(new RoadBike("Speedy"));
            shop.Attach(new HybridBike("Rover"));

            shop.DisplayBikes();

            shop.AcceptVisitor(new TirePumpRobot());
            shop.AcceptVisitor(new PainterRobot());

            shop.DisplayBikes();
        }
Пример #2
0
        public void PaintRobot_DoWork_ChangesBikeColour()
        {
            // Arrange
            BikeShop     shop           = new BikeShop();
            IBike        testBike       = new MountainBike("Test");
            ConsoleColor originalColour = testBike.Colour;

            shop.Attach(testBike);

            // Act
            shop.AcceptVisitor(new PainterRobot());

            // Assert - This could fail if it randomly chooses the original colour again
            Assert.IsFalse(testBike.Colour == originalColour);
        }
Пример #3
0
        public void TirePumpRobot_DoWork_ChangesTirePressure()
        {
            // Arrange
            BikeShop shop                 = new BikeShop();
            IBike    testBike             = new MountainBike("Test");
            int      originalTirePressure = testBike.TirePressure;

            shop.Attach(testBike);

            // Act
            shop.AcceptVisitor(new TirePumpRobot());

            // Assert
            Assert.IsFalse(testBike.TirePressure == originalTirePressure);
        }