コード例 #1
0
        public async Task <ActionResult <Order> > Add(OrderRequest order)
        {
            var lotFound = await parkingLotService.GetParkingLotByName(order.ParkingLotName);

            if (lotFound == null)
            {
                return(BadRequest("no parkingLot match the name"));
            }

            var orderFound = orderService.GetOrders().Result
                             .FirstOrDefault(orderEntity => orderEntity.PlateNumber == order.PlateNumber &&
                                             orderEntity.Status == Status.Open);

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

            var emptyPosition = await parkingLotService.GetParkingLotEmptyPositionByName(order.ParkingLotName);

            if (emptyPosition == 0)
            {
                return(BadRequest("The parking lot is full"));
            }

            var orderReturn = await orderService.AddOrder(order);

            return(CreatedAtAction(nameof(GetByNumber), new { number = orderReturn.OrderNumber }, orderReturn));
        }
        public async Task Story1_AC4_Should_get_parkingLot_by_id()
        {
            // given
            var parkingLot1 = new ParkingLot("Lot1", 10, "location1");
            var parkingLot2 = new ParkingLot("Lot2", 10, "location1");

            // when
            await service.AddParkingLot(parkingLot1);

            var name = await service.AddParkingLot(parkingLot2);

            var lot = service.GetParkingLotByName(name);

            // then
            Assert.Equal(parkingLot2, lot.Result);
        }
コード例 #3
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));
        }
        public async Task Should_get_parkingLot_when_get_parkingLot_by_name_via_parkingLotService()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotContext context = scopedServices.GetRequiredService <ParkingLotContext>();
            var parkingLotDto         = GenerateParkingLotDto();

            ParkingLotService parkingLotService = new ParkingLotService(context);

            var parkingLotName = await parkingLotService.AddParkingLot(parkingLotDto);

            var foundParkingLot = await parkingLotService.GetParkingLotByName(parkingLotName);

            Assert.Equal(1, context.ParkingLots.Count());
            Assert.Equal(parkingLotDto.Name, foundParkingLot.Name);
        }
        public async Task <ActionResult <ParkingLot> > GetByName(string name)
        {
            var lotFound = await service.GetParkingLotByName(name);

            return(lotFound == null ? (ActionResult <ParkingLot>)NotFound("no lot match name") : Ok(lotFound));
        }