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

            // Create Some Bikes
            MountainBike mBike = new MountainBike("Red", 16, 85, 2);

            mBike.Display();

            RoadBike rBike = new RoadBike("Black", 29, 90, true);

            rBike.Display();

            // Now Decorate both the bikes with brakes
            Brakes mountainBikeWithBrakes = new Brakes(mBike);

            mountainBikeWithBrakes.AddBrakes(BrakeType.Disc);

            mountainBikeWithBrakes.Display();

            Brakes roadBikeWithBrakes = new Brakes(rBike);

            roadBikeWithBrakes.AddBrakes(BrakeType.Rim);

            roadBikeWithBrakes.Display();

            // Now Decorate the mountain bike with shocks
            Shocks mountainBikeWithShocks = new Shocks(mBike);

            mountainBikeWithShocks.AddShocks(8);


            mountainBikeWithShocks.Display();
        }
Ejemplo n.º 2
0
        public void ShocksDecorator_AllValidInput_ReturnsInstanceOfBike()
        {
            // Arrange
            MountainBike bike = new MountainBike("Red", 26, 90, 1);

            // Act
            Shocks bikeWithShocks = new Shocks(bike);

            bikeWithShocks.AddShocks(6);
            bikeWithShocks.Display();

            // Assert
            Assert.IsInstanceOfType(bikeWithShocks, typeof(Bike));
        }
Ejemplo n.º 3
0
        public void AllDecorators_AllValidInput_ReturnsInstanceOfBike()
        {
            // Arrange
            MountainBike bike = new MountainBike("Red", 26, 90, 1);

            // Act
            Brakes bikeWithBrakes = new Brakes(bike);

            bikeWithBrakes.AddBrakes(BrakeType.Disc);
            bikeWithBrakes.Display();

            Shocks bikeWithBrakesAndShocks = new Shocks(bikeWithBrakes);

            bikeWithBrakesAndShocks.AddShocks(6);
            bikeWithBrakesAndShocks.Display();

            // Assert
            Assert.IsInstanceOfType(bikeWithBrakes, typeof(Bike));
            Assert.IsInstanceOfType(bikeWithBrakesAndShocks, typeof(Bike));
        }