Ejemplo n.º 1
0
        public void Should_return_my_car_when_i_use_my_ticket_in_lots_with_other_car()
        {
            var boy = new SmartParkingBoy(new List <Lot> {
                new Lot(2)
            });
            const string carId  = "川A 123456";
            var          ticket = new Ticket(boy.Park(new Car(carId)));

            boy.Park(new Car("123"));

            var car = boy.Take(ticket);

            Assert.Equal(carId, car.Id);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public void should_park_into_second_parking_lot_when_have_two_parking_lots_and_both_are_available_the_second_have_more_spot()
        {
            var parkingLotA = new ParkingLot(_capacity);
            var parkingLotB = new ParkingLot(_capacity);

            for (var i = 0; i < _capacity - 1; i++)
            {
                parkingLotA.Park(new Car());
            }
            for (var i = 0; i < _capacity - 2; i++)
            {
                parkingLotB.Park(new Car());
            }
            var preNumOfCarA = parkingLotA.GetAvailableSpotNumber();
            var preNumOfCarB = parkingLotB.GetAvailableSpotNumber();
            var car          = new Car();
            var list         = new List <ParkingLot>()
            {
                parkingLotA, parkingLotB
            };
            var smartParkingBoy = new SmartParkingBoy(list);

            smartParkingBoy.Park(car);

            Assert.Equal(preNumOfCarA, parkingLotA.GetAvailableSpotNumber());
            Assert.Equal(preNumOfCarB - 1, parkingLotB.GetAvailableSpotNumber());
        }
Ejemplo n.º 4
0
        public void SmartParkingBoy_Should_park_cars_to_more_space_parkingLot_with_cars(int parkingCapacity1, int parkingCapacity2, int parkingCapacity3)
        {
            //given
            var parkingLots = new List <ParkingLot>()
            {
                { new ParkingLot(parkingCapacity1) }, { new ParkingLot(parkingCapacity2) }, { new ParkingLot(parkingCapacity3) }
            };
            var smartParkingBoy = new SmartParkingBoy();
            var parkingBoy      = new ParkingBoy();

            //when
            for (int i = 0; i < 2; i++)
            {
                parkingBoy.Park(i.ToString(), parkingLots[1]);
                parkingBoy.Park(i.ToString(), parkingLots[2]);
            }

            var numberPlate      = "XX2345";
            var parkingTicket    = smartParkingBoy.Park(numberPlate, parkingLots);
            var expectParkingLot = parkingLots[2];

            //then
            Assert.NotEmpty(parkingTicket);
            Assert.Contains <string>("XX2345", expectParkingLot.ParkingCarsList);
        }
Ejemplo n.º 5
0
        void should_save_to_the_previous_parking_lot_when_parking_lot_left_space_is_equal()
        {
            var parkingLotA = new ParkingLot(20);
            var parkingLotB = new ParkingLot(20);
            var parkingLotC = new ParkingLot(20);
            var parkingBoy  = new SmartParkingBoy(new List <ParkingLot>
            {
                parkingLotA,
                parkingLotB,
                parkingLotC
            });

            for (int i = 0; i < 15; i++)
            {
                parkingLotA.Park(new Car());
            }

            for (int i = 0; i < 10; i++)
            {
                parkingLotB.Park(new Car());
            }

            for (int i = 0; i < 10; i++)
            {
                parkingLotC.Park(new Car());
            }

            parkingBoy.Park(new Car());
            Assert.Equal(5, parkingLotA.GetAvailableSpace());
            Assert.Equal(9, parkingLotB.GetAvailableSpace());
            Assert.Equal(10, parkingLotC.GetAvailableSpace());
        }
        given_parking_boy_and_smart_parking_boy_then_smart_boy_can_not_manage_parking_boy()
        {
            var parkingLot      = new OOParkingLot(1);
            var parkingBoy      = new ParkingBoy(parkingLot);
            var smartParkingBoy = new SmartParkingBoy(parkingBoy as IParkingLot);

            smartParkingBoy.Park(new Car("car"));
        }
Ejemplo n.º 7
0
        void should_not_park_car_when_all_parking_lot_are_full()
        {
            var firstParkingLot  = new ParkingLot(1);
            var secondParkingLot = new ParkingLot(1);
            var smartParkingBoy  = new SmartParkingBoy(new List <ParkingLot> {
                firstParkingLot, secondParkingLot
            });

            smartParkingBoy.Park(new Car("Not care1"));
            ParkCarResult parkCarResult = smartParkingBoy.Park(new Car("Not care2"));

            Assert.Equal(ParkCarResult.Success, parkCarResult);

            parkCarResult = smartParkingBoy.Park(new Car("Not care3"));

            Assert.Equal(ParkCarResult.NoParkingSpace, parkCarResult);
        }
Ejemplo n.º 8
0
        public void Should_Smart_Park_No_Car_Given_Parking_Lot_Has_No_Position()
        {
            //given
            var parkedCar  = new Car("N98245");
            var parkingBoy = new SmartParkingBoy(new List <ParkingLot>()
            {
                new ParkingLot(1)
            });

            parkingBoy.Park(parkedCar, out _);

            //when
            var newCar    = new Car("A982453");
            var newTicket = parkingBoy.Park(newCar, out _);

            //then
            Assert.Null(newTicket);
        }
Ejemplo n.º 9
0
        void should_can_pick_the_car_when_parking_boy_park_a_car()
        {
            var parkingBoy = new SmartParkingBoy(new ParkingLot(10));
            var car        = new Car();
            var token      = parkingBoy.Park(car);

            var pickedCar = parkingBoy.Pick(token);

            Assert.Same(car, pickedCar);
        }
Ejemplo n.º 10
0
        public void should_park_a_car_into_a_parking_lot_which_has_space_and_get_a_ticket()
        {
            var list = new List <ParkingLot> {
                new ParkingLot(_capacity)
            };
            var smartParkingBoy = new SmartParkingBoy(list);

            var ticket = smartParkingBoy.Park(new Car());

            Assert.NotNull(ticket);
        }
        public void given_two_parkingLot_with_same_space_and_a_smart_parking_boy_when_smart_boy_park_a_car_then_the_car_in_the_first_parkingLot()
        {
            var firstParkinglot  = new OOParkingLot(1);
            var secondParkinglot = new OOParkingLot(1);

            var smartParkingBoy = new SmartParkingBoy(firstParkinglot, secondParkinglot);
            var car             = new Car("car");
            var carId           = smartParkingBoy.Park(car);

            Assert.AreSame(car, firstParkinglot.Pick(carId));
        }
Ejemplo n.º 12
0
        public void should_pick_the_same_car_after_parked_it()
        {
            var parkingLot      = new ParkingLot(1);
            var smartParkingBoy = new SmartParkingBoy(parkingLot);
            var car             = new Car();
            var token           = smartParkingBoy.Park(car);

            var pickedCar = smartParkingBoy.Pick(token);

            pickedCar.Should().BeSameAs(car);
        }
Ejemplo n.º 13
0
        public void given_a_parking_lot_and_a_smart_parking_boy_which_managed_by_parking_manager_when_parking_boy_park_a_car_then_manager_could_pick_the_car()
        {
            var parkinglot      = new OOParkingLot(1);
            var smartParkingBoy = new SmartParkingBoy(parkinglot);
            var manager         = new ParkingManager(smartParkingBoy);
            var car             = new Car("car");

            var carId = smartParkingBoy.Park(car);

            Assert.AreSame(car, manager.Pick(carId));
        }
Ejemplo n.º 14
0
        public void park_the_car_in_the_second_lot_and_return_a_ticket_when_park_a_vehicle_and_both_the_second_and_the_third_lot_have_most_empty_slots()
        {
            var parkingLots = new ParkingLot[3] {
                new ParkingLot(1), new ParkingLot(2), new ParkingLot(2)
            };
            var smartParkingBoy = new SmartParkingBoy(parkingLots);
            var fromParkingBoy  = smartParkingBoy.Park(new Vehicle());

            Assert.IsType <Ticket>(fromParkingBoy);
            Assert.Same(parkingLots[1], fromParkingBoy.ParkingLot);
        }
Ejemplo n.º 15
0
        void should_park_car_to_the_parking_lot_which_has_the_larget_space_count()
        {
            var parkingLot = new ParkingLot(10);
            var parkingBoy = new SmartParkingBoy(new ParkingLot(5), parkingLot, new ParkingLot(3));
            var car        = new Car();
            var token      = parkingBoy.Park(car);

            var pickedCar = parkingLot.Pick(token);

            Assert.Same(car, pickedCar);
        }
Ejemplo n.º 16
0
        public void should_throw_exception_when_parking_boy_get_car_given_an_invalid_ticket_and_a_parking_lot()
        {
            var parkinglot = new ParkingLot(_capacity);
            var boy        = new SmartParkingBoy(new List <ParkingLot> {
                parkinglot
            });
            var car = new Car();

            boy.Park(car);

            Assert.Throws <NotFoundException>(() => boy.GetCar(new object()));
        }
Ejemplo n.º 17
0
        public void Should_get_ticket_when_parking_boy_park_a_car()
        {
            var boy = new SmartParkingBoy(new List <Lot> {
                new Lot(1)
            });
            const string carId = "川A 123456";
            var          car   = new Car(carId);

            var ticket = boy.Park(car);

            Assert.NotNull(ticket);
        }
Ejemplo n.º 18
0
        public void Should_throw_error_when_smart_boy_try_to_park_a_car_into_2_full_lots()
        {
            var lot1 = new Lot(0);
            var lot2 = new Lot(0);
            var boy  = new SmartParkingBoy(new List <Lot> {
                lot1, lot2
            });
            const string carId = "川A 123456";
            var          car   = new Car(carId);

            Assert.Throws <NoEnoughSpotException>(() =>
                                                  boy.Park(car));
        }
Ejemplo n.º 19
0
        public void Should_Smart_Parking_Boy_Park_Mutiple_Cars_And_Fetch_The_Right_Car_Using_Ticket()
        {
            //given
            var expectedCar = new Car("N98245");

            //when
            var parkingBoy = new SmartParkingBoy(new List <ParkingLot>()
            {
                new ParkingLot()
            });
            var carList = new List <Car>()
            {
                new Car("car1"), new Car("car2"), new Car("car3")
            };

            carList.ForEach(car => parkingBoy.Park(car, out _));
            var ticket = parkingBoy.Park(expectedCar, out _);
            var car    = parkingBoy.Fetch(ticket, out _);

            //then
            Assert.Equal(expectedCar, car);
        }
Ejemplo n.º 20
0
        public void should_be_able_to_park_car_when_there_is_multi_parking_lot_with_same_avaliable_space()
        {
            var parkingLot1     = new ParkingLot(1);
            var parkingLot2     = new ParkingLot(1);
            var smartParkingBoy = new SmartParkingBoy(new List <ParkingLot> {
                parkingLot1, parkingLot2
            });
            var car = new Car();

            var ticket = smartParkingBoy.Park(car);

            Assert.Equal(car, parkingLot1.Pick(ticket) ?? parkingLot2.Pick(ticket));
        }
Ejemplo n.º 21
0
        public void should_park_car_by_smart_parking_boy()
        {
            var parkingLot      = new ParkingLot(1);
            var smartParkingBoy = new SmartParkingBoy(new List <ParkingLot>()
            {
                parkingLot
            });
            var car = new Car();

            var ticket = smartParkingBoy.Park(car);

            Assert.Equal(car, parkingLot.Pick(ticket));
        }
        public void Should_Park_Return_Null_When_Park_Null_Car()
        {
            // given
            Car car         = null;
            var parkingLot1 = new ParkingLot("ParkingLotOne");
            var parkingLot2 = new ParkingLot("ParkingLotOne");
            var parkingBoy  = new SmartParkingBoy("Jack", parkingLot1, parkingLot2);

            // when
            var parkingTicket = parkingBoy.Park(car);

            // then
            Assert.Null(parkingTicket);
        }
        public void Should_Park_Return_ParkingTicket_When_Park_To_Available_ParkingLot()
        {
            // given
            var car         = new Car("JAA8888");
            var parkingLot1 = new ParkingLot("ParkingLotOne");
            var parkingLot2 = new ParkingLot("ParkingLotOne");
            var parkingBoy  = new SmartParkingBoy("Jack", parkingLot1, parkingLot2);

            // when
            var parkingTicket = parkingBoy.Park(car);

            // then
            Assert.IsType <ParkingTicket>(parkingTicket);
        }
Ejemplo n.º 24
0
        public void should_park_car_to_parking_lot_2_if_parking_lot_2_has_more_space()
        {
            var parkingLot1     = new ParkingLot(1);
            var parkingLot2     = new ParkingLot(2);
            var car             = new Car();
            var smartParkingBoy = new SmartParkingBoy(new List <ParkingLot> {
                parkingLot1, parkingLot2
            });

            var ticket = smartParkingBoy.Park(car);

            Assert.NotEqual(car, parkingLot1.Pick(ticket));
            Assert.Equal(car, parkingLot2.Pick(ticket));
        }
Ejemplo n.º 25
0
        public void Should_get_ticket_from_lot_2_when_smart_boy_park_and_park_2_is_more_empty_than_lot_1()
        {
            var lot1 = new Lot(1);
            var lot2 = new Lot(2);
            var boy  = new SmartParkingBoy(new List <Lot> {
                lot1, lot2
            });
            const string carId = "川A 123456";
            var          car   = new Car(carId);

            var ticket = boy.Park(car);

            Assert.Equal(lot2.Id, ticket.LotId);
        }
Ejemplo n.º 26
0
        public void Should_Smart_Parking_Boy_Park_A_Car_And_Get_Ticket()
        {
            //given
            var expectedTicket = new Ticket("N98245");

            //when
            var parkingBoy = new SmartParkingBoy(new List <ParkingLot>()
            {
                new ParkingLot()
            });
            var ticket = parkingBoy.Park(new Car("N98245"), out _);

            //then
            Assert.Equal(expectedTicket.GetType(), ticket.GetType());
        }
Ejemplo n.º 27
0
        public void Should_Smart_Parking_Boy_Park_The_Car_To_Mutiple_Parking_Lots_And_Park_To_The_Parking_Lot_Has_More_Avaliable_Spaces()
        {
            //given
            var parkingLot2 = new ParkingLot(2);
            var parkingBoy  = new SmartParkingBoy(new List <ParkingLot>()
            {
                new ParkingLot(1), parkingLot2
            });

            //when
            var ticket = parkingBoy.Park(new Car("car"), out _);

            //then
            Assert.Contains(ticket.TicketNumber, parkingLot2.Tickets);
        }
Ejemplo n.º 28
0
        public void should_get_the_right_car_when_parking_boy_get_car_given_a_valid_ticket_and_a_parking_lot()
        {
            var parkinglot = new ParkingLot(_capacity);
            var boy        = new SmartParkingBoy(new List <ParkingLot> {
                parkinglot
            });
            var car    = new Car();
            var ticket = boy.Park(car);


            var gettedCar = boy.GetCar(ticket);

            Assert.NotNull(gettedCar);
            Assert.Equal(car, gettedCar);
        }
Ejemplo n.º 29
0
        void should_pick_the_car_from_parking_lots_when_park_a_car_by_parking_boy()
        {
            const string carId           = "ABC123";
            var          car             = new Car(carId);
            var          parkingLot      = new ParkingLot();
            var          smartParkingBoy = new SmartParkingBoy(new List <ParkingLot> {
                parkingLot
            });

            smartParkingBoy.Park(car);

            Car pickedCar = parkingLot.Pick(carId);

            Assert.Same(car, pickedCar);
        }
Ejemplo n.º 30
0
        public void Tickets_id_should_different_when_smart_boy_park_2_cars_into_2_lots_witch_are_same_empty()
        {
            var lot1 = new Lot(2);
            var lot2 = new Lot(2);
            var boy  = new SmartParkingBoy(new List <Lot> {
                lot1, lot2
            });
            var cars = new List <Car> {
                new Car("111"), new Car("222")
            };

            var tickets = boy.Park(cars);

            Assert.NotEqual(tickets[0].LotId, tickets[1].LotId);
        }