public static FlightInfoDbContext Create()
        {
            var options = new DbContextOptionsBuilder <FlightInfoDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var context = new FlightInfoDbContext(options);

            context.Database.EnsureCreated();
            context.Airports.AddRange(new[] {
                new Airport {
                    AirportId = 1, Name = "Chris Hadfield Airport", City = "Sarnia", Country = "Canada", IATA = "YZR", ICAO = "CYZR", Longitude = 42.9994010925293M, Altitude = -82.30889892578125M
                },
                new Airport {
                    AirportId = 2, Name = "Leicester Airport", City = "Leicester", Country = "United Kingdom", IATA = string.Empty, ICAO = "EGBG", Longitude = 52.6077995300293M, Altitude = 1.03193998336792M
                },
                new Airport {
                    AirportId = 3, Name = "RAF Wyton", City = "Wyton", Country = "United Kingdom", IATA = "QUY", ICAO = "EGUY", Longitude = 52.3572006226M, Altitude = -0.107832998037M
                },
                new Airport {
                    AirportId = 4, Name = "Lidköping-Hovby Airport", City = "Lidkoping", Country = "Sweden", IATA = "LDK", ICAO = "ESGL", Longitude = 58.4655M, Altitude = 13.1744M
                }
            });
            context.Flights.AddRange(new[] {
                new Flight {
                    DepartureAirportId = 1, DestinationAirportId = 4, FuelConsumption = 10M
                },
            });

            context.SaveChanges();

            return(context);
        }
Пример #2
0
        public FlightInfoDbContext GetDbContext(bool useSqlLite = false)
        {
            var builder = new DbContextOptionsBuilder <FlightInfoDbContext>();

            if (useSqlLite)
            {
                builder.UseSqlite("DataSource=:memory:", x => { });
            }
            else
            {
                builder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            }

            var dbContext = new FlightInfoDbContext(builder.Options);

            if (useSqlLite)
            {
                // SQLite needs to open connection to the DB.
                // Not required for in-memory-database.
                dbContext.Database.OpenConnection();
            }

            dbContext.Database.EnsureCreated();

            return(dbContext);
        }
Пример #3
0
        static void Main(string[] args)
        {
            var builder = new DbContextOptionsBuilder <FlightInfoDbContext>();
            FlightInfoDbContext context = new FlightInfoDbContext(builder.Options);

            FlightInfoInitializer.Initialize(context);
        }
Пример #4
0
        public AirportSearchQueryHandlerTest(QueryTestFixture fixture)
        {
            _context = fixture.Context;
            var myProfile     = new AutoMapperProfile();
            var configuration = new MapperConfiguration(cfg => cfg.AddProfile(myProfile));

            _mapper = new Mapper(configuration);
        }
Пример #5
0
 public AirportSearchQueryHandler(FlightInfoDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public GetFuelConsumptionQueryHandler(FlightInfoDbContext context)
 {
     _context = context;
 }
Пример #7
0
 public static void Initialize(FlightInfoDbContext context)
 {
     var initializer = new FlightInfoInitializer();
 }
Пример #8
0
 public UpdateFlightCommandHandlerTest(QueryTestFixture fixture)
 {
     _context = fixture.Context;
 }
Пример #9
0
 public FlightInfoHandler(FlightInfoDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public UpdateFlightCommandHandler(FlightInfoDbContext context)
 {
     _context = context;
 }
        public static void Destroy(FlightInfoDbContext context)
        {
            context.Database.EnsureDeleted();

            context.Dispose();
        }
 public GetFuelConsumptionQueryHandlerTest(QueryTestFixture fixture)
 {
     _context = fixture.Context;
 }
Пример #13
0
 public QueryTestFixture()
 {
     Context = FlightInfoDbContextFactory.Create();
 }