示例#1
0
        public async Task <ActionResult <ParkingOrderDto> > AddParkingOrder(ParkingOrderDto parkingOrderDto)
        {
            var orderFound = parkingOrderService.GetAllParkingOrders().Result
                             .FirstOrDefault(parkingOrderEntity => parkingOrderEntity.PlateNumber == parkingOrderDto.PlateNumber);

            if (orderFound != null)
            {
                return(BadRequest("car in the lot"));
            }

            var parkingLot = await parkingLotService.GetParkingLotByName(parkingOrderDto.ParkingLotName);

            var capacity = parkingLot.Capacity;
            var occupies = await parkingLotService.GetParkingLotCapacityByName(parkingOrderDto.ParkingLotName);

            if (occupies == -1)
            {
                return(BadRequest("parking lot not found"));
            }

            if (capacity == occupies)
            {
                return(BadRequest("parking lot is full"));
            }

            var parkingOrderNumber = await parkingOrderService.AddParkingOrder(parkingOrderDto);

            return(CreatedAtAction(nameof(GetParkingOrderByOrderNumber), new { orderNumber = parkingOrderNumber }, parkingOrderNumber));
        }
示例#2
0
        public async Task Should_add_parkingOrder_when_add_parkingOrder_via_parkingOrderService()
        {
            // given
            var scope                 = Factory.Services.CreateScope();
            var scopedServices        = scope.ServiceProvider;
            ParkingLotContext context = scopedServices.GetRequiredService <ParkingLotContext>();
            var parkingOrderDto       = GenerateParkingOrderDto();
            ParkingOrderService parkingOrderService = new ParkingOrderService(context);

            // when
            var parkingOrderNumber = await parkingOrderService.AddParkingOrder(parkingOrderDto);

            var foundParkingOrder = await context.ParkingOrders.FirstOrDefaultAsync(parkingOrderEntity => parkingOrderEntity.OrderNumber == parkingOrderNumber);

            // then
            Assert.Equal(parkingOrderDto.OrderNumber, foundParkingOrder.OrderNumber);
        }
示例#3
0
        public async Task Should_get_correct_parkingOrder_when_get_parkingOrder_via_parkingOrderService()
        {
            // given
            var scope                               = Factory.Services.CreateScope();
            var scopedServices                      = scope.ServiceProvider;
            ParkingLotContext   context             = scopedServices.GetRequiredService <ParkingLotContext>();
            ParkingOrderService parkingOrderService = new ParkingOrderService(context);
            var parkingOrderDtoList                 = GenerateParkingOrderDtoList();

            foreach (var parkingOrderDto in parkingOrderDtoList)
            {
                await parkingOrderService.AddParkingOrder(parkingOrderDto);
            }

            // when
            var parkingOrder = await parkingOrderService.GetParkingOrderByOrderNumber(parkingOrderDtoList[0].OrderNumber);

            // then
            Assert.Equal(parkingOrderDtoList[0], parkingOrder);
        }
示例#4
0
        public async Task Should_get_all_parkingOrders_when_get_parkingOrders_via_parkingOrderService()
        {
            // given
            var scope                               = Factory.Services.CreateScope();
            var scopedServices                      = scope.ServiceProvider;
            ParkingLotContext   context             = scopedServices.GetRequiredService <ParkingLotContext>();
            ParkingOrderService parkingOrderService = new ParkingOrderService(context);
            var parkingOrderDtoList                 = GenerateParkingOrderDtoList();

            foreach (var parkingOrderDto in parkingOrderDtoList)
            {
                await parkingOrderService.AddParkingOrder(parkingOrderDto);
            }

            // when
            var allParkingOrders = await parkingOrderService.GetAllParkingOrders();

            // then
            Assert.Equal(5, allParkingOrders.Count());
        }
示例#5
0
        public async Task Should_update_parkingOrder_when_update_parkingOrder_via_parkingOrderService()
        {
            // given
            var scope                               = Factory.Services.CreateScope();
            var scopedServices                      = scope.ServiceProvider;
            ParkingLotContext   context             = scopedServices.GetRequiredService <ParkingLotContext>();
            ParkingOrderService parkingOrderService = new ParkingOrderService(context);
            var parkingOrderDtoList                 = GenerateParkingOrderDtoList();

            foreach (var parkingOrderDto in parkingOrderDtoList)
            {
                await parkingOrderService.AddParkingOrder(parkingOrderDto);
            }

            UpdateParkingOrderDto updateParkingOrderDto = new UpdateParkingOrderDto("closed");

            // when
            var changedParkingOrder = await parkingOrderService.UpdateParkingOrder(parkingOrderDtoList[0].OrderNumber, updateParkingOrderDto);

            // then
            Assert.Equal(updateParkingOrderDto.CloseTime, changedParkingOrder.CloseTime);
            Assert.Equal(updateParkingOrderDto.OrderStatus, changedParkingOrder.OrderStatus);
        }