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());
        }
示例#2
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());
        }
示例#3
0
        public TicketServiceTests()
        {
            var options = new DbContextOptionsBuilder()
                          .UseInMemoryDatabase(nameof(TicketServiceTests))
                          .Options;

            _context = new ParkingLotDbContext(options);
        }
        //Constructor
        public ParkingLotTestCase()
        {
            var context = new ParkingLotDbContext(dbContextOptions);

            _IVehicalParkingDetailsRL = new VehicalParkingDetailsRL(context);
            _IVehicalParkingDetailsBL = new VehicalParkingDetailsBL(_IVehicalParkingDetailsRL);

            _IUserRL = new UserRL(context);
            _IUserBL = new UserBL(_IUserRL);

            parkingController = new ParkingController(_IVehicalParkingDetailsBL, distributedCache);
            userController    = new UserController(_IUserBL, configuration);
        }
        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());
        }
示例#6
0
        static void ShowData(ParkingLotDbContext context)
        {
            context.Owners.Load();
            context.Cars.Load();
            context.ParkingLots.Load();
            context.ParkingSpots.Load();
            context.Visits.Load();

            foreach (var owner in context.Owners)
            {
                Console.WriteLine($"{owner.Name} - {owner.Phone}");

                Console.WriteLine("Cars: ");

                foreach (var car in owner.Cars)
                {
                    Console.WriteLine($"{car.Name} - {car.LicensePlate}");
                }
                Console.WriteLine();
            }

            foreach (var parkingLot in context.ParkingLots)
            {
                Console.WriteLine($"Parking Lot: {parkingLot.Name}");

                Console.WriteLine("ParkingSpots: ");

                foreach (var parkingSpot in parkingLot.ParkingSpots)
                {
                    Console.WriteLine($"Number - {parkingSpot.Number}, Cost - {parkingSpot.Cost}, Is Busy - {parkingSpot.IsBusy}");
                }

                Console.WriteLine();
            }

            foreach (var visit in context.Visits)
            {
                if (visit.Left != null)
                {
                    Console.WriteLine($"Car {visit.CarId} entered parking spot {visit.ParkingSpotId} in parking lot {visit.ParkingSpot.ParkingLotId}" + $"at {visit.Entered} and left at {visit.Left}");
                }
                else
                {
                    Console.WriteLine(@$ "Car {visit.CarId} entered parking spot {visit.ParkingSpotId} in parking lot {visit.ParkingSpot.ParkingLotId} at {visit.Entered} and still there");
                }
            }

            Console.WriteLine();
        }
        public async Task Should_delete_parkigLot_successfully_when_can_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 addReturn = await parkingLotService.AddParkingLot(parkingLotDto1);

            await parkingLotService.DeleteParkingLot(addReturn);

            Assert.Equal(0, context.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_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);
        }
示例#10
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_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 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_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());
        }
示例#14
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_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);
        }
示例#16
0
        private FreeSpotDTO FindFreeSpot(int parkingLevelId, ParkingLotDbContext dbContext)
        {
            var getFreeSpot = dbContext.ParkingSpaces.Where(e => e.IsTaken == false && e.ParkingLevelId == parkingLevelId).FirstOrDefault();

            if (getFreeSpot == null)
            {
                return(new FreeSpotDTO()
                {
                    isFull = true,
                    Message = FAULTY_PARK_MESSAGE
                });
            }

            return(new FreeSpotDTO()
            {
                Id = getFreeSpot.Id,
                SpaceNumber = getFreeSpot.SpaceNumber,
                ParkingLevelId = getFreeSpot.ParkingLevelId,
                Message = string.Format(SUCCESS_PARK_MESSAGE, getFreeSpot.SpaceNumber, getFreeSpot.ParkingLevelId)
            });
        }
        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);
        }
示例#18
0
        static void SeedData(ParkingLotDbContext context)
        {
            context.Database.EnsureDeleted();
            context.Database.Migrate();

            var owner1 = new Owner {
                Name = "Adam", Phone = "0994750925"
            };
            var owner2 = new Owner {
                Name = "Erick", Phone = "0501448285"
            };
            var owner3 = new Owner {
                Name = "Rob", Phone = "0678452522"
            };
            var owner4 = new Owner {
                Name = "Alice", Phone = "0637870244"
            };

            var car1 = new Car {
                Name = "Ferrari", LicensePlate = "XA1232", Owner = owner1
            };
            var car2 = new Car {
                Name = "Audi", LicensePlate = "AA7575", Owner = owner2
            };
            var car3 = new Car {
                Name = "BMW", LicensePlate = "AI8585", Owner = owner3
            };
            var car4 = new Car {
                Name = "Toyota", LicensePlate = "AX7777", Owner = owner4
            };

            context.Cars.AddRange(car1, car2, car3, car4);
            context.SaveChanges();

            var parkingLot1 = new ParkingLot {
                Name = "Greenway Self-Park", Address = "Molochnaya 3"
            };

            var parkingSpot1 = new ParkingSpot {
                Number = "1", IsBusy = false, Cost = 60, ParkingLot = parkingLot1
            };
            var parkingSpot2 = new ParkingSpot {
                Number = "2", IsBusy = false, Cost = 50, ParkingLot = parkingLot1
            };

            var garage1 = new Garage {
                Number = "1", IsBusy = false, Cost = 100, ParkingLot = parkingLot1
            };
            var garage2 = new Garage {
                Number = "2", IsBusy = false, Cost = 100, ParkingLot = parkingLot1
            };

            context.ParkingSpots.AddRange(parkingSpot1, parkingSpot2, garage1, garage2);
            context.SaveChanges();

            var visit1 = new Visit {
                Car = car1, ParkingSpot = parkingSpot1, Entered = new DateTime(2021, 2, 10, 12, 20, 45), Left = new DateTime(2021, 2, 11, 15, 25, 30)
            };
            var visit2 = new Visit {
                Car = car2, ParkingSpot = garage1, Entered = new DateTime(2021, 2, 11), Left = DateTime.Now,
            };
            var visit3 = new Visit {
                Car = car3, ParkingSpot = parkingSpot2, Entered = DateTime.Now, Left = null,
            };
            var visit4 = new Visit {
                Car = car4, ParkingSpot = garage2, Entered = DateTime.Now, Left = null,
            };

            context.Visits.AddRange(visit1, visit2, visit3, visit4);
            context.SaveChanges();
        }
示例#19
0
 public VehicalParkingDetailsRL(ParkingLotDbContext _dataBase)
 {
     dataBase = _dataBase;
 }
 public OrderService(ParkingLotDbContext parkingLotDbContext, ParkingLotService parkingLotService)
 {
     this.parkingLotDbContext = parkingLotDbContext;
     this.parkingLotService   = parkingLotService;
 }
示例#21
0
 public TicketService(ParkingLotDbContext context, ParkingLotConfig config)
 {
     _context = context;
     _config  = config;
 }
示例#22
0
 public ParkingLotRepository(ParkingLotDbContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
示例#23
0
 public ParkingLotService(ParkingLotDbContext dbContext, IMapper mapper) : base(dbContext, mapper)
 {
 }
示例#24
0
 //Constructor
 public UserRL(ParkingLotDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
示例#25
0
 protected BaseService(ParkingLotDbContext dbContext, IMapper mapper)
 {
     DbContext = dbContext;
     Mapper    = mapper;
 }
 public CarService(ParkingLotDbContext parkingLotDbContext)
 {
     this.parkingLotDbContext = parkingLotDbContext;
 }
 public ReportingService(ParkingLotDbContext context)
 {
     _context = context;
 }