Exemplo n.º 1
0
        public async Task GetFlightsAsync_WhenHasData()
        {
            // Create test data before the call
            var flights = FlightEntity.GenerateTestData();

            _context.Flights.AddRange(flights);
            _context.SaveChanges();

            // Make the call
            DefaultFlightService service = new DefaultFlightService(_context);
            var result = await service.GetFlightsAsync(CancellationToken.None);

            // Validate the result
            Assert.NotNull(result);
            Assert.Equal(flights.Length, Enumerable.Count <Flight>(result));
        }
Exemplo n.º 2
0
 public void Dispose()
 {
     // clean up any objects that were instantiated in the constructor
     _context.Flights.RemoveRange(_context.Flights);
     _context.Bookings.RemoveRange(_context.Bookings);
     _context.SaveChanges();
     _context.Dispose();
     // Call the helper class to Reset AutoMapper since it handles multithreading.
     AutoMapperHelper.Reset();
 }
Exemplo n.º 3
0
        public DefaultAvailabilityServiceTests()
        {
            // Configure an instance of the FlightsDBContext and 'in memory' database.
            // NOTE : Ensure that the name passed to UseInMemoryDatabase is unique to this test class!
            var optionsBuilder = new DbContextOptionsBuilder <FlightsDBContext>();

            optionsBuilder.UseInMemoryDatabase("DefaultAvailabilityServiceTests");
            _context = new FlightsDBContext(optionsBuilder.Options);

            // Create test data before any calls
            var flights = FlightEntity.GenerateTestData();

            _context.Flights.AddRange(flights);
            var bookings = BookingEntity.GenerateTestData();

            _context.Bookings.AddRange(bookings);
            _context.SaveChanges();

            // Call the helper class to initialise AutoMapper since it handles multithreading.
            AutoMapperHelper.Initialize();
        }
Exemplo n.º 4
0
 public void AddBooking(Booking newBooking)
 {
     context.Add <Booking>(newBooking);
     context.SaveChanges();
 }