Example #1
0
        public async Task <ParkingLotDto> UpdateCapacityAsync(string name, CapacityDto updatedCapacity)
        {
            var parkingLot = await GetParkingLotEntityByIdAsync(name);

            parkingLot.Capacity = updatedCapacity.Capacity.Value;
            parkingLotDbContext.ParkingLots.Update(parkingLot);
            return(new ParkingLotDto(parkingLot));
        }
        public async Task Should_updated_parkingLot_successfully()
        {
            //given
            var parkingLot        = GenerateParkingLotDtoInstance();
            var dbContext         = GetContext();
            var parkingLotService = new ParkingLotService(dbContext);
            var name = await parkingLotService.AddParkingLotAsync(parkingLot);

            //when
            var updatedCapacity = new CapacityDto()
            {
                Capacity = 2
            };
            var acatualParkingLots = await parkingLotService.UpdateCapacityAsync(name, updatedCapacity);

            //then
            Assert.Equal(updatedCapacity.Capacity.Value, acatualParkingLots.Capacity.Value);

            var actualParkingLot = await dbContext.ParkingLots.FirstOrDefaultAsync(lot => lot.Name == name);

            Assert.Equal(updatedCapacity.Capacity.Value, actualParkingLot.Capacity);
        }
Example #3
0
        public async Task <ActionResult <ParkingLotDto> > UpdateCapacity(string name, CapacityDto updatedCapacity)
        {
            if (updatedCapacity == null || updatedCapacity.Capacity == null)
            {
                return(BadRequest("Capacity cannot be null."));
            }

            if (!await parkingLotService.IsParkingLotExistedAsync(name))
            {
                return(NotFound("The parking lot is not existed."));
            }

            var updatedParkingLot = await parkingLotService.UpdateCapacityAsync(name, updatedCapacity);

            return(Ok(updatedParkingLot));
        }