Exemple #1
0
        public void ParkCar_Not_Possible_When_Parking_Lots_Are_Full()
        {
            var parkingLotManager = new ParkingLotManager();

            parkingLotManager.SetEmptyLots(3);

            parkingLotManager.ParkCar(new Car {
                RegistrationNumber = "Test-Registration-Number1", Color = "Test-Color1"
            }, parkingLotManager.GetNextEmptyLot());
            parkingLotManager.ParkCar(new Car {
                RegistrationNumber = "Test-Registration-Number2", Color = "Test-Color2"
            }, parkingLotManager.GetNextEmptyLot());
            parkingLotManager.ParkCar(new Car {
                RegistrationNumber = "Test-Registration-Number3", Color = "Test-Color3"
            }, parkingLotManager.GetNextEmptyLot());

            Assert.Equal(0, parkingLotManager.GetNextEmptyLot());
        }
Exemple #2
0
        public void ParkCar_Uses_Empty_Parking_Lot()
        {
            var parkingLotManager = new ParkingLotManager();

            parkingLotManager.SetEmptyLots(3);
            parkingLotManager.ParkCar(new Car {
                RegistrationNumber = "Test-Registration-Number1", Color = "Test-Color1"
            }, parkingLotManager.GetNextEmptyLot());
            Assert.Equal(2, parkingLotManager.GetNextEmptyLot());
        }
Exemple #3
0
        public void GetNextEmptyLot_Returns_Closest_Empty_Lot_After_Adjusting_Car_Leaving()
        {
            var parkingLotManager = new ParkingLotManager();

            parkingLotManager.SetEmptyLots(3);

            parkingLotManager.ParkCar(new Car {
                RegistrationNumber = "Test-Registration-Number1", Color = "Test-Color1"
            }, parkingLotManager.GetNextEmptyLot());
            parkingLotManager.ParkCar(new Car {
                RegistrationNumber = "Test-Registration-Number2", Color = "Test-Color2"
            }, parkingLotManager.GetNextEmptyLot());
            parkingLotManager.ParkCar(new Car {
                RegistrationNumber = "Test-Registration-Number3", Color = "Test-Color3"
            }, parkingLotManager.GetNextEmptyLot());

            parkingLotManager.LeaveParking(2);
            parkingLotManager.LeaveParking(3);

            Assert.Equal(2, parkingLotManager.GetNextEmptyLot());
        }
Exemple #4
0
        public void GetRegistrationNumbersByCarColor_Returns_Registration_After_Parking_A_Car()
        {
            var parkingLotManager = new ParkingLotManager();

            parkingLotManager.SetEmptyLots(3);
            var car = new Car {
                RegistrationNumber = "Test-Registration-Number", Color = "Test-Color"
            };

            parkingLotManager.ParkCar(car, 1);

            Assert.Equal(car.RegistrationNumber, parkingLotManager.GetRegistrationNumbersByCarColor("Test-Color").First());
        }
Exemple #5
0
        public void GetRegistrationNumbersByCarColor_Returns_Empty_Registration_After_Leaving_Parking()
        {
            var parkingLotManager = new ParkingLotManager();

            parkingLotManager.SetEmptyLots(3);
            var car1 = new Car {
                RegistrationNumber = "Test-Registration-Number1", Color = "Test-Color"
            };

            parkingLotManager.ParkCar(car1, 1);
            parkingLotManager.LeaveParking(1);

            Assert.Empty(parkingLotManager.GetRegistrationNumbersByCarColor("Test-Color"));
        }
Exemple #6
0
        public void GetRegistrationNumbersByCarColor_Returns_Registrations_After_Parking_Multiple_Car()
        {
            var parkingLotManager = new ParkingLotManager();

            parkingLotManager.SetEmptyLots(3);
            var car1 = new Car {
                RegistrationNumber = "Test-Registration-Number1", Color = "Test-Color"
            };
            var car2 = new Car {
                RegistrationNumber = "Test-Registration-Number2", Color = "Test-Color"
            };
            var car3 = new Car {
                RegistrationNumber = "Test-Registration-Number3", Color = "Test-Color"
            };

            parkingLotManager.ParkCar(car1, 1);
            parkingLotManager.ParkCar(car2, 1);
            parkingLotManager.ParkCar(car3, 1);

            Assert.Equal(new List <string> {
                car1.RegistrationNumber, car2.RegistrationNumber, car3.RegistrationNumber
            }, parkingLotManager.GetRegistrationNumbersByCarColor("Test-Color"));
        }
        public void Handle(string input, ParkingLotManager parkingLotManager)
        {
            var firstEmptySlot = parkingLotManager.GetNextEmptyLot();

            if (firstEmptySlot == 0)
            {
                Console.WriteLine("Sorry, parking lot is full");
                return;
            }

            var tokens = input.Split(' ');

            if (tokens.Length == 3)
            {
                var car = new Car {
                    RegistrationNumber = tokens[1], Color = tokens[2]
                };
                parkingLotManager.ParkCar(car, firstEmptySlot);
                Console.WriteLine($"Allocated slot number: {firstEmptySlot}");
            }
        }