public async Task Should_update_parkingLot_when_update()
        {
            this.client.DeleteAsync("/parkingLots/clear");
            //given
            var           request1     = JsonConvert.SerializeObject(parkingLotDto1);
            var           request2     = JsonConvert.SerializeObject(parkingLotDto2);
            StringContent requestBody1 = new StringContent(request1, Encoding.UTF8, "application/json");
            StringContent requestBody2 = new StringContent(request2, Encoding.UTF8, "application/json");
            var           response1    = await client.PostAsync("/parkingLots", requestBody1);

            var response2 = await client.PostAsync("/parkingLots", requestBody2);

            var responseBody1 = await response1.Content.ReadAsStringAsync();

            ParkingLotDto addParkingLot1 = JsonConvert.DeserializeObject <ParkingLotDto>(responseBody1);
            var           name           = addParkingLot1.Name;
            var           update         = new UpdateParkingLotDto(50);

            parkingLotDto1.Capacity = update.Capacity;
            var           updateRequest     = JsonConvert.SerializeObject(update);
            StringContent updateRequestBody = new StringContent(updateRequest, Encoding.UTF8, "application/json");
            //when
            var response = await client.PatchAsync($"/parkingLots/{name}", updateRequestBody);

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

            ParkingLotDto respondParkingLot = JsonConvert.DeserializeObject <ParkingLotDto>(responseBody);
            //then
            var parkingLotDto1String    = JsonConvert.SerializeObject(parkingLotDto1);
            var respondParkingLotString = JsonConvert.SerializeObject(respondParkingLot);

            Assert.Equal(parkingLotDto1String, respondParkingLotString);
        }
Exemple #2
0
        public async Task Should_update_parkingLot_capacity_successfully()
        {
            var           client        = GetClient();
            ParkingLotDto parkingLotDto = new ParkingLotDto();

            parkingLotDto.Name     = "LiverpoolLot";
            parkingLotDto.Location = "Liverpool";
            parkingLotDto.Capacity = 100;
            var           httpContent  = JsonConvert.SerializeObject(parkingLotDto);
            StringContent content      = new StringContent(httpContent, Encoding.UTF8, MediaTypeNames.Application.Json);
            var           postResponse = await client.PostAsync("/parkingLots", content);

            UpdateParkingLotDto updateParkingLotDto = new UpdateParkingLotDto();

            updateParkingLotDto.Capacity = 300;
            var           httpContent2 = JsonConvert.SerializeObject(updateParkingLotDto);
            StringContent content2     = new StringContent(httpContent2, Encoding.UTF8, MediaTypeNames.Application.Json);
            await client.PatchAsync(postResponse.Headers.Location, content2);

            var updateParkingLotResponse = await client.GetAsync(postResponse.Headers.Location);

            var body = await updateParkingLotResponse.Content.ReadAsStringAsync();

            var returnUpdateParkingLot = JsonConvert.DeserializeObject <ParkingLotDto>(body);

            Assert.Equal(300, returnUpdateParkingLot.Capacity);
        }
Exemple #3
0
        public async Task Should_not_update_parkingLot_capacity_if_it_is_less_than_zero()
        {
            var           client        = GetClient();
            ParkingLotDto parkingLotDto = new ParkingLotDto();

            parkingLotDto.Name     = "LiverpoolLot";
            parkingLotDto.Location = "Liverpool";
            parkingLotDto.Capacity = 100;
            var           httpContent  = JsonConvert.SerializeObject(parkingLotDto);
            StringContent content      = new StringContent(httpContent, Encoding.UTF8, MediaTypeNames.Application.Json);
            var           postResponse = await client.PostAsync("/parkingLots", content);

            UpdateParkingLotDto updateParkingLotDto = new UpdateParkingLotDto();

            updateParkingLotDto.Capacity = -2;
            var           httpContent2  = JsonConvert.SerializeObject(updateParkingLotDto);
            StringContent content2      = new StringContent(httpContent2, Encoding.UTF8, MediaTypeNames.Application.Json);
            var           patchResponse = await client.PatchAsync(postResponse.Headers.Location, content2);

            var updateParkingLotResponse = await client.GetAsync(postResponse.Headers.Location);

            var body = await updateParkingLotResponse.Content.ReadAsStringAsync();

            var returnUpdateParkingLot = JsonConvert.DeserializeObject <ParkingLotDto>(body);

            Assert.Equal(100, returnUpdateParkingLot.Capacity);
            Assert.Equal(StatusCodes.Status400BadRequest, (int)patchResponse.StatusCode);
        }
        public async Task Should_Update_parkingLot_Capacity_Patch_UpdateParkingLot()
        {
            // given
            ParkingLotDto parkingLotDto = new ParkingLotDto()
            {
                Name     = "NO.1",
                Capacity = 50,
                Location = "BeiJingSouthRailWayStationParkingLot"
            };
            string        httpContent  = JsonConvert.SerializeObject(parkingLotDto);
            StringContent content      = new StringContent(httpContent, Encoding.UTF8, MediaTypeNames.Application.Json);
            var           responsePost = await client.PostAsync("/parkinglots", content);

            // when
            UpdateParkingLotDto updateParkingLotDto = new UpdateParkingLotDto()
            {
                Name     = "NO.1",
                Capacity = 10,
                Location = "BeiJingSouthRailWayStationParkingLot"
            };
            string        httpContentPatch = JsonConvert.SerializeObject(updateParkingLotDto);
            StringContent contentPatch     = new StringContent(httpContentPatch, Encoding.UTF8, MediaTypeNames.Application.Json);
            var           response         = await client.PatchAsync(responsePost.Headers.Location, contentPatch);

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

            var returnParkingLot = JsonConvert.DeserializeObject <ParkingLotDto>(body);

            // then
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(updateParkingLotDto.Capacity, returnParkingLot.Capacity);
            Assert.Equal(1, context.ParkingLot.Count());
        }
        public async Task <ParkingLotDto> UpdateById(int id, UpdateParkingLotDto updateParkingLotDto)
        {
            var foundParkingLotEntity = await this.parkingLotContext.ParkingLot.FirstOrDefaultAsync(parkingLotEntity => parkingLotEntity.Id == id);

            UpdateParkingLotEntity updateParkingLotEntity = new UpdateParkingLotEntity(updateParkingLotDto);

            foundParkingLotEntity.Capacity = updateParkingLotEntity.Capacity;
            await this.parkingLotContext.SaveChangesAsync();

            return(new ParkingLotDto(foundParkingLotEntity));
        }
Exemple #6
0
        public async Task <ActionResult <ParkingLotDto> > UpdateByName(string name, UpdateParkingLotDto updateParkingLotDto)
        {
            var parkingLotDto = await this.parkingLotService.UpdateParkingLot(name, updateParkingLotDto);

            // return CreatedAtAction(nameof(GetByName), new { name = name }, parkingLotDto);
            if (parkingLotDto == null)
            {
                return(NotFound());
            }

            return(Ok(parkingLotDto));
        }
        public async Task <ActionResult <ParkingLotDto> > Update(int id, UpdateParkingLotDto updateParkingLotDto)
        {
            if (updateParkingLotDto.Capacity < 0)
            {
                return(BadRequest(new Dictionary <string, string>()
                {
                    { "message", "Capacity of parkingLot can not be less than zero!" }
                }));
            }

            var parkinglot = await this.parkingLotService.UpdateParkingLot(id, updateParkingLotDto.Capacity);

            return(Ok(parkinglot));
        }
Exemple #8
0
        public async Task <ParkingLotDto> UpdateParkingLot(string name, UpdateParkingLotDto updateParkingLotDto)
        {
            var foundParkingLotEntity = await this.parkingLotDbContext.ParkingLots
                                        .Include(parkingLot => parkingLot.Cars)
                                        .Include(parkingLot => parkingLot.Orders)
                                        .FirstOrDefaultAsync(parkingLotEntity => parkingLotEntity.Name == name);

            if (foundParkingLotEntity == null)
            {
                return(null);
            }

            foundParkingLotEntity.Capacity = updateParkingLotDto.Capacity;
            return(new ParkingLotDto(foundParkingLotEntity));
        }
        public async Task Should_update_parkingLot_Successfully_Via_Service()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotDbContext context           = scopedServices.GetRequiredService <ParkingLotDbContext>();
            ParkingLotService   parkingLotService = new ParkingLotService(context);

            context.ParkingLots.RemoveRange(context.ParkingLots);
            context.SaveChanges();
            var update    = new UpdateParkingLotDto(50);
            var addReturn = await parkingLotService.AddParkingLot(parkingLotDto1);

            var updateReturn = await parkingLotService.UpdateParkingLot(addReturn, update);

            Assert.Equal(50, updateReturn.Capacity);
        }
        public async Task <ActionResult <ParkingLotDto> > UpdateById(int id, UpdateParkingLotDto updateParkingLotDto)
        {
            var parkingLotDto = await this.parkingLotService.UpdateById(id, updateParkingLotDto);

            return(Ok(parkingLotDto));
        }
Exemple #11
0
 public UpdateParkingLotEntity(UpdateParkingLotDto updateParkingLotDto)
 {
     this.Name     = updateParkingLotDto.Name;
     this.Capacity = updateParkingLotDto.Capacity;
     this.Location = updateParkingLotDto.Location;
 }