public DatabaseTestDB() { // gebruik in memory data voor testdata // gebruik van context vh te testen project var options = new DbContextOptionsBuilder <FlightServicesContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; // property dependancy voorbereiden Context = new FlightServicesContext(options); Context.Database.EnsureCreated(); // seed vanuit standaard API project door SaveChanges Uit te voeren bij OnModelCreating //DatabaseInitializer.Initialize(Context); // extra seeding kan voor test omgeving met FakeData }
public FlightsController_Test() { context = Context; flightList = Context.Flights; departureList = Context.Departures; destinationList = Context.Destinations; airplaneList = Context.Airplanes; locationList = Context.Locations; var mapperConfig = new MapperConfiguration(opts => { opts.AddProfile(new FlightProfiles()); }); this.mapper = mapperConfig.CreateMapper(); }
private static void Seed(FlightServicesContext context) { var fakeFlights = new[] { new Flight { Id = Guid.Parse("e5a74ec1-4185-41e4-befc-155c8bbb5d8e"), TimeOfDeparture = DateTime.Parse("24/12/2020 13:40"), TimeOfArrival = DateTime.Parse("24/12/2020 15:00"), FlightStatus = "On time", Departure = { Location = { Id = Guid.NewGuid(), Country = "Sweden", City = "Stockholm", Airport = "ARN" } }, Destination = { Location = { Id = Guid.NewGuid(), Country = "Belgium", City = "Charleroi", Airport = "CRL" } }, Airplane = { Id = Guid.NewGuid(), Name = "CH7652", Type = "Boejing", TotalSeats = 200 } }, }; context.Flights.AddRange(fakeFlights); context.SaveChanges(); }
//ctor dependancy van de applicatie context: public FlightRepo(FlightServicesContext context) : base(context) { this._context = context; }
public DepartureRepo(FlightServicesContext _context) : base(_context) { this._context = _context; }
//ctor dependancy van de applicatie context: public GenericRepo(FlightServicesContext context) { this._context = context; }
public static void Initialize(FlightServicesContext context) { Seed(context); }
public AirplaneRepo(FlightServicesContext _context) : base(_context) { this.context = _context; }
public ReservationRepo(FlightServicesContext _context) : base(_context) { this.context = _context; }
public DestinationRepo(FlightServicesContext _context) : base(_context) { context = _context; }