public async Task IsCarAvailableByDate_ShouldReturnFalse_ForCarWithoutTrip_WithRaservation_ByDate()
        {
            var context                = ApplicationDbContextInMemoryFactory.InitializeContext();
            var carsRepository         = new EfDeletableEntityRepository <Car>(context);
            var tripsRepository        = new EfDeletableEntityRepository <Trip>(context);
            var reservationsRepository = new EfDeletableEntityRepository <Reservation>(context);
            var parkingsRepository     = new EfDeletableEntityRepository <Parking>(context);
            var parkingService         = new ParkingsService(parkingsRepository);
            var carsService            = new CarsService(carsRepository, tripsRepository, reservationsRepository, parkingService);
            var seeder = new DbContextTestsSeeder();
            await seeder.SeedCarsAsync(context);

            var car = await carsRepository.All().FirstOrDefaultAsync();

            var date       = DateTime.UtcNow.AddDays(5);
            var resevation = new Reservation()
            {
                ReservationDate = date, CarId = car.Id
            };
            await reservationsRepository.AddAsync(resevation);

            await reservationsRepository.SaveChangesAsync();

            var reservationFromDbCarId = await reservationsRepository.All().Select(r => r.CarId).FirstOrDefaultAsync();

            var result = await carsService.IsCarAvailableByDate(date, reservationFromDbCarId);

            Assert.False(result, ErrorMessage);
        }
        public async Task GetHotOffersCarsAsync_ShouldReturnFourCars()
        {
            MapperInitializer.InitializeMapper();
            var context       = ApplicationDbContextInMemoryFactory.InitializeContext();
            var carRepository = new EfDeletableEntityRepository <Car>(context);
            var homeService   = new HomeService(carRepository);
            var seeder        = new DbContextTestsSeeder();
            await seeder.SeedCarsAsync(context);

            var result = await homeService.GetHotOffersCarsAsync();

            Assert.True(result.Count() == 4, ErrorMessage);
        }
        public async Task GetCountByParkingAsync_ShouldReturnCorrectResult()
        {
            var context                = ApplicationDbContextInMemoryFactory.InitializeContext();
            var carsRepository         = new EfDeletableEntityRepository <Car>(context);
            var tripsRepository        = new EfDeletableEntityRepository <Trip>(context);
            var reservationsRepository = new EfDeletableEntityRepository <Reservation>(context);
            var parkingsRepository     = new EfDeletableEntityRepository <Parking>(context);
            var parkingService         = new ParkingsService(parkingsRepository);
            var carsService            = new CarsService(carsRepository, tripsRepository, reservationsRepository, parkingService);
            var seeder = new DbContextTestsSeeder();
            await seeder.SeedCarsAsync(context);

            var result = await carsService.GetCountByParkingAsync("Sofia one");

            Assert.True(result == 3, ErrorMessage);
        }
        public async Task GetAllByParkingWithPagingAsync_ShouldReturnAllCarsByTown(int?take, int skip)
        {
            var context                = ApplicationDbContextInMemoryFactory.InitializeContext();
            var carsRepository         = new EfDeletableEntityRepository <Car>(context);
            var tripsRepository        = new EfDeletableEntityRepository <Trip>(context);
            var reservationsRepository = new EfDeletableEntityRepository <Reservation>(context);
            var parkingsRepository     = new EfDeletableEntityRepository <Parking>(context);
            var parkingService         = new ParkingsService(parkingsRepository);
            var carsService            = new CarsService(carsRepository, tripsRepository, reservationsRepository, parkingService);
            var seeder = new DbContextTestsSeeder();
            await seeder.SeedCarsAsync(context);

            var result = await carsService.GetAllByParkingWithPagingAsync <CarsServiceAllModel>("Sofia one", take, skip);

            Assert.True(result.Count() == 3, ErrorMessage);
        }
        public async Task IsCarAvailableByDate_ShouldReturnTrue_ForCarWithoutTripAndRaservation_ByDate()
        {
            var context                = ApplicationDbContextInMemoryFactory.InitializeContext();
            var carsRepository         = new EfDeletableEntityRepository <Car>(context);
            var tripsRepository        = new EfDeletableEntityRepository <Trip>(context);
            var reservationsRepository = new EfDeletableEntityRepository <Reservation>(context);
            var parkingsRepository     = new EfDeletableEntityRepository <Parking>(context);
            var parkingService         = new ParkingsService(parkingsRepository);
            var carsService            = new CarsService(carsRepository, tripsRepository, reservationsRepository, parkingService);
            var seeder = new DbContextTestsSeeder();
            await seeder.SeedCarsAsync(context);

            var car = await carsRepository.All().FirstOrDefaultAsync();

            var result = await carsService.IsCarAvailableByDate(DateTime.UtcNow, car.Id);

            Assert.True(result, ErrorMessage);
        }
        public async Task GetAllAsync_ShouldReturnCorrectResult()
        {
            MapperInitializer.InitializeMapper();
            var context                = ApplicationDbContextInMemoryFactory.InitializeContext();
            var carsRepository         = new EfDeletableEntityRepository <Car>(context);
            var tripsRepository        = new EfDeletableEntityRepository <Trip>(context);
            var reservationsRepository = new EfDeletableEntityRepository <Reservation>(context);
            var parkingsRepository     = new EfDeletableEntityRepository <Parking>(context);
            var parkingService         = new ParkingsService(parkingsRepository);
            var carsService            = new CarsService(carsRepository, tripsRepository, reservationsRepository, parkingService);
            var seeder = new DbContextTestsSeeder();
            await seeder.SeedCarsAsync(context);

            var cars = await carsService.GetAllAsync <CarsServiceAllModel>();

            var count = cars.ToList().Count;

            Assert.True(count == 5, ErrorMessage);
        }
예제 #7
0
        public async Task GetByCarIdAsync_ShouldReturnCorrectResult()
        {
            MapperInitializer.InitializeMapper();
            var context               = ApplicationDbContextInMemoryFactory.InitializeContext();
            var townRepository        = new EfDeletableEntityRepository <Town>(context);
            var parkingSlotRepository = new EfDeletableEntityRepository <ParkingSlot>(context);
            var parkingRepository     = new EfDeletableEntityRepository <Parking>(context);
            var carRepository         = new EfDeletableEntityRepository <Car>(context);
            var parkingsService       = new ParkingsService(parkingRepository, parkingSlotRepository, townRepository, carRepository);
            var seeder = new DbContextTestsSeeder();
            await seeder.SeedParkingsAsync(context);

            await seeder.SeedCarsAsync(context);

            var car = await carRepository.All().FirstOrDefaultAsync();

            var result = await parkingsService.GetByCarIdAsync(car.Id);

            Assert.True(result.Id == car.ParkingId, ErrorMessage);
        }