public async Task AddAsync(ParkingGarage parkingGarage) { try { await _documentClient.CreateDocumentAsync(GetDocumentCollectionUri(), parkingGarage, GetRequestOptions()); } catch (Exception e) { throw RepositoryExceptionBuilder.CreateExceptionForDocumentCreation(parkingGarage, e); } }
public void ShouldAddCarToGarage() { // Tests AddCar() method // Arrange var xxx = new ParkingGarage(); // Act xxx.AddCar(1971, "Ford", "Tempo"); // Assert Assert.NotEmpty(xxx.ListOfCars); }
public async Task UpdateAsync(ParkingGarage parkingGarage) { var documentUri = UriFactory.CreateDocumentUri(DatabaseId, CollectionId, parkingGarage.Id); try { await _documentClient.UpsertDocumentAsync(documentUri, parkingGarage, GetRequestOptions()); } catch (Exception e) { throw RepositoryExceptionBuilder.CreateExceptionForDocumentUpdate(documentUri, e); } }
public async Task <ActionResult <ParkingGarage> > PostParkingGarage([FromBody] ParkingGarage parkingGarage) { try { ParkingGarage newParkingGarage = await parkingGarageManager.CreateParkingGarage(parkingGarage); return(Ok(newParkingGarage)); } catch (Exception) { return(BadRequest()); } }
/// <summary> /// Get parking garage with id /// </summary> /// <param name="parkingGarageID"></param> /// <returns>ParkingGarage</returns> public async Task <ParkingGarage> GetParkingGarage(int parkingGarageID) { try { ParkingGarage parkingGarage = await context.ParkingGarages.Where(p => p.parkingGarageID == parkingGarageID).FirstOrDefaultAsync(); return(parkingGarage); } catch (Exception) { throw; } }
public void ShouldRemoveCarFromGarage() { // Tests RemoveCar() method // Arrange var xxx = new ParkingGarage(); // Act xxx.AddCar(1971, "Ford", "Tempo"); xxx.RemoveCar(0); // Assert Assert.Empty(xxx.ListOfCars); }
public void StatsDontExceedMax() { // Should be able to list stats of all cars // Create necessary method(s) // Garage class should provide cars // Program class should list all stats var xxx = new ParkingGarage(); xxx.ListOfCars.Add(new Car()); xxx.ListOfCars[0].AddFuel(); Assert.Equal(100, xxx.ListOfCars[0].GasLevel); }
/// <summary> /// creates new parking garage /// </summary> /// <param name="parkingGarage"></param> /// <returns>ParkingGarage</returns> public async Task <ParkingGarage> CreateParkingGarage(ParkingGarage parkingGarage) { try { await context.ParkingGarages.AddAsync(parkingGarage); context.SaveChanges(); return(parkingGarage); } catch (Exception) { throw; } }
public async Task GetParkingGarage_ReturnOk() { // Act var result = await controller.GetParkingGarage(1); // Assert OkObjectResult actionResult = Assert.IsType <OkObjectResult>(result.Result); Assert.NotNull(actionResult); actionResult = (OkObjectResult)result.Result; ParkingGarage model = (ParkingGarage)actionResult.Value; Assert.Equal("CimParking", model.name); Dispose(); }
public void ShouldFuelAllCars() { // Tests FuelAllCars() method // Arrange var xxx = new ParkingGarage(); // Act xxx.ListOfCars.Add(new Car(50)); xxx.ListOfCars.Add(new Car(50)); xxx.FuelAllCars(); // Assert int putGasInCars = xxx.ListOfCars[0].GasLevel + xxx.ListOfCars[1].GasLevel; Assert.Equal(200, putGasInCars); }
public override ActionResult Index(ParkingBlock currentBlock) { ParkingGateway gateway = new ParkingGateway(); ParkingGarage garage = gateway.GetParkingGarage(currentBlock.Location); ParkingViewModel model = new ParkingViewModel() { Heading = currentBlock.Heading, Location = currentBlock.Location, Address = garage.Address, TotalCapacity = garage.ParkingStatus.TotalCapacity, AvailableCapacity = garage.ParkingStatus.AvailableCapacity, IsOpen = garage.ParkingStatus.Open, LastUpdated = Convert.ToDateTime(garage.LastModifiedDate) }; return(PartialView(model)); }
public async Task PutParkingGarage_ReturnNotFound() { // Act ParkingGarage parkingGarage = new ParkingGarage() { name = "TestName", address = "TestAddress", city = "TestCity", postcode = "1234AA", totalParkingSpots = 100 }; var result = await controller.PutParkingGarage(0, parkingGarage); // Assert NotFoundResult actionResult = Assert.IsType <NotFoundResult>(result.Result); Assert.NotNull(actionResult); Dispose(); }
/// <summary> /// deletes parking garage /// </summary> /// <param name="parkingGarageID"></param> /// <returns>ParkingGarage</returns> public async Task <ParkingGarage> DeleteParkingGarage(int parkingGarageID) { try { ParkingGarage parkingGarage = await context.ParkingGarages.Where(p => p.parkingGarageID == parkingGarageID).FirstOrDefaultAsync(); if (parkingGarage == null) { return(null); } context.ParkingGarages.Remove(parkingGarage); context.SaveChanges(); return(parkingGarage); } catch (Exception) { throw; } }
/// <summary> /// Updates parking garage /// </summary> /// <param name="parkingGarage"></param> /// <returns>ParkingGarage</returns> public async Task <ParkingGarage> UpdateParkingGarage(int id, ParkingGarage parkingGarage) { try { ParkingGarage oldparkingGarage = await context.ParkingGarages.Where(p => p.parkingGarageID == id).FirstOrDefaultAsync(); if (oldparkingGarage == null) { return(null); } oldparkingGarage = parkingGarage; context.ParkingGarages.Update(oldparkingGarage); context.SaveChanges(); return(oldparkingGarage); } catch (Exception) { throw; } }
public async Task <ActionResult <ParkingGarage> > PutParkingGarage(int id, [FromBody] ParkingGarage parkingGarage) { try { ParkingGarage updatedParkingGarage = await parkingGarageManager.UpdateParkingGarage(id, parkingGarage); if (updatedParkingGarage == null) { return(NotFound()); } return(Ok(parkingGarage)); } catch (NullReferenceException) { return(NotFound()); } catch (Exception) { return(BadRequest()); } }
public async Task <ActionResult <ParkingGarage> > DeleteParkingGarage(int id) { try { ParkingGarage parkingGarage = await parkingGarageManager.DeleteParkingGarage(id); if (parkingGarage == null) { return(NotFound()); } return(Ok(parkingGarage)); } catch (NullReferenceException) { return(NotFound()); } catch (Exception) { return(BadRequest()); } }
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 async Task PutParkingGarage_ReturnOk() { // Act ParkingGarage parkingGarage = new ParkingGarage() { name = "TestName", address = "TestAddress", city = "TestCity", postcode = "1234AA", totalParkingSpots = 100 }; var result = await controller.PutParkingGarage(1, parkingGarage); // Assert OkObjectResult actionResult = Assert.IsType <OkObjectResult>(result.Result); Assert.NotNull(actionResult); actionResult = (OkObjectResult)result.Result; ParkingGarage model = (ParkingGarage)actionResult.Value; Assert.Equal("TestName", model.name); Dispose(); }
public async Task Seed() { _db.Database.EnsureCreated(); var user = await _userManager.FindByEmailAsync("*****@*****.**"); var user2 = await _userManager.FindByEmailAsync("*****@*****.**"); //if (user == null) //{ //seeding simple user data into database /* user = new Manager { * UserName = "******", * Email = "*****@*****.**", * Name = "Brett", * SSN = 123456789, * HireDate = DateTime.Now * }; * * * user2 = new Manager { * UserName = "******", * Email = "*****@*****.**", * Name = "Jake", * SSN = 123456289, * HireDate = DateTime.Now * }; * * * //var result = await _userManager.CreateAsync(user, "P@ssword1!"); * //var result2 = await _userManager.CreateAsync(user2, "P@ssword1!"); * //if(result != IdentityResult.Success) { * // throw new InvalidOperationException("Failed to create default user"); * //} * * * var garage = new ParkingGarage() { * ID = 1, * Manager = user, * Floors = 5, * Address = "123 Apple Street" * }; * */var garage3 = new ParkingGarage() { ID = 4, Manager = user2, Floors = 5, Address = "258 Buckeye Drive" }; /* * var space1 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 1, * Floor = 1, * Status = "open" * }; * * var garage2 = new ParkingGarage() { * ID = 2, * Manager = user, * Floors = 3, * Address = "321 Pear Street" * }; * * * var space2 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 2, * Floor = 3, * Status = "open" * }; * * var space3 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 3, * Floor = 1, * Status = "out" * }; * * var space4 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 4, * Floor = 1, * Status = "out" * }; * * var space5 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 5, * Floor = 3, * Status = "out" * }; * * var space6 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 6, * Floor = 3, * Status = "inuse" * }; * * var space7 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 7, * Floor = 3, * Status = "open" * }; * * var space8 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 8, * Floor = 1, * Status = "out" * }; * * var space9 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 9, * Floor = 1, * Status = "out" * }; * * var space10 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 10, * Floor = 1, * Status = "out" * }; * * var space11 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 11, * Floor = 1, * Status = "open" * }; * * var space12 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 12, * Floor = 1, * Status = "open" * }; * * var space13 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 13, * Floor = 4, * Status = "open" * }; * * var space14 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 14, * Floor = 3, * Status = "inuse" * }; * * var space15 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 15, * Floor = 5, * Status = "open" * }; * * var space16 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 16, * Floor = 4, * Status = "inuse" * }; * * var space17 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 17, * Floor = 1, * Status = "open" * }; * * var space18 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 18, * Floor = 1, * Status = "open" * }; * * var space19 = new ParkingSpace() { * Garage = garage, * Manager = user, * ID = 19, * Floor = 4, * Status = "inuse" * }; * * var space20 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 20, * Floor = 1, * Status = "open" * }; * * var space21 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 21, * Floor = 3, * Status = "open" * }; * * var space22 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 22, * Floor = 1, * Status = "open" * }; * * var space23 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 23, * Floor = 1, * Status = "open" * }; * * var space24 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 24, * Floor = 1, * Status = "open" * }; * * var space25 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 25, * Floor = 1, * Status = "open" * }; * * var space26 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 26, * Floor = 1, * Status = "open" * }; * * var space27 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 27, * Floor = 1, * Status = "inuse" * }; * * var space28 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 28, * Floor = 2, * Status = "open" * }; * * var space29 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 29, * Floor = 2, * Status = "out" * }; * * var space30 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 30, * Floor = 2, * Status = "open" * }; * * var space31 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 31, * Floor = 2, * Status = "out" * }; * * var space32 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 32, * Floor = 2, * Status = "open" * }; * * var space33 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 33, * Floor = 3, * Status = "inuse" * }; * * var space34 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 34, * Floor = 3, * Status = "open" * }; * * var space35 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 35, * Floor = 1, * Status = "open" * }; * * var space36 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 36, * Floor = 1, * Status = "open" * }; * * var space37 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 37, * Floor = 1, * Status = "inuse" * }; * * var space38 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 38, * Floor = 2, * Status = "inuse" * }; * * var space39 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 39, * Floor = 3, * Status = "inuse" * }; * * var space40 = new ParkingSpace() { * Garage = garage2, * Manager = user, * ID = 40, * Floor = 2, * Status = "out" * }; * * var space41 = new ParkingSpace() { * Garage = garage3, * Manager = user2, * ID = 41, * Floor = 3, * Status = "open" * }; * * var space42 = new ParkingSpace() { * Garage = garage3, * Manager = user2, * ID = 42, * Floor = 1, * Status = "open" * }; * * var space43 = new ParkingSpace() { * Garage = garage3, * Manager = user2, * ID = 43, * Floor = 2, * Status = "out" * }; * * var space44 = new ParkingSpace() { * Garage = garage3, * Manager = user2, * ID = 44, * Floor = 1, * Status = "inuse" * }; * * var space45 = new ParkingSpace() { * Garage = garage3, * Manager = user2, * ID = 45, * Floor = 2, * Status = "inuse" * }; * * var space46 = new ParkingSpace() { * Garage = garage3, * Manager = user2, * ID = 46, * Floor = 3, * Status = "inuse" * }; * * var space47 = new ParkingSpace() { * Garage = garage3, * Manager = user2, * ID = 47, * Floor = 2, * Status = "out" * }; */ var space48 = new ParkingSpace() { Garage = garage3, Manager = user2, ID = 48, Floor = 3, Status = "inuse" }; var space49 = new ParkingSpace() { Garage = garage3, Manager = user2, ID = 49, Floor = 1, Status = "open" }; var space50 = new ParkingSpace() { Garage = garage3, Manager = user2, ID = 50, Floor = 2, Status = "inuse" }; var space51 = new ParkingSpace() { Garage = garage3, Manager = user2, ID = 51, Floor = 3, Status = "out" }; /* _db.Garages.Add(garage); * _db.Garages.Add(garage2); * _db.Garages.Add(garage3); * * _db.ParkingSpaces.Add(space1); * _db.ParkingSpaces.Add(space2); * _db.ParkingSpaces.Add(space3); * _db.ParkingSpaces.Add(space4); * _db.ParkingSpaces.Add(space5); * _db.ParkingSpaces.Add(space6); * _db.ParkingSpaces.Add(space7); * _db.ParkingSpaces.Add(space8); * _db.ParkingSpaces.Add(space9); * _db.ParkingSpaces.Add(space10); * _db.ParkingSpaces.Add(space11); * _db.ParkingSpaces.Add(space12); * _db.ParkingSpaces.Add(space13); * _db.ParkingSpaces.Add(space14); * _db.ParkingSpaces.Add(space15); * _db.ParkingSpaces.Add(space16); * _db.ParkingSpaces.Add(space17); * _db.ParkingSpaces.Add(space18); * _db.ParkingSpaces.Add(space19); * _db.ParkingSpaces.Add(space20); * _db.ParkingSpaces.Add(space21); * _db.ParkingSpaces.Add(space22); * _db.ParkingSpaces.Add(space23); * _db.ParkingSpaces.Add(space24); * _db.ParkingSpaces.Add(space25); * _db.ParkingSpaces.Add(space26); * _db.ParkingSpaces.Add(space27); * _db.ParkingSpaces.Add(space28); * _db.ParkingSpaces.Add(space29); * _db.ParkingSpaces.Add(space30); * _db.ParkingSpaces.Add(space31); * _db.ParkingSpaces.Add(space32); * _db.ParkingSpaces.Add(space33); * _db.ParkingSpaces.Add(space34); * _db.ParkingSpaces.Add(space35); * _db.ParkingSpaces.Add(space36); * _db.ParkingSpaces.Add(space37); * _db.ParkingSpaces.Add(space38); * _db.ParkingSpaces.Add(space39); * _db.ParkingSpaces.Add(space40); * _db.ParkingSpaces.Add(space41); * _db.ParkingSpaces.Add(space42); * _db.ParkingSpaces.Add(space43); * _db.ParkingSpaces.Add(space44); * _db.ParkingSpaces.Add(space45); * _db.ParkingSpaces.Add(space46); * _db.ParkingSpaces.Add(space47); */ _db.ParkingSpaces.Add(space48); _db.ParkingSpaces.Add(space49); _db.ParkingSpaces.Add(space50); _db.ParkingSpaces.Add(space51); _db.SaveChanges(); //} }
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 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); }
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 }