protected TestingCaseFixture() { var builder = WebHost.CreateDefaultBuilder() .UseStartup <TStartup>(); // constructs the testing server with the WebHostBuilder configuration // Startup class configures injected mocked services, and middleware (ConfigureServices, etc.) var server = new TestServer(builder); var services = server.Host.Services; // resolve a DbContext instance from the container and begin a transaction on the context. _client = server.CreateClient(); _context = services.GetRequiredService <InfiniteCalendarContext>(); _transaction = _context.Database.BeginTransaction(); }
/** * Applies possible missing migrations from the database. */ private void Migrate() { // testing migrations var dbConnectionString = Configuration.GetConnectionString("DefaultConnection"); var options = new DbContextOptionsBuilder <InfiniteCalendarContext>() .UseSqlServer(dbConnectionString) .Options; var context = new InfiniteCalendarContext(options); // always execute possible missing migrations if (!context.Database.GetPendingMigrations().ToList().Any()) { return; } // context.Database.EnsureCreated(); context.Database.Migrate(); }
public CalendarController(ILogger <HolidayController> logger, InfiniteCalendarContext context, IMapper mapper) { _logger = logger; _context = context; _mapper = mapper; }
public TestingScenarioBuilder(InfiniteCalendarContext context) { _context = context; }