예제 #1
0
        public static void Run()
        {
            Console.WriteLine($"{Environment.NewLine}*** ITERATOR PATTERN ***{Environment.NewLine}");

            BikeProductionLine productionLine = new BikeProductionLine(new Bike
            {
                ProductionNumber = 1
            });

            productionLine.Add(new Bike
            {
                ProductionNumber = 2
            });

            productionLine.Add(new Bike
            {
                ProductionNumber = 3
            });

            productionLine.Add(new Bike
            {
                ProductionNumber = 4
            });

            BikeIterator iterator = productionLine.CreateIterator();

            while (!iterator.IsFinished)
            {
                iterator.CurrentBike.Build();
                iterator.Next();
            }
        }
예제 #2
0
        public static void Run()
        {
            Console.WriteLine($"{Environment.NewLine}*** PROTOTYPE PATTERN ***{Environment.NewLine}");

            Bike bike = new Bike
            {
                ModelName        = "Rocket",
                ProductionNumber = 1
            };

            BikeProductionLine line = new BikeProductionLine(bike, 10);

            line.Run();
        }
예제 #3
0
        public void BikeProductionLine_Run_BuildsCorrectNumberOfBikes()
        {
            // Arrange
            int numberOfBikesToMake = 100;

            Mock <Bike>        mockBike = new Mock <Bike>();
            BikeProductionLine line     = new BikeProductionLine(mockBike.Object, numberOfBikesToMake);

            mockBike.Setup(m => m.Clone()).Returns(mockBike.Object);

            // Act
            line.Run();

            // Assert
            mockBike.Verify(m => m.Clone(), Times.Exactly(numberOfBikesToMake));
        }
예제 #4
0
        public void BikeProductionLine_CreateIterator_IteratorsAcrossAllBikesInPRoductionLine()
        {
            // Arrange
            Mock <Bike>        mockBike = new Mock <Bike>();
            BikeProductionLine line     = new BikeProductionLine(mockBike.Object);
            BikeIterator       iterator = line.CreateIterator();

            // Act
            while (!iterator.IsFinished)
            {
                iterator.CurrentBike.Build();
                iterator.Next();
            }

            // Assert
            mockBike.Verify(m => m.Build(), Times.Once);
        }