Пример #1
0
        public void ExecuteCommand()
        {
            //Given: command as 'park KA-01-HH-1234 White'
            string command = "park KA-01-HH-1234 White";
            //When: I call Park object
            VehicleDetailsModel vehivleDetail = new VehicleDetailsModel
            {
                RegistrationNumber = "KA-01-HH-1234",
                Color = "White"
            };

            _mockParkingVehicle.Setup(x => x.GetDetail(It.IsAny <string>())).Returns(vehivleDetail);
            _mockValidateVeicleDetails.Setup(x => x.Validate(It.IsAny <VehicleDetailsModel>())).Returns(string.Empty);
            _mockParkingRepository.Setup(x => x.GetEmptySlotIndex()).Returns(0);
            _mockParkingRepository.Setup(x => x.ParkVehicle(It.IsAny <VehicleDetailsModel>(), It.IsAny <int>())).Returns(0);
            _mockParkSuccessMessage.Setup(x => x.CreateMessage(It.IsAny <int>())).Returns("Allocated slot number: 1");
            string result = _commandExecutorSelector.ExecuteCommand(command);

            //Then: Method Validate, GetDetail, GetEmptySlotIndex, ParkVehicle, CreateMessage executes once
            _mockParkingVehicle.Verify(x => x.GetDetail(It.IsAny <string>()), Times.Once());
            _mockValidateVeicleDetails.Verify(x => x.Validate(It.IsAny <VehicleDetailsModel>()), Times.Once());
            _mockParkingRepository.Verify(x => x.GetEmptySlotIndex(), Times.Once());
            _mockParkingRepository.Verify(x => x.ParkVehicle(It.IsAny <VehicleDetailsModel>(), It.IsAny <int>()), Times.Once());
            _mockParkSuccessMessage.Verify(x => x.CreateMessage(It.IsAny <int>()), Times.Once());
        }
Пример #2
0
        public void GivenCommand_create_parking_lot_12_Then_Get_Created_a_parking_lot_with_12_slots()
        {
            //Given: Command as 'create_parking_lot 12'
            string command = "create_parking_lot 12";

            //When: I call CreateParkingLot object
            _mockSlot.Setup(x => x.GetSlotSize(It.IsAny <string>())).Returns(12);
            _mockCheckParkingLotCreated.Setup(x => x.IsCreated()).Returns(false);
            _mockParkingRepository.Setup(x => x.CreateParkingSlots(It.IsAny <int>()));
            string result = _commandExecutorSelector.ExecuteCommand(command);
            //Then : I get 'Created a parking lot with 12 slots'
            string expected = "Created a parking lot with 12 slots";

            Assert.AreEqual(expected, result);
        }
Пример #3
0
        public void Given_leave4()
        {
            //Given: command as 'leave 4'
            string command = "leave 4";

            //When: I call Leave object
            _mockSlotToEmpty.Setup(x => x.GetNumber(It.IsAny <string>())).Returns(3);
            _mockValidateSlotNumberToEmpty.Setup(x => x.ValidateSlotNumber(It.IsAny <int>())).Returns(string.Empty);
            _mockParkingRepository.Setup(x => x.EmptyASlot(It.IsAny <int>()));
            _mockLeaveSuccessMessage.Setup(x => x.CreateMessage(It.IsAny <int>())).Returns("Slot number 4 is free");
            string result = _commandExecutorSelector.ExecuteCommand(command);

            //Then: EmptyASlot and CreateMessage executes
            _mockParkingRepository.Verify(x => x.EmptyASlot(It.IsAny <int>()));
            _mockLeaveSuccessMessage.Verify(x => x.CreateMessage(It.IsAny <int>()));
        }
        public void ExecuteCommand()
        {
            //Given: command as "registration_numbers_for_cars_with_colour White"
            string command = "registration_numbers_for_cars_with_colour White";

            //When: I call RegistrationNumbersForCarsWithColour object
            _mockVehicleColor.Setup(x => x.GetColor(It.IsAny <string>())).Returns("White");
            VehicleDetailsModel[] cars = new VehicleDetailsModel[1];
            cars[0] = new VehicleDetailsModel {
                Color = "White", RegistrationNumber = "ka-01-hh-1111"
            };
            _mockParkingRepository.Setup(x => x.GetParkingDetails()).Returns(cars);
            string[] registrationNumber = { "ka-01-hh-1111" };
            _mockVehicleByColor.Setup(x => x.GetRegistrationNumbers(It.IsAny <VehicleDetailsModel[]>(), It.IsAny <string>())).Returns(registrationNumber);
            _mockVehicleByColorSuccessMessage.Setup(x => x.BuildMessage(It.IsAny <string[]>())).Returns("ka-01-hh-1111");
            _commandExecutorSelector.ExecuteCommand(command);
            //Then: Method BuildMessage executes
            _mockVehicleByColorSuccessMessage.Verify(x => x.BuildMessage(It.IsAny <string[]>()));
        }
Пример #5
0
        public void RegistrationNumberFound()
        {
            //Given: Command as 'slot_number_for_registration_number KA-01-HH-3141'
            string command = "slot_number_for_registration_number KA-01-HH-3141";

            //When: I call SlotNumberForRegistrationNumber object
            _mockVehicleRegistrationNumber.Setup(x => x.GetNumber(It.IsAny <string>())).Returns("KA-01-HH-3141");
            VehicleDetailsModel[] vehicleDetails = new VehicleDetailsModel[1];
            vehicleDetails[0] = new VehicleDetailsModel
            {
                Color = "green",
                RegistrationNumber = "KA-01-HH-3141"
            };
            _mockParkingRepository.Setup(x => x.GetParkingDetails()).Returns(vehicleDetails);
            _mockSlotByRegistrationNumber.Setup(x => x.GetSlotNumber(It.IsAny <VehicleDetailsModel[]>(), It.IsAny <string>())).Returns(1);
            string result = _commandExecutorSelector.ExecuteCommand(command);

            //Then: I get '1'
            Assert.AreEqual("1", result);
        }
        public void ExecuteCommand()
        {
            //Given: command as "slot_numbers_for_cars_with_colour White"
            string command = "slot_numbers_for_cars_with_colour White";

            //When: I call SlotNumbersForCarsWithColour object
            _mockVehicleColor.Setup(x => x.GetColor(It.IsAny <string>())).Returns("White");
            VehicleDetailsModel[] cars = new VehicleDetailsModel[1];
            cars[0] = new VehicleDetailsModel
            {
                RegistrationNumber = "ka-01-hh-1111",
                Color = "white"
            };
            _mockParkingRepository.Setup(x => x.GetParkingDetails()).Returns(cars);
            List <int> slotList = new List <int>();

            slotList.Add(1);
            _mockSlotByColor.Setup(x => x.GetSlotNumbers(It.IsAny <VehicleDetailsModel[]>(), It.IsAny <string>())).Returns(slotList);
            _mockSlotByColorMessage.Setup(x => x.BuildMessage(It.IsAny <List <int> >())).Returns("1");
            _commandExecutorSelector.ExecuteCommand(command);
            //Then: method BuildMessage executes
            _mockSlotByColorMessage.Verify(x => x.BuildMessage(It.IsAny <List <int> >()));
        }
Пример #7
0
        public void ExecuteCommand()
        {
            //Given: command as 'status'
            string command = "status";

            //When: I call Status object
            VehicleDetailsModel[] parlingDetails = new VehicleDetailsModel[1];
            parlingDetails[0] = new VehicleDetailsModel
            {
                RegistrationNumber = "KA-01-HH-1111",
                Color = "Black"
            };
            _mockParkingRepository.Setup(x => x.GetParkingDetails()).Returns(parlingDetails);
            StringBuilder expected = new StringBuilder();

            expected.AppendLine("Slot No.   Registration No   Colour");
            expected.AppendLine("1   KA-01-HH-1111   Black");
            _mockStatusOutput.Setup(x => x.Build(It.IsAny <VehicleDetailsModel[]>())).Returns(expected.ToString());
            string result = _commandExecutorSelector.ExecuteCommand(command);

            //Then: method GetParkingDetails and Build executes
            _mockParkingRepository.Verify(x => x.GetParkingDetails());
            _mockStatusOutput.Verify(x => x.Build(It.IsAny <VehicleDetailsModel[]>()));
        }