Ejemplo n.º 1
0
        public static IWebHost LoadSampleData(this IWebHost webHost)
        {
            using (var scope = webHost.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                var context  = services.GetRequiredService <FlightsDBContext>();

                context.Flights.AddRange(FlightEntity.GenerateTestData());
                context.Bookings.AddRange(BookingEntity.GenerateTestData());

                context.SaveChanges();
            }

            return(webHost);
        }
        public async Task GetBookingsAsync_WhenHasData()
        {
            // Create test data before the call
            var bookings = BookingEntity.GenerateTestData();

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

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

            // Validate the result
            Assert.NotNull(result);
            Assert.Equal(bookings.Length, Enumerable.Count <Booking>(result));
        }
Ejemplo 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();
        }