public void WhenCustomerWithContractArrivesAndLessThanTenPecentFree_ThenIsAccepted()
        {
            //arrage
            var numberOfParkingsToGenerate = ParkingGarage.NumberOfParkingSpots - ParkingGarage.RequiredFreeParkingSpots;
            var existingParkings = new HashSet<Parking>(TestUtils.GenerateCurrentParkings(numberOfParkingsToGenerate)); //450 spots taken

            var car = new Car("123ABC");

            var parkingRepository = new MockParkingRepository(existingParkings);
            var contractRepository = new MockParkingContractRepository(new List<IVehicle> { car });
            var invoiceRepository = new MockParkingInvoiceRepository(new List<ParkingInvoice>());

            var garage = new ParkingGarage(new ParkingService(parkingRepository, contractRepository, invoiceRepository));

            //act
            garage.StartParking(car);

            //assert

            Assert.AreEqual(garage.NumberOfCurrentlyParkedCars, 451);

            //expecting ParkingException NOT to be thrown
        }
        public void WhenCustomerWithContractParksMultipleTimes_ThenOneInvoiceCreatedWithAllAmounts()
        {
            //arrage

            var startTimes = new List<DateTime>
            {
                new DateTime(2015, 6, 1, 0, 0, 0), //June 1st 2015 00:00
                new DateTime(2015, 7, 1, 0, 0, 0) //July 1st 2015 00:00
            };

            var endTimes = new List<DateTime>
            {
                new DateTime(2015, 6, 1, 1, 0, 0), //June 1st 2015 01:00
                new DateTime(2015, 7, 1, 2, 15, 0) //July 1st 2015 02:15
            };

            var parkingRepository = new MockParkingRepository(new HashSet<Parking>(), startTimes, endTimes);
            var car = new Car("123ABC");

            var contractRepository = new MockParkingContractRepository(new List<IVehicle> { car });
            var invoiceRepository = new MockParkingInvoiceRepository(new List<ParkingInvoice>());

            var garage = new ParkingGarage(new ParkingService(parkingRepository, contractRepository, invoiceRepository));

            //act
            garage.StartParking(car); //June 1st 2015 00:00
            garage.StopParking(car); //June 1st 2015 01:00

            garage.StartParking(car); //July 1st 2015 00:00
            garage.StopParking(car); //July 1st 2015 02:15

            //assert
            var invoices = invoiceRepository.GetParkingInvoices(car);

            Assert.AreEqual(invoices.Count, 1);
            Assert.AreEqual(invoices[0].InvoiceAmount, 20); //1st parking - 1h, 2nd parking 2h 15min -> 3h
        }
        public void WhenTooWideVehicleEntersParkingGarage_ThenItIsRejected()
        {
            //arrage
            var parkingRepository = new MockParkingRepository(new HashSet<Parking>());
            var contractRepository = new MockParkingContractRepository(new List<IVehicle>());
            var invoiceRepository = new MockParkingInvoiceRepository(new List<ParkingInvoice>());

            var garage = new ParkingGarage(new ParkingService(parkingRepository, contractRepository, invoiceRepository));
            var wideCar = new WideCar("111ABC");

            //act
            garage.StartParking(wideCar);

            //assert

            //expecting VehicleSizeException
        }
        public void WhenParkingGarageFullAndCarArrivesToPark_ThenIsRejected()
        {
            //arrage
            var existingParkings = new HashSet<Parking>(TestUtils.GenerateCurrentParkings(ParkingGarage.NumberOfParkingSpots));

            var parkingRepository = new MockParkingRepository(existingParkings);
            var contractRepository = new MockParkingContractRepository(new List<IVehicle>());
            var invoiceRepository = new MockParkingInvoiceRepository(new List<ParkingInvoice>());

            var garage = new ParkingGarage(new ParkingService(parkingRepository, contractRepository, invoiceRepository));
            var car = new Car("123ABC");

            //act
            garage.StartParking(car);

            //assert

            //expecting ParkingException to be thrown
        }
        public void WhenMultipleCarsParked_ThenCorrectStatisticsCalculated()
        {
            //arrage

            var startTimes = new List<DateTime>
            {
                new DateTime(2015, 6, 1, 0, 0, 0), //June 1st 2015 00:00
                new DateTime(2015, 7, 1, 0, 0, 0), //July 1st 2015 00:00
                new DateTime(2015, 7, 2, 0, 0, 0), //July 2nd 2015 00:00
                new DateTime(2015, 7, 6, 0, 0, 0) //July 6th 2015 00:00
            };

            var endTimes = new List<DateTime>
            {
                new DateTime(2015, 6, 1, 1, 0, 0), //June 1st 2015 01:00
                new DateTime(2015, 7, 1, 2, 15, 0), //July 1st 2015 02:15
                new DateTime(2015, 7, 2, 3, 15, 0), //July 2nd 2015 03:15
                new DateTime(2015, 7, 6, 1, 15, 0), //July 6th 2015 01:15
            };

            var car1 = new Car("123ABC");
            var car2 = new Car("223ABC");
            var car3 = new Car("323ABC");

            var parkingRepository = new MockParkingRepository(new HashSet<Parking>(), startTimes, endTimes);

            var contractRepository = new MockParkingContractRepository(new List<IVehicle> { car1 });
            var invoiceRepository = new MockParkingInvoiceRepository(new List<ParkingInvoice>());
            var parkingService = new ParkingService(parkingRepository, contractRepository, invoiceRepository);

            var garage = new ParkingGarage(parkingService);

            //act
            garage.StartParking(car1); //June 1st 2015 00:00
            garage.StopParking(car1); //June 1st 2015 01:00

            garage.StartParking(car2); //July 1st 2015 00:00
            garage.StopParking(car2); //July 1st 2015 02:15

            garage.StartParking(car3); //July 2nd 2015 00:00
            garage.StopParking(car3); //July 2nd 2015 03:15

            garage.StartParking(car1); //July 6th 2015 00:00
            garage.StopParking(car1); //July 6th 2015 01:15

            //assert
            Assert.AreEqual(garage.TotalNumberOfParkedCars, 3);

            //1st parking - 1h
            //2nd parking - 3h
            //3rd parking - 4h
            //4th parking - 2h

            //PricePerHour = 5
            Assert.AreEqual(garage.TotalInvoicedAmount, 50);
        }