public async Task Should_update_parkingLot_capacity_when_update_parkingLot_by_name()
        {
            // given
            var           client        = GetClient();
            ParkingLotDto parkingLotDto = GenerateParkingLotDto();
            UpdateParkingLotCapacityDto updateParkingLotCapacityDto = new UpdateParkingLotCapacityDto(10);
            var           httpContent = JsonConvert.SerializeObject(parkingLotDto);
            StringContent content     = new StringContent(httpContent, Encoding.UTF8, MediaTypeNames.Application.Json);
            await client.PostAsync("/ParkingLots", content);

            var response = await client.GetAsync($"/ParkingLots/{parkingLotDto.Name}");

            var responseBody = await response.Content.ReadAsStringAsync();

            var responseParkingLot = JsonConvert.DeserializeObject <ParkingLotDto>(responseBody);

            Assert.Equal(parkingLotDto.Capacity, responseParkingLot.Capacity);
            Assert.NotEqual(updateParkingLotCapacityDto.Capacity, responseParkingLot.Capacity);
            var           httpPatchContent = JsonConvert.SerializeObject(updateParkingLotCapacityDto);
            StringContent patchContent     = new StringContent(httpPatchContent, Encoding.UTF8, MediaTypeNames.Application.Json);

            // when
            var patchResponse = await client.PatchAsync($"/ParkingLots/{parkingLotDto.Name}", patchContent);

            var patchResponseBody = await patchResponse.Content.ReadAsStringAsync();

            var changedParkingLot = JsonConvert.DeserializeObject <ParkingLotDto>(patchResponseBody);

            // then
            Assert.Equal(updateParkingLotCapacityDto.Capacity, changedParkingLot.Capacity);
        }
        public async Task Should_not_update_parkingLot_capacity_when_update_parkingLot_do_not_exist_via_parkingLotService()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotContext context       = scopedServices.GetRequiredService <ParkingLotContext>();
            var parkingLotCapacityUpdateDto = new UpdateParkingLotCapacityDto(10);

            ParkingLotService parkingLotService = new ParkingLotService(context);

            var foundParkingLot = await parkingLotService.UpdateParkingLotCapacity("notExistParkingLotName", parkingLotCapacityUpdateDto);

            Assert.Null(foundParkingLot);
        }
        public async Task Should_update_parkingLot_capacity_when_update_parkingLot_by_name_via_parkingLotService()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotContext context       = scopedServices.GetRequiredService <ParkingLotContext>();
            var parkingLotCapacityUpdateDto = new UpdateParkingLotCapacityDto(10);

            ParkingLotService parkingLotService = new ParkingLotService(context);

            var parkingLotDto  = GenerateParkingLotDto();
            var parkingLotName = await parkingLotService.AddParkingLot(parkingLotDto);

            var foundParkingLot = await parkingLotService.UpdateParkingLotCapacity(parkingLotName, parkingLotCapacityUpdateDto);

            Assert.Equal(parkingLotCapacityUpdateDto.Capacity, foundParkingLot.Capacity);
        }
        public async Task Should_not_update_parkingLot_capacity_when_update_parkingLot_not_exist()
        {
            // given
            var client = GetClient();
            UpdateParkingLotCapacityDto updateParkingLotCapacityDto = new UpdateParkingLotCapacityDto(10);
            var           httpPatchContent = JsonConvert.SerializeObject(updateParkingLotCapacityDto);
            StringContent patchContent     = new StringContent(httpPatchContent, Encoding.UTF8, MediaTypeNames.Application.Json);
            var           parkingLotName   = "ha";

            // when
            var patchResponse = await client.PatchAsync($"/ParkingLots/{parkingLotName}", patchContent);

            var patchResponseBody = await patchResponse.Content.ReadAsStringAsync();

            var changedParkingLot = JsonConvert.DeserializeObject <ParkingLotDto>(patchResponseBody);

            // then
            Assert.Null(changedParkingLot);
        }
Example #5
0
        public async Task <ParkingLotDto> UpdateParkingLotCapacity(string parkingLotName, UpdateParkingLotCapacityDto updateParkingLotCapacityDto)
        {
            var foundParkingLot = await this.parkingLotContext.ParkingLots.FirstOrDefaultAsync(parkingLotEntity => parkingLotEntity.Name == parkingLotName);

            if (foundParkingLot != null)
            {
                foundParkingLot.Capacity = updateParkingLotCapacityDto.Capacity;
                this.parkingLotContext.ParkingLots.Update(foundParkingLot);
                await this.parkingLotContext.SaveChangesAsync();

                return(new ParkingLotDto(foundParkingLot));
            }

            return(null);
        }
Example #6
0
        public async Task <ActionResult <ParkingLotDto> > UpdateParkingLotCapacity(string parkingLotName, UpdateParkingLotCapacityDto updateParkingLotCapacity)
        {
            var changedParkingLotDto = await parkingLotService.UpdateParkingLotCapacity(parkingLotName, updateParkingLotCapacity);

            return(Ok(changedParkingLotDto));
        }