Esempio n. 1
0
        public void Should_Add_Airport()
        {
            // Given
            var options = new DbContextOptionsBuilder <CustomContext>()
                          .UseInMemoryDatabase("TestDB")
                          .EnableSensitiveDataLogging()
                          .Options;

            // When
            using (var context = new CustomContext(options))
            {
                var repository = new AirportsRepository(context);
                var uow        = new UnitOfWork(context);

                repository.Add(_airport);
                uow.Save();
            }

            // Then
            using (var context = new CustomContext(options))
            {
                var repository = new AirportsRepository(context);

                var result = repository.GetAll().Single(x => x.IATA == _airport.IATA);

                Assert.NotNull(result);
            }
        }
Esempio n. 2
0
 public Task Execute()
 {
     return(AirportsHttpService.Get()
            .ContinueWith(x => AirportsRepository.Put(
                              MapperFactory.ResolveMapper <AirportsJsonGetResponse, AirportsRepositoryItem>()
                              .Map(x.Result))));
 }
Esempio n. 3
0
 public UnitOfWork(TransaviaDbContext ctx, IEventDispatcher eventDispatcher)
 {
     _ctx             = ctx;
     _eventDispatcher = eventDispatcher;
     AirportTypes     = new AirportTypesRepository(ctx, eventDispatcher);
     AirportStatuses  = new AirportStatusesRepository(ctx, eventDispatcher);
     AirportSizes     = new AirportSizesRepository(ctx, eventDispatcher);
     Countries        = new CountriesRepository(ctx, eventDispatcher);
     Continents       = new ContinentsRepository(ctx, eventDispatcher);
     Airports         = new AirportsRepository(ctx, eventDispatcher);
 }
        public void Should_Add_Flight()
        {
            // Given
            var options = new DbContextOptionsBuilder <CustomContext>()
                          .UseInMemoryDatabase("TestDB")
                          .UseLazyLoadingProxies()
                          .EnableSensitiveDataLogging()
                          .Options;

            var flightId = 100;

            // When
            using (var context = new CustomContext(options))
            {
                context.Database.EnsureCreated();

                var uow                = new UnitOfWork(context);
                var repository         = new FlightsRepository(context);
                var airportRepository  = new AirportsRepository(context);
                var aircraftRepository = new AircraftRepository(context);

                airportRepository.Add(_departureAirport);
                airportRepository.Add(_destinationAirport);
                aircraftRepository.Add(_aircraft);
                uow.Save();

                var flight = new Flight(_departureAirport, _destinationAirport, _aircraft)
                {
                    Id = 100
                };

                repository.Add(flight);
                uow.Save();
            }

            // Then
            using (var context = new CustomContext(options))
            {
                var repository = new FlightsRepository(context);
                var result     = repository.GetAll().Single(x => x.Id == flightId);

                Assert.NotNull(result);
                Assert.Equal(_departureAirport.Id, result.DepartureAirport.Id);
            }
        }
Esempio n. 5
0
        public async Task <AirportServiceResponse> GetAirports(bool bypassCache = false)
        {
            AirportServiceResponse response;

            if (bypassCache)
            {
                var httpResponseObject = await AirportsHttpService.Get();

                response = MapperFactory.ResolveMapper <AirportsJsonGetResponse, AirportServiceResponse>()
                           .Map(httpResponseObject);
                response.FromCache = false;
                return(response);
            }

            var cachedAirports = AirportsRepository.Get();

            response = MapperFactory.ResolveMapper <IEnumerable <IAirportsRepositoryItem>, AirportServiceResponse>()
                       .Map(cachedAirports);
            response.FromCache = true;
            return(response);
        }
        public void ItReturnsNotNullModel()
        {
            // Arrange
            AviTradeContext dbContext = new AviTradeContext();
            IItemsRepository itemsRepository = new ItemsRepository(dbContext);
            IAirportsRepository airportsRepository = new AirportsRepository(dbContext);
            IAircraftsRepository aircraftsRepository = new AircraftsRepository(dbContext);
            IContractsRepository contractsRepository = new ContractsRepository(dbContext);
            ITradersRepository tradersRepository = new TradersRepository(dbContext);
            IPeriodsRepository periodsRepository = new PeriodsRepository(dbContext);
            IInvoicesRepository invoicesRepository = new InvoicesRepository(dbContext, periodsRepository);
            ICurrenciesRepository currenciesRepository = new CurrenciesRepository(dbContext);
            IOrdersRepository ordersRepository = new OrdersRepository(dbContext, contractsRepository, airportsRepository, aircraftsRepository, itemsRepository, currenciesRepository, invoicesRepository);
            DataServiceController controller = null; // new DataServiceController(contractsRepository, tradersRepository, ordersRepository, itemsRepository, airportsRepository, aircraftsRepository);

            // Act
            AjaxOrdersViewModel model = controller.BuildAjaxOrdersViewModel(1, 0, "1,2,3,4", DateTime.Now.AddDays(30),
                                                                            true, 0, 20);

            // Assert
            Assert.IsNotNull(model);
        }
Esempio n. 7
0
 public AirportsService()
 {
     airportsRepository = new AirportsRepository();
 }
 private static void SetupRepositories(AviTradeContext ctx)
 {
     _contractsRepository = new ContractsRepository(ctx);
     _airportsRepository = new AirportsRepository(ctx);
     _aircraftsRepository = new AircraftsRepository(ctx);
     _itemsRepository = new ItemsRepository(ctx);
     _currenciesRepository = new CurrenciesRepository(ctx);
     _periodsRepository = new PeriodsRepository(ctx);
     _invoicesRepository = new InvoicesRepository(ctx, _periodsRepository);
     _ordersRepository = new OrdersRepository(ctx, _contractsRepository, _airportsRepository, _aircraftsRepository, _itemsRepository, _currenciesRepository, _invoicesRepository);
     _tradersRepository = new TradersRepository(ctx);
 }