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); } }
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); } }