コード例 #1
0
        public async Task Should_delete_specific_parkingLot_when_give_name_Test()
        {
            var scope                       = Factory.Services.CreateScope();
            var scopeServices               = scope.ServiceProvider;
            ParkingLotDbContext context     = scopeServices.GetRequiredService <ParkingLotDbContext>();
            ParkingLotDto       parkingLot1 = new ParkingLotDto();

            parkingLot1.Name     = "345";
            parkingLot1.Capacity = 0;
            parkingLot1.Location = "southRoad";
            ParkingLotDto parkingLot2 = new ParkingLotDto();

            parkingLot2.Name     = "234";
            parkingLot2.Capacity = 0;
            parkingLot2.Location = "southRoad";

            ParkingLotService parkingLotService = new ParkingLotService(context);
            var name1 = await parkingLotService.AddParkingLot(parkingLot1);

            var name2 = await parkingLotService.AddParkingLot(parkingLot2);

            await parkingLotService.DeleteParkingLot(parkingLot1.Name);

            Assert.Equal(1, context.ParkingLots.Count());
        }
        public async Task Should_Get_Parking_Lots_By_Name()
        {
            // given
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotContext context = scopedServices.GetRequiredService <ParkingLotContext>();

            // when
            int           startindex     = 1;
            int           endindex       = 2;
            ParkingLotDto parkingLotDto1 = new ParkingLotDto()
            {
                Name     = "parkinglot1",
                Capacity = 4,
                Location = "Beijing",
            };
            ParkingLotDto parkingLotDto2 = new ParkingLotDto()
            {
                Name     = "parkinglot2",
                Capacity = 3,
                Location = "Beijing",
            };
            ParkingLotService parkingLotService = new ParkingLotService(context);
            await parkingLotService.AddParkingLot(parkingLotDto1);

            await parkingLotService.AddParkingLot(parkingLotDto2);

            var parkingLot = await parkingLotService.GetByName("parkinglot2");

            Assert.Equal(parkingLotDto2, parkingLot);
        }
コード例 #3
0
        public async Task Story2_AC1_3_Should_add_order_correctly()
        {
            // given
            var parkingLot = new ParkingLot("Lot1", 10, "location1");
            var order      = new OrderRequest("Lot1", "JA00001");

            // when
            await parkingLotService.AddParkingLot(parkingLot);

            var orderEntity = await orderService.AddOrder(order);

            // then
            Assert.Equal(orderEntity, context.Orders.FirstOrDefaultAsync().Result);
            Assert.Equal(Status.Open, context.Orders.FirstOrDefaultAsync().Result.Status);
        }
        public async Task Should_not_create_order_when_parkingLot_is_full_via_service()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>();

            context.ParkingLots.RemoveRange(context.ParkingLots);
            context.Orders.RemoveRange(context.Orders);
            context.Cars.RemoveRange(context.Cars);
            context.SaveChanges();
            ParkingLotService parkingLotService = new ParkingLotService(context);
            OrderService      orderService      = new OrderService(context);
            CarService        carService        = new CarService(context);

            var name = await parkingLotService.AddParkingLot(parkingLotDto1);

            var orderNumber1 = await orderService.AddOrder(orderDto1);

            await carService.AddCar(name, carDto1);

            Assert.Equal(1, context.Orders.Count());
            var orderNumber2 = await orderService.AddOrder(orderDto2);

            Assert.Equal(1, context.Orders.Count());
        }
        public async Task Should_get_x_parkingLots_for_page_y_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 addReturn1 = await parkingLotService.AddParkingLot(parkingLotDto1);

            var addReturn2 = await parkingLotService.AddParkingLot(parkingLotDto2);

            var getAllReturn = await parkingLotService.GetByPageSizeAndIndex(1, 1);

            Assert.Equal(1, getAllReturn.Count);
        }
        public async Task Story1_AC1_Should_add_parkingLot()
        {
            // given
            var parkingLot = new ParkingLot("Lot1", 10, "location1");

            // when
            await service.AddParkingLot(parkingLot);

            // then
            Assert.Equal(parkingLot, new ParkingLot(context.ParkingLots.FirstAsync().Result));
        }
        public async Task Should_not_add_parkingLot_when_parkingLot_name_already_exist_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 context.ParkingLots.FirstOrDefaultAsync(parkingLotEntity => parkingLotEntity.Name == parkingLotName);

            Assert.Equal(1, context.ParkingLots.Count());

            var parkingLotNameTwo = await parkingLotService.AddParkingLot(parkingLotDto);

            Assert.Null(parkingLotNameTwo);
        }
        public async Task Should_not_delete_parkingLot_when_can_not_find_by_name_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 addReturn1 = await parkingLotService.AddParkingLot(parkingLotDto1);

            var addReturn2 = await parkingLotService.AddParkingLot(parkingLotDto2);

            await parkingLotService.DeleteParkingLot(addReturn1);

            await parkingLotService.DeleteParkingLot(addReturn1);

            Assert.Equal(1, context.ParkingLots.Count());
        }
        public async Task <ActionResult <ParkingLotDto> > AddParkingLot(ParkingLotDto parkingLotDto)
        {
            int?id = await parkingLotService.AddParkingLot(parkingLotDto);

            if (id != null)
            {
                return(CreatedAtAction(nameof(GetById), new { id = id }, parkingLotDto));
            }

            return(BadRequest());
        }
        public async Task Should_add_parkingLot_successfully_via_service()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>();

            context.ParkingLots.RemoveRange(context.ParkingLots);
            context.SaveChanges();
            ParkingLotService parkingLotService = new ParkingLotService(context);
            await parkingLotService.AddParkingLot(parkingLotDto1);

            Assert.Equal(1, context.ParkingLots.Count());
        }
        public async Task Should_create_parkingLot_successfully_via_parkingLot_service()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;
            ParkingLotContext parkingLotContext = scopedServices.GetRequiredService <ParkingLotContext>();
            ParkingLotDto     parkingLotDto     = new ParkingLotDto();

            parkingLotDto.Name     = "LiverpoolLot";
            parkingLotDto.Location = "Liverpool";
            parkingLotDto.Capacity = 100;
            ParkingLotService parkingLotService = new ParkingLotService(parkingLotContext);
            await parkingLotService.AddParkingLot(parkingLotDto);

            Assert.Equal(1, parkingLotContext.ParkingLots.Count());
        }
        public async Task Should_not_add_parkingLot_when_name_already_exist_via_service()
        {
            var scope                   = Factory.Services.CreateScope();
            var scopedServices          = scope.ServiceProvider;
            ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>();

            context.ParkingLots.RemoveRange(context.ParkingLots);
            context.SaveChanges();
            ParkingLotService parkingLotService = new ParkingLotService(context);
            await parkingLotService.DeleteAllParkingLot();

            await parkingLotService.AddParkingLot(parkingLotDto1);

            //await parkingLotService.AddParkingLot(parkingLotDto1);
            Assert.Equal(1, context.ParkingLots.Count());
        }
        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_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 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);
        }
コード例 #16
0
        public async Task Should_get_parkingLots_when_give_pageIndex_Test()
        {
            var scope                       = Factory.Services.CreateScope();
            var scopeServices               = scope.ServiceProvider;
            ParkingLotDbContext context     = scopeServices.GetRequiredService <ParkingLotDbContext>();
            ParkingLotDto       parkingLot1 = new ParkingLotDto();

            parkingLot1.Name     = "345";
            parkingLot1.Capacity = 0;
            parkingLot1.Location = "southRoad";

            ParkingLotService parkingLotService = new ParkingLotService(context);
            var name1 = await parkingLotService.AddParkingLot(parkingLot1);

            var actualParkingLots = await parkingLotService.GetParkingLotByPageIndex(2);

            Assert.Equal(new List <ParkingLotDto>(), actualParkingLots);
        }
        public async Task Should_add_car_successfully_when_position_available_via_service()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>();

            context.ParkingLots.RemoveRange(context.ParkingLots);
            context.Orders.RemoveRange(context.Orders);
            context.Cars.RemoveRange(context.Cars);
            context.SaveChanges();
            ParkingLotService parkingLotService = new ParkingLotService(context);
            CarService        carService        = new CarService(context);
            var addParkingLotReturn             = await parkingLotService.AddParkingLot(parkingLotDto1);

            await carService.AddCar(addParkingLotReturn, carDto1);

            Assert.Equal(1, context.Cars.Count());
        }
コード例 #18
0
        public async Task Should_create_a_new_parkingLot_when_give_name_capacity_and_location_Test()
        {
            var scope                        = Factory.Services.CreateScope();
            var scopeServices                = scope.ServiceProvider;
            ParkingLotDbContext context      = scopeServices.GetRequiredService <ParkingLotDbContext>();
            ParkingLotDto       paringLotDto = new ParkingLotDto();

            paringLotDto.Name     = "123";
            paringLotDto.Capacity = 0;
            paringLotDto.Location = "southRoad";

            ParkingLotService parkingLotService = new ParkingLotService(context);
            await parkingLotService.AddParkingLot(paringLotDto);

            Assert.Equal(1, context.ParkingLots.Count());
            var createdParkingLot = await context.ParkingLots.FirstOrDefaultAsync(item => item.Name == paringLotDto.Name);

            Assert.Equal(paringLotDto, new ParkingLotDto(createdParkingLot));
        }
        public async Task Should_get_parkingLot_Successfully_by_name_Via_Service()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>();

            context.ParkingLots.RemoveRange(context.ParkingLots);
            context.SaveChanges();
            ParkingLotService parkingLotService = new ParkingLotService(context);
            await parkingLotService.AddParkingLot(parkingLotDto1);

            var getByName = await parkingLotService.GetByName("IBM");

            var parkingLotDto1String = JsonConvert.SerializeObject(parkingLotDto1);
            var getByNameString      = JsonConvert.SerializeObject(getByName);

            Assert.Equal(parkingLotDto1String, getByNameString);
        }
        public async Task Should_update_order_status_to_close_when_car_left_via_service()
        {
            var scope          = Factory.Services.CreateScope();
            var scopedServices = scope.ServiceProvider;

            ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>();

            context.Orders.RemoveRange(context.Orders);
            context.SaveChanges();
            ParkingLotService parkingLotService = new ParkingLotService(context);
            OrderService      orderService      = new OrderService(context);

            parkingLotService.AddParkingLot(parkingLotDto1);
            UpdateOrderDto updateOrderDto = new UpdateOrderDto("closed");
            var            addOrderNumber = await orderService.AddOrder(orderDto1);

            var orderDto = await orderService.UpdateOrder(addOrderNumber, updateOrderDto);

            Assert.Equal("closed", orderDto.OrderStatus);
        }
コード例 #21
0
        public async Task <ActionResult <ParkingLot> > Add(ParkingLot parkingLot)
        {
            if (parkingLot.Location == null || parkingLot.Name == null)
            {
                return(BadRequest("location or name can not be empty"));
            }

            if (parkingLot.Capacity < 0)
            {
                return(BadRequest("capacity can not be negative"));
            }

            var lotFound = service.GetAllParkingLots().Result.FirstOrDefault(lot => lot.Name == parkingLot.Name);

            if (lotFound != null)
            {
                return(BadRequest("lot with same name exists"));
            }

            var name = await service.AddParkingLot(parkingLot);

            return(CreatedAtAction(nameof(GetByName), new { name = name }, parkingLot));
        }
        public async Task Should_Add_New_Factory_Success_Via_Service()
        {
            // Given
            ParkingLotDto parkingLotDto = new ParkingLotDto();

            parkingLotDto.Name     = "ParkingLot_A";
            parkingLotDto.Capacity = 30;
            parkingLotDto.Location = "Beijing";

            ParkingLotDbContext context = GetContext();
            ParkingLotService   service = new ParkingLotService(context);

            // When
            await service.AddParkingLot(parkingLotDto);

            // Then
            Assert.Equal(1, context.ParkingLots.ToList().Count);

            var firstParkingLot = await context.ParkingLots.FirstOrDefaultAsync();

            Assert.Equal(parkingLotDto.Name, firstParkingLot.Name);
            Assert.Equal(parkingLotDto.Capacity, firstParkingLot.Capacity);
            Assert.Equal(parkingLotDto.Location, firstParkingLot.Location);
        }
        public async Task <ActionResult <ParkingLotDto> > Add(ParkingLotDto parkingLotDto)
        {
            var name = await parkingLotService.AddParkingLot(parkingLotDto);

            return(CreatedAtAction(nameof(GetByName), new { name }, parkingLotDto));
        }