public void GivenListParkinglotDto_WhenGetAll_ThenReturnOKWithList() { //Given ParkinglotDto parkinglotDto = new ParkinglotDto(); List <ParkinglotDto> listParkinglotDto = new List <ParkinglotDto>() { parkinglotDto }; Parkinglot parkinglot = new Parkinglot(); List <Parkinglot> listParkinglot = new List <Parkinglot>() { parkinglot }; _parkinglotService.GetAll().Returns(listParkinglot); //_parkinglotMapper.ListToDtoList(listParkinglot).Returns(listParkinglotDto); //When OkObjectResult ok = (OkObjectResult)_parkinglotController.GetAllParkinglots().Result; //ActionResult<List<ParkinglotDto>> returnValue = _parkinglotController.GetAllParkinglots(); //then //OkObjectResult returnValue = (OkObjectResult)_parkinglotController.GetAllParkinglots().Result; Assert.Equal(200, ok.StatusCode); Assert.IsType <List <ParkinglotDto> >(ok.Value); }
private void Dialog_mGo(object sender, OnGoEventArgs e) { int index = e.Position; Parkinglot parkinglot = mParkinglots[index]; LatLng parkingPosition = new LatLng(parkinglot.lat, parkinglot.lng); LatLng clientPosition = DeviceManager.GetClientLocation(locationProvider, currentLocation); mMarkerParking = MarkerManager.CreateMarker(parkingPosition, parkinglot.name, parkinglot.id + ":" + parkinglot.address, BitmapDescriptorFactory.HueRed); mMarkerUser = MarkerManager.CreateUserPosition(clientPosition); if (mMap != null) { mMap.AddMarker(mMarkerParking); mMap.AddMarker(mMarkerUser); // Sete el Info Windows mMap.SetInfoWindowAdapter(this); // Agregarle Eventos a la Info Window // La Info Window solo puede contener eventos que involucren a TODA la ventana // No a componentes internos mMap.SetOnInfoWindowClickListener(this); RouteToDestination(clientPosition, parkingPosition); } }
public void GivenAllNeccesaryPropertiesFromParkinglots_WhenMakingNewParkinglotsObject_ThenNoErrorThrow() { //Given Parkinglot testParkinglot = new Parkinglot() { Name = "test", Capacity = 1, AvailablePlaces = 1, DivisionId = 2, PricePerHour = 3, ContactPersonId = 4, PlAddress = new Address { StreetName = "ljhg", StreetNumber = "kuh", PostalCode = "lkjh", CityName = "lkjh" }, BuildingTypeId = 5 }; //when testParkinglot.CheckValues(); //then Assert.Equal("test", testParkinglot.Name); }
public void SetParkinglot(Parkinglot parkinglot, int position) { mParkinglot = parkinglot; mPosition = position; loadParkinglot(); }
private void btnAddParkingspot_Click(object sender, EventArgs e) { Parkingspots.Items.Clear(); Parkinglot parking = new Parkinglot("Spot one", 3, 2) { Type = parkingLotType.small }; Parkinglot parkingTwo = new Parkinglot("Spot two", 4, 3) { Type = parkingLotType.medium }; Parkinglot parkingThree = new Parkinglot("Spot three", 5, 4) { Type = parkingLotType.large }; entre.Add(parking); entre.Add(parkingTwo); entre.Add(parkingThree); foreach (Parkinglot park in entre.ParkedCars) { Parkingspots.Items.Add(park); } }
public bool AddCarToAParkingLot(string licensePlate) { Car car = Cars.FirstOrDefault(x => x.LicencePlate == licensePlate); Parkinglot parkinglot = null; foreach (Parkinglot lot in ParkedCars.Where(x => x.Type == parkingLotType.small && !x.Reserved)) { if (car.Length < lot.Length && car.Width < lot.Width) { parkinglot = lot; } } if (parkinglot == null) { foreach (Parkinglot lot in ParkedCars.Where(x => x.Type == parkingLotType.medium && !x.Reserved)) { if (car.Length < lot.Length && car.Width < lot.Width) { parkinglot = lot; } } } if (parkinglot == null) { parkinglot = ParkedCars.FirstOrDefault(x => x.Type == parkingLotType.large && !x.Reserved); } parkinglot.Car = car; return(true); }
public void GivenAnAllocationService_WhenStartAllocationWithDiffLiceplate_ThenExecptionThrown() { //Given Allocation startAllocation = new Allocation() { MemberPersonId = 1, ParkinglotId = 1 }; Parkinglot parkinglot = new Parkinglot() { Id = 1 }; _parkinglotService.GetOneParkinglot(1).Returns(parkinglot); _personService.GetById(1).Returns(_testPerson); _parkinglotService.ReduceAvailableParkingSpots(parkinglot).Returns(true); _allocationRepository.SaveNewAllocation(startAllocation).Returns(startAllocation); var allocationService = new AllocationService(_allocationRepository, _parkinglotService, _personService); //When Action action = () => allocationService.StartAllocation(startAllocation, new LicensePlate("Fout", "BE")); //Then var exception = Assert.Throws <EntityNotValidException>(action); Assert.Contains("the following entity was found to be invalid", exception.Message); }
public void should_pick_car_after_the_car_parked() { Parkinglot parkinglot = new Parkinglot(); Car carPickup = parkinglot.Pick(parkinglot.Park(new Car())); Assert.NotNull(carPickup); }
public void should_print_report_when_manager_has_only_one_parkinglot() { var parkinglotWit1Car3Availiable = new Parkinglot(4); var parkingDirector = new ParkingDirector(new ParkingManager(parkinglotWit1Car3Availiable)); parkinglotWit1Car3Availiable.Park(new Car()); Assert.Equal("M 1 3\r\n P 1 3\r\n", parkingDirector.Report()); }
public void should_not_pick_with_wrong_parkingToken() { var parkinglot = new Parkinglot(); parkinglot.Park(new Car()); var parkingToken = "123324"; Assert.Null(parkinglot.Pick(parkingToken)); }
public bool ReduceAvailableParkingSpots(Parkinglot parkinglot) { if (parkinglot.AvailablePlaces == 0) { throw new EntityNotValidException("Parkinglot", parkinglot.Id.ToString()); } parkinglot.AvailablePlaces--; return(_parkinglotRepository.UpdateParkinglot(parkinglot)); }
public void should_print_report_when_manager_has_one_parkingboy_with_one_parklot() { var parkinglotWit1Car3Availiable = new Parkinglot(4); var parkingDirector = new ParkingDirector(new ParkingManager(ParkingBoyFactory.CreateParkingBoy(parkinglotWit1Car3Availiable))); parkinglotWit1Car3Availiable.Park(new Car()); Assert.Equal("M 1 3\r\n B 1 3\r\n P 1 3\r\n", parkingDirector.Report()); }
public void should_park_car_when_only_one_parkinglot() { var parkinglot = new Parkinglot(); var parkingBoy = ParkingBoyFactory.CreateParkingBoy(parkinglot); var car = new Car(); var parkingToken = parkingBoy.Park(car); Assert.Same(car, parkinglot.Pick(parkingToken)); }
public void should_pick_car_when_there_are_two_parkinglot_parked() { var parkinglot = new Parkinglot(); var parkingBoy = ParkingBoyFactory.CreateParkingBoy(new Parkinglot(), parkinglot); var car = new Car(); var parkingToken = parkinglot.Park(car); Assert.Same(car, parkingBoy.Pick(parkingToken)); }
public void should_not_pickup_car_twice() { var parkinglot = new Parkinglot(); var parkingToken = parkinglot.Park(new Car()); parkinglot.Pick(parkingToken); var carPickUp = parkinglot.Pick(parkingToken); Assert.Null(carPickUp); }
public void should_print_report_when_manager_has_only_two_parkinglot() { var firstParkinglotWit1Car3Availiable = new Parkinglot(4); var secondParkinglotWit1Car3Availiable = new Parkinglot(3); var parkingDirector = new ParkingDirector(new ParkingManager(firstParkinglotWit1Car3Availiable, secondParkinglotWit1Car3Availiable)); firstParkinglotWit1Car3Availiable.Park(new Car()); Assert.Equal("M 1 6\r\n P 1 3\r\n P 0 3\r\n", parkingDirector.Report()); }
public void should_parked_in_higher_vacancy_rate_when_no_car_parked_before_with_different_init() { var higherVacancyRateParkinglot = new Parkinglot(2); var lowerVacancyRateParkinglot = new Parkinglot(3); var superParkingBoy = ParkingBoyFactory.CreateSuperParkingBoy(higherVacancyRateParkinglot,lowerVacancyRateParkinglot); var car = new Car(); var parkingToken = superParkingBoy.Park(car); Assert.Same(car, higherVacancyRateParkinglot.Pick(parkingToken)); }
public void should_park_car_sequently_when_first_parkinglot_is_full_and_second_not() { var firstFullParkinglot = new Parkinglot(1); firstFullParkinglot.Park(new Car()); var secondNotFullParkinglot = new Parkinglot(1); var parkingBoy = ParkingBoyFactory.CreateParkingBoy(firstFullParkinglot, secondNotFullParkinglot); var car = new Car(); var parkingToken = parkingBoy.Park(car); Assert.Same(car, secondNotFullParkinglot.Pick(parkingToken)); }
public void should_failed_pick_car_after_parked_when_all_parkinglot_is_full() { var firstParkinglot = new Parkinglot(1); firstParkinglot.Park(new Car()); var secondParkinglot = new Parkinglot(1); secondParkinglot.Park(new Car()); var parkingBoy = ParkingBoyFactory.CreateParkingBoy(firstParkinglot); var parkingToken = parkingBoy.Park(new Car()); Assert.Null(parkingBoy.Pick(parkingToken)); }
public void should_pick_right_car_when_mutiple_cars_parked() { Parkinglot parkinglot = new Parkinglot(); parkinglot.Park(new Car()); Car qq = new Car(); var parkingTokenForQQ = parkinglot.Park(qq); parkinglot.Park(new Car()); var carPickup = parkinglot.Pick(parkingTokenForQQ); Assert.Same(qq, carPickup); }
public bool Add(Parkinglot park) { if (park == null) { return(false); } else { ParkedCars.Add(park); return(true); } }
public void should_park_in_high_available_stalls_when_no_car_parked_before_with_differet_init_count() { var moreAvailableStalls = new Parkinglot(2); var parkingBoy = ParkingBoyFactory.CreateSmartParkingBoy( new Parkinglot(1), moreAvailableStalls); var car = new Car(); var token = parkingBoy.Park(car); Assert.Same(car, moreAvailableStalls.Pick(token)); }
public void should_park_in_high_available_stalls_when_no_car_parked_before_with_same_init() { var parkinglot = new Parkinglot(1); var parkingBoy = ParkingBoyFactory.CreateSmartParkingBoy( parkinglot, new Parkinglot(1)); var car = new Car(); var token = parkingBoy.Park(car); Assert.Same(car, parkinglot.Pick(token)); }
public void should_failed_pick_when_all_parkinglots_are_full() { var firstParkinglot = new Parkinglot(1); firstParkinglot.Park(new Car()); var secondParkinglot = new Parkinglot(1); secondParkinglot.Park(new Car()); var smartParkingBoy = ParkingBoyFactory.CreateSmartParkingBoy(firstParkinglot, secondParkinglot); var parkingToken = smartParkingBoy.Park(new Car()); Assert.Null(smartParkingBoy.Pick(parkingToken)); }
public void GivenAParkinglotService_WhenCreateParkinglot_ThenANewParkinglotObjectIsReturned() { //Given Parkinglot newParkinglot = new Parkinglot(); IParkinglotRepository parkinglotRepository = Substitute.For <IParkinglotRepository>(); var parkinglotService = new ParkinglotService(parkinglotRepository); //When var returnParkinglot = parkinglotService.CreateParkinglot(newParkinglot); //Then Assert.IsType <Parkinglot>(returnParkinglot); }
public void GivenAParkinglotService_WhenCreateParkinglot_ThenReposotoryReceivedNewParkinglot() { //Given Parkinglot newParkinglot = new Parkinglot(); IParkinglotRepository parkinglotRepository = Substitute.For <IParkinglotRepository>(); var parkinglotService = new ParkinglotService(parkinglotRepository); //When var returnParkinglot = parkinglotService.CreateParkinglot(newParkinglot); //Then parkinglotRepository.Received().SaveNewParkinglot(newParkinglot); }
private void FillingInMemoryDatabase(ParkSharkContext context) { #region fillingInMemoryDatabase Address adress = new Address() { StreetNumber = "1", StreetName = "tt", CityName = "er", PostalCode = "4153", }; context.Persons.Add(new Person( 1, "Person1", "MobilePhone1", "000", adress, "*****@*****.**", new LicensePlate("123", "BE"))); context.Set <BuildingType>().Add(new BuildingType() { Id = 1, Name = "Underground" }); context.Divisions.Add(new Division(1, "Division1", "Original1", 1, null)); Parkinglot parkinglotToCreate = new Parkinglot() { Id = 1, BuildingTypeId = 1, Capacity = 5, AvailablePlaces = 5, ContactPersonId = 1, DivisionId = 1, Name = "xxxxxxxx", PlAddress = new Address() { StreetNumber = "1", StreetName = "tt", CityName = "er", PostalCode = "4153" }, PricePerHour = 10 }; context.Add(parkinglotToCreate); context.SaveChanges(); #endregion fillingInMemoryDatabase }
public void should_park_in_high_available_stalls_when_parked_differently_before_with_same_init() { var lessAvailableStalls = new Parkinglot(2); lessAvailableStalls.Park(new Car()); var moreAvailableStall = new Parkinglot(2); var parkingBoy = ParkingBoyFactory.CreateSmartParkingBoy( lessAvailableStalls, moreAvailableStall); var car = new Car(); var token = parkingBoy.Park(car); Assert.Same(car, moreAvailableStall.Pick(token)); }
public void should_pick_from_his_parkinglot() { var parkinglot = new Parkinglot(1); var parkingManager = new ParkingManager( ParkingBoyFactory.CreateParkingBoy(new Parkinglot(0)), ParkingBoyFactory.CreateSmartParkingBoy(new Parkinglot(0)), ParkingBoyFactory.CreateSuperParkingBoy(new Parkinglot(0)), parkinglot); var car = new Car(); var token = parkinglot.Park(car); Assert.Same(car, parkingManager.Pick(token)); }
public void GivenAParkinglotService_WhenGetOneNoneExistingParkinglot_ThenThrowException() { //Given Parkinglot newParkinglot = new Parkinglot(); IParkinglotRepository parkinglotRepository = Substitute.For <IParkinglotRepository>(); parkinglotRepository.GetOneParkinglot(5).ReturnsNull(); var parkinglotService = new ParkinglotService(parkinglotRepository); //When Action action = () => parkinglotService.GetOneParkinglot(5); //Then Assert.Throws <EntityNotFoundException>(action); }
public void GivenCompletParkinglotDto_WhenCreatingNewParkinglot_ThenReturnStatusCode201WithParkinglotDto() { //Given ParkinglotDto parkinglotDto = new ParkinglotDto(); Parkinglot parkinglot = new Parkinglot(); //_parkinglotMapper.DtoToDomain(parkinglotDto).Returns(parkinglot); _parkinglotService.CreateParkinglot(_parkinglotMapper.DtoToDomain(parkinglotDto)).Returns(parkinglot); //When CreatedResult returnValue = (CreatedResult)_parkinglotController.Createparkinglot(parkinglotDto).Result; //then Assert.Equal(201, returnValue.StatusCode); }
public void GivenAParkinglotService_WhenGetOneParkinglot_ThenReturnParkinglot() { //Given Parkinglot newParkinglot = new Parkinglot(); IParkinglotRepository parkinglotRepository = Substitute.For <IParkinglotRepository>(); parkinglotRepository.GetOneParkinglot(5).Returns(newParkinglot); var parkinglotService = new ParkinglotService(parkinglotRepository); //When var returnParkinglot = parkinglotService.GetOneParkinglot(5); //Then Assert.IsType <Parkinglot>(returnParkinglot); }
public Allocation StartAllocation(Allocation newAllocation, LicensePlate memberLicensePlate) { Parkinglot parkinglotToChange = _parkinglotService.GetOneParkinglot(newAllocation.ParkinglotId); Person person = GetPersonFromAllocation(newAllocation); if (person.LicensePlate.Equals(memberLicensePlate)) { _parkinglotService.ReduceAvailableParkingSpots(parkinglotToChange); } if (!person.LicensePlate.Equals(memberLicensePlate)) { throw new EntityNotValidException("Licenseplate", memberLicensePlate); } return(_allocationRepository.SaveNewAllocation(newAllocation)); }
public void GivenAParkinglotService_WhenReduceAvailablePlacesParkinglot_ThenThrowExceptionIfGoesNegative() { //Given Parkinglot newParkinglot = new Parkinglot() { AvailablePlaces = 0 }; IParkinglotRepository parkinglotRepository = Substitute.For <IParkinglotRepository>(); var parkinglotService = new ParkinglotService(parkinglotRepository); //When Action action = () => parkinglotService.ReduceAvailableParkingSpots(newParkinglot); //Then Assert.Throws <EntityNotValidException> (action); }
public void should_print_report_when_manager_has_two_parklots_and_one_parkingboy_with_two_parklot() { var parkinglotWith1Parked2Available = new Parkinglot(3); var parkinglotWith1Parked3Availible = new Parkinglot(4); var parkingDirector = new ParkingDirector( new ParkingManager( new Parkinglot(3), ParkingBoyFactory.CreateParkingBoy(parkinglotWith1Parked2Available, parkinglotWith1Parked3Availible), new Parkinglot(4) )); parkinglotWith1Parked2Available.Park(new Car()); parkinglotWith1Parked3Availible.Park(new Car()); Assert.Equal("M 2 12\r\n P 0 3\r\n B 2 5\r\n P 1 2\r\n P 1 3\r\n P 0 4\r\n", parkingDirector.Report()); }
public void GivenListParkinglotDto_WhenGetOnel_ThenReturnOKWithOne() { //Given Parkinglot parkinglot = new Parkinglot(); _parkinglotService.GetOneParkinglot(1).Returns(parkinglot); _parkinglotMapper.DomainToDto(parkinglot).Returns(new ParkinglotDto()); //When OkObjectResult ok = (OkObjectResult)_parkinglotController.GetOneParkinglot(1).Result; //then Assert.Equal(200, ok.StatusCode); Assert.IsType <ParkinglotDto>(ok.Value); }
public void GivenAParkinglotService_WhenGetAllParkinglots_ThenRepositoryReceivedGetAllParkinglots() { //Given Parkinglot newParkinglot = new Parkinglot(); List <Parkinglot> testParkinglots = new List <Parkinglot>() { newParkinglot }; IParkinglotRepository parkinglotRepository = Substitute.For <IParkinglotRepository>(); var parkinglotService = new ParkinglotService(parkinglotRepository); //When var returnParkinglot = parkinglotService.GetAll(); //Then parkinglotRepository.Received().GetAllParkinglots(); }
public void GivenAParkinglotService_WhenReduceAvailablePlacesParkinglot_ThenReduceAvailablePlaces() { //Given Parkinglot newParkinglot = new Parkinglot() { AvailablePlaces = 5 }; IParkinglotRepository parkinglotRepository = Substitute.For <IParkinglotRepository>(); var parkinglotService = new ParkinglotService(parkinglotRepository); parkinglotRepository.UpdateParkinglot(newParkinglot).Returns(true); //When parkinglotService.ReduceAvailableParkingSpots(newParkinglot); //Then Assert.Equal(4, newParkinglot.AvailablePlaces); }
public void GivenAParkinglotService_WhenGetAllParkinglots_ThenListOfParkinglotsIsReturned() { //Given Parkinglot newParkinglot = new Parkinglot(); List <Parkinglot> testParkinglots = new List <Parkinglot>() { newParkinglot }; IParkinglotRepository parkinglotRepository = Substitute.For <IParkinglotRepository>(); parkinglotRepository.GetAllParkinglots().Returns(testParkinglots); var parkinglotService = new ParkinglotService(parkinglotRepository); //When var returnParkinglot = parkinglotService.GetAll(); //Then Assert.IsType <List <Parkinglot> >(returnParkinglot); }
public void GivenListOfParkinglots_WhenGetOneNotExistingParkinglot_ThenReturnNull() { //Given var parkinglot = new Parkinglot(); var options = new DbContextOptionsBuilder <ParkSharkContext>() .UseInMemoryDatabase("parkshark" + Guid.NewGuid().ToString("n")) .Options; //When using (var context = new ParkSharkContext(options)) { IParkinglotRepository parkinglotRepository = new ParkinglotRepository(context); var result = parkinglotRepository.GetOneParkinglot(5); //Then Assert.Null(result); } }
public void GivenAParkinglot_WhenSaveParkinglot_ThenRepoReturnsTrue() { //Given var parkinglot = new Parkinglot(); var options = new DbContextOptionsBuilder <ParkSharkContext>() .UseInMemoryDatabase("parkshark" + Guid.NewGuid().ToString("n")) .Options; var result = false; //When using (var context = new ParkSharkContext(options)) { IParkinglotRepository parkinglotRepository = new ParkinglotRepository(context); result = parkinglotRepository.SaveNewParkinglot(parkinglot); } //Then Assert.True(result); }
public void GivenInCompletParkinglotDto_WhenCreatingNewParkinglot_ThenReturnStatusCode400() { //Given ParkinglotDto parkinglotDto = new ParkinglotDto(); Parkinglot parkinglot = new Parkinglot(); _parkinglotMapper.When(fake => fake.DtoToDomain(parkinglotDto)) .Do(call => { throw new EntityNotValidException("Name required", this); }); // is allowed but only if void //_parkinglotMapper.DtoToDomain(parkinglotDto) // .Returns(x => throw new EntityNotValidException("Name required", this)); Action action = () => _parkinglotController.Createparkinglot(parkinglotDto); var exception = Assert.Throws <EntityNotValidException>(action); Assert.Contains("Name required", exception.Message); ////then //Assert.IsType<BadRequestObjectResult>(returnValue); }
public void GivenNotAllNeccesaryPropertiesFromParkinglots_WhenMakingNewParkinglotsObject_ThenErrorThrow() { //Given Parkinglot testParkinglot = new Parkinglot() { Name = "test", Capacity = 1, AvailablePlaces = 1, DivisionId = 2, ContactPersonId = 4, PlAddress = new Address(), BuildingTypeId = 5 }; //when Action action = () => testParkinglot.CheckValues(); //then var exception = Assert.Throws <EntityNotValidException>(action); Assert.Contains("is required", exception.Message); }
public void GivenAnAllocationService_WhenStartAllocation_ThenANewLocationIsReturned() { //Given Allocation startAllocation = new Allocation() { MemberPersonId = 1, ParkinglotId = 1 }; Parkinglot parkinglot = new Parkinglot() { Id = 1 }; _parkinglotService.GetOneParkinglot(1).Returns(parkinglot); _personService.GetById(1).Returns(_testPerson); _parkinglotService.ReduceAvailableParkingSpots(parkinglot).Returns(true); _allocationRepository.SaveNewAllocation(startAllocation).Returns(startAllocation); var allocationService = new AllocationService(_allocationRepository, _parkinglotService, _personService); //When var returnAllocation = allocationService.StartAllocation(startAllocation, _testPerson.LicensePlate); //Then Assert.IsType <Allocation>(returnAllocation); }
public void GivenAnAllocationService_WhenStopAllocation_ThenReturnTrue() { //Given Parkinglot parkinglot = new Parkinglot() { Id = 1 }; Allocation stopAllocation = new Allocation() { MemberPersonId = 1, ParkinglotId = 1, Status = StatusAllocation.Active, Parkinglot = parkinglot }; _parkinglotService.AddAvailableParkingSpots(stopAllocation.Parkinglot).Returns(true); _allocationRepository.GetAllocationById("AllocationID").Returns(stopAllocation); _allocationRepository.UpdateAllocation(stopAllocation).Returns(true); var allocationService = new AllocationService(_allocationRepository, _parkinglotService, _personService); //When var result = allocationService.StopAllocation(1, "AllocationID"); //Then Assert.True(result); }
public void should_pick_failed_when_all_parkinglots_vacancy_rate_is_zero() { var firstParkinglot = new Parkinglot(1); firstParkinglot.Park(new Car()); var secondParkinglot = new Parkinglot(1); secondParkinglot.Park(new Car()); var superParkingBoy = ParkingBoyFactory.CreateSuperParkingBoy(firstParkinglot, secondParkinglot); var parkingToken = superParkingBoy.Park(new Car()); Assert.Null(superParkingBoy.Pick(parkingToken)); }
public async Task GetOneParkinglot_WhenGetOneParkinglot_ThenReturnParkinglotDto() { var server = new TestServer(new WebHostBuilder() .UseStartup <TestStartup>()); using (server) { var client = server .CreateClient(); var context = server.Host.Services.GetService <ParkSharkContext>(); #region fillingInMemoryDatabase Address adress = new Address() { StreetNumber = "1", StreetName = "tt", CityName = "er", PostalCode = "4153", }; context.Persons.Add(new Person( 1, "Person1", "MobilePhone1", "000", adress, "*****@*****.**", new LicensePlate("123", "be") )); context.Set <BuildingType>().Add(new BuildingType() { Id = 1, Name = "Underground" }); context.Divisions.Add(new Division("test", "original", 0, null)); Parkinglot parkinglot = new Parkinglot() { BuildingTypeId = 1, Capacity = 5, AvailablePlaces = 5, ContactPersonId = 1, DivisionId = 1, Name = "Name", Id = 1, PlAddress = new Address() { StreetNumber = "1", StreetName = "tt", CityName = "er", PostalCode = "4153" }, PricePerHour = 10 }; context.Add(parkinglot); await context.SaveChangesAsync(); #endregion fillingInMemoryDatabase var response = await client.GetAsync("api/parkinglots/1"); var responseString = await response.Content.ReadAsStringAsync(); ParkinglotDto parkinglotDto = JsonConvert.DeserializeObject <ParkinglotDto>(responseString); Assert.True(response.IsSuccessStatusCode); Assert.IsType <ParkinglotDto>(parkinglotDto); } }
public bool SaveNewParkinglot(Parkinglot parkinglot) { _context.Add(parkinglot); return(_context.SaveChanges() == 1); }
public void should_park_the_car_in_more_available_stalls_parkinglot() { var littleAvailableStallsParkinglot = new Parkinglot(2); littleAvailableStallsParkinglot.Park(new Car()); var moreAvailableStallsParkinglot = new Parkinglot(4); moreAvailableStallsParkinglot.Park(new Car()); var smartParkingBoy = ParkingBoyFactory.CreateSmartParkingBoy(littleAvailableStallsParkinglot, moreAvailableStallsParkinglot); var car = new Car(); var parkingToken = smartParkingBoy.Park(car); Assert.Same(car, moreAvailableStallsParkinglot.Pick(parkingToken)); }
public void should_pick_the_car_when_only_one_parkninglot() { var parkinglot = new Parkinglot(); var smartParkingBoy = ParkingBoyFactory.CreateSmartParkingBoy(parkinglot); var car = new Car(); var parkingToken = parkinglot.Park(car); var pickedCar = smartParkingBoy.Pick(parkingToken); Assert.Same(car, pickedCar); }
public void Should_pick_when_there_are_two_parkinglots() { var parkinglot = new Parkinglot(); var superParkingBoy = ParkingBoyFactory.CreateSuperParkingBoy(new Parkinglot(), parkinglot); var car = new Car(); var parkingToken = parkinglot.Park(car); var pickedCar = superParkingBoy.Pick(parkingToken); Assert.Same(car, pickedCar); }
public async Task <ActionResult <Parkinglot> > UpdateParkinglots(int parkinglotID, Parkinglot parkinglot) { try { var existingParkinglot = await _parkinglotRepo.GetParkinglotById(parkinglotID); if (existingParkinglot != null) { if (parkinglot.Starship != null) { if (existingParkinglot.Length > parkinglot.Starship.Length) { existingParkinglot.IsOccupied = parkinglot.IsOccupied; existingParkinglot.Starship = parkinglot.Starship; _parkinglotRepo.Update(existingParkinglot); await _parkinglotRepo.Save(); } else { return(BadRequest("Whoops! Your starship was too big for the parkinglot!")); } } else { existingParkinglot.IsOccupied = parkinglot.IsOccupied; existingParkinglot.Starship = null; _parkinglotRepo.Update(existingParkinglot); await _parkinglotRepo.Save(); } } else { return(NotFound($"There is no parkinglot with the ID : {parkinglotID}")); } _logger.LogInformation($"Updating parkinglot with id {existingParkinglot.ParkinglotID} in the database"); return(NoContent()); } catch (Exception e) { return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {e.Message}")); } }