コード例 #1
0
        public void Should_SmartParkingBoy_Park_The_Car_To_The_Parkinglot_With_More_Empty_Positions(int currentLoadforPark1, int currentLoadforPark2)
        {
            //Given
            var    boy         = new SmartParkingBoy("Jack");
            var    car         = new Car("RJ_45675415");
            string message     = string.Empty;
            var    parkingLots = new List <CarLot <string, Car> >()
            {
                LotInitialize.FillLotWithCars(currentLoadforPark1),
                LotInitialize.FillLotWithCars(currentLoadforPark2),
            };
            string expectedTicket = "SuperPark: RJ_45675415";
            int    minimumIndex   = 0;

            for (int index = 0; index < parkingLots.Count; index++)
            {
                if (parkingLots[index].Count == Math.Min(currentLoadforPark1, currentLoadforPark2))
                {
                    minimumIndex = index;
                    break;
                }
            }

            int expectedLoad = Math.Min(currentLoadforPark1, currentLoadforPark2) + 1;

            //When
            string actualTicket = boy.Park(car, parkingLots, out message);
            var    actualLoad   = parkingLots[minimumIndex].Count;

            //Then
            Assert.Equal(expectedTicket, actualTicket);
            Assert.Equal(expectedLoad, actualLoad);
        }
コード例 #2
0
        public void Should_Manager_Can_Tell_Boy_To_Park(string plateNumber, string parkingTicket)
        {
            //Given
            var manager   = new ParkingManager("Chris");
            var employee  = new ParkingBoy("Jack");
            var employee2 = new SmartParkingBoy("Joy");

            manager.HireBoy(employee);
            manager.HireBoy(employee2);
            string parkMessage = string.Empty;
            var    car         = new Car(plateNumber);
            var    parkingLots = new List <CarLot <string, Car> >()
            {
                LotInitialize.FillLotWithCars(10, 20),
                LotInitialize.FillLotWithCars(8, 30),
            };

            string expected = parkingTicket;

            //When
            var result = manager.ManagerPark(car, parkingLots, out parkMessage);

            //Then
            Assert.IsType <string>(result);
            Assert.Equal(expected, result);
        }
コード例 #3
0
        public void Should_ParkingBoy_Return_Null_When_Both_Parkinglots_Are_Full(string plateNumber, string parkingTicket)
        {
            //Given
            var    boy         = new ParkingBoy("Jack");
            var    car         = new Car(plateNumber);
            string message     = string.Empty;
            var    parkingLots = new List <CarLot <string, Car> >()
            {
                LotInitialize.FillLotWithCars(10),
                LotInitialize.FillLotWithCars(10),
            };
            string expectedTicket = null;
            int    expectedLoadsOfFirstParkinglot  = 10;
            int    expectedLoadsOfSecondParkinglot = 10;

            //When
            string actualTicket = boy.Park(car, parkingLots, out message);
            var    actualLoadsOfFirstParkinglot  = parkingLots[0].Count;
            var    actualLoadsOfSecondParkinglot = parkingLots[1].Count;

            //Then
            Assert.Equal(expectedTicket, actualTicket);
            Assert.Equal(expectedLoadsOfFirstParkinglot, actualLoadsOfFirstParkinglot);
            Assert.Equal(expectedLoadsOfSecondParkinglot, actualLoadsOfSecondParkinglot);
        }
コード例 #4
0
        public void Should_ParkingBoy_Return_Correct_Error_Message_When_Parkinglot_Is_Full()
        {
            //Given
            var boy         = new ParkingBoy("Jack");
            var parkingLots = new List <CarLot <string, Car> >()
            {
                LotInitialize.FillLotWithCars(10),
                LotInitialize.FillLotWithCars(10),
            };
            string expectedMessage = "Not enough position.";
            string actualMessage;

            //When
            var result = boy.Park(new Car("BJ_54654"), parkingLots, out actualMessage);

            //Then
            Assert.Equal(expectedMessage, actualMessage);
        }
コード例 #5
0
        public void Should_ParkingBoyFecth_Return_No_Car_Given_Wrong_Tickect()
        {
            //Given
            var    boy           = new ParkingBoy("Jack");
            string fectchmessage = string.Empty;
            var    parkingLots   = new List <CarLot <string, Car> >()
            {
                LotInitialize.FillLotWithCars(3)
            };
            var ticket   = "SuperPark: 456213154";
            Car expected = null;

            //When
            var result = boy.Fetch(ticket, parkingLots, out fectchmessage);

            //Then
            Assert.Equal(expected, result);
        }
コード例 #6
0
        public void Should_ParkingBoyPark_Return_No_Ticket_Given_Full_Parkinglot()
        {
            //Given
            var    boy         = new ParkingBoy("Jack");
            string message     = string.Empty;
            var    parkingLots = new List <CarLot <string, Car> >()
            {
                LotInitialize.FillLotWithCars(10),
            };
            var    car      = new Car("BJ_454867");
            string expected = null;

            //When
            var result = boy.Park(car, parkingLots, out message);

            //Then
            Assert.Equal(expected, result);
        }
コード例 #7
0
        public void Should_ParkingBoy_Return_Correct_Error_Message_Given_No_Tickect()
        {
            //Given
            var boy         = new ParkingBoy("Jack");
            var parkingLots = new List <CarLot <string, Car> >()
            {
                LotInitialize.FillLotWithCars(3),
                LotInitialize.FillLotWithCars(4),
            };
            Car    expectedCar     = null;
            string expectedMessage = "Please provide your parking ticket.";
            string actualMessage;

            //When
            var actualCar = boy.Fetch(parkingLots, out actualMessage);

            //Then
            Assert.Equal(expectedCar, actualCar);
            Assert.Equal(expectedMessage, actualMessage);
        }
コード例 #8
0
        public void Should_ParkingBoy_Return_Correct_Error_Message_Given_Wrong_Tickect()
        {
            //Given
            var boy         = new ParkingBoy("Jack");
            var parkingLots = new List <CarLot <string, Car> >()
            {
                LotInitialize.FillLotWithCars(3),
                LotInitialize.FillLotWithCars(4),
            };
            var    ticket          = "SuperPark: 456213154";
            Car    expectedCar     = null;
            string expectedMessage = "Unrecognized parking ticket.";
            string actualMessage;

            //When
            var actualCar = boy.Fetch(ticket, parkingLots, out actualMessage);

            //Then
            Assert.Equal(expectedCar, actualCar);
            Assert.Equal(expectedMessage, actualMessage);
        }
コード例 #9
0
        public void Should_ParkingBoyFecth_Return_Right_Car()
        {
            //Given
            var    boy           = new ParkingBoy("Jack");
            string message       = string.Empty;
            string fectchmessage = string.Empty;
            var    parkingLots   = new List <CarLot <string, Car> >()
            {
                LotInitialize.FillLotWithCars(3)
            };
            var ticket = "SuperPark: RJ_12784";

            boy.Park(new Car("RJ_12784"), parkingLots, out message);
            Car expected = parkingLots[0]["RJ_12784"];

            //When
            var result = boy.Fetch(ticket, parkingLots, out fectchmessage);

            //Then
            Assert.Equal(expected, result);
        }
コード例 #10
0
        public void Should_SuperSmartParkingBoy_Park_The_Car_To_The_Parkinglot_With_Higher_EmptyRate(int currentLotLoad1, int currentLotLoad2, int loadCapacity1, int loadCapacity2)
        {
            //Given
            var    boy         = new SuperSmartParkingBoy("Jack");
            var    car         = new Car("RJ_45675415");
            string message     = string.Empty;
            var    parkingLots = new List <CarLot <string, Car> >()
            {
                LotInitialize.FillLotWithCars(currentLotLoad1, loadCapacity1),
                LotInitialize.FillLotWithCars(currentLotLoad2, loadCapacity2),
            };
            var    testCount       = parkingLots[0].Count;
            var    testCapacity    = parkingLots[0].Capacity;
            string expectedTicket  = "SuperPark: RJ_45675415";
            double minimumLoadRate = Math.Min(parkingLots[0].LoadRate, parkingLots[1].LoadRate);
            int    targetIndex     = 0;

            for (int index = 0; index < parkingLots.Count; index++)
            {
                if (parkingLots[index].LoadRate == Math.Min(parkingLots[0].LoadRate, parkingLots[1].LoadRate))
                {
                    targetIndex = index;
                    break;
                }
            }

            int expectedLoad = parkingLots[targetIndex].Count + 1;

            //When
            string actualTicket = boy.Park(car, parkingLots, out message);
            var    actualLoad   = parkingLots[targetIndex].Count;

            //Then
            Assert.Equal(expectedTicket, actualTicket);
            Assert.Equal(expectedLoad, actualLoad);
        }