Beispiel #1
0
        public TestContext(ITestOutputHelper testOutputHelper, ServicesTestsCollectionFixture collectionFixture)
        {
            _xunitOutput       = testOutputHelper;
            _collectionFixture = collectionFixture;

            var serviceProviderBuilder = new ServiceCollection()
#if SQLITE
                                         .AddEntityFrameworkSqlite()
#else
                                         .AddEntityFrameworkNpgsql()
#endif
                                         .AddLogging(c =>
                                                     c.AddDebug()
                                                     .AddProvider(_logCollectorProvider)
                                                     .AddFilter <LogCollectorProvider>(LogCategories.Ef, LogLevel.Information)
                                                     );

            var options = new DbContextOptionsBuilder <DavesAlpacasDbContext>()
#if SQLITE
                          .UseSqlite(_collectionFixture.ConnectionString)
#else
                          .UseNpgsql(_collectionFixture.ConnectionString)
#endif
                          .UseInternalServiceProvider(serviceProviderBuilder.BuildServiceProvider())
                          .EnableSensitiveDataLogging()
                          .Options;

            this.DbContextFactory = new DbContextFactory(options);

            initLoggers();
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DbIntegrationTestBase"/> class.
 /// </summary>
 /// <param name="testOutputHelper">The xUnit output helper.</param>
 /// <param name="collectionFixture">The collection fixture.</param>
 public DbIntegrationTestBase(ITestOutputHelper testOutputHelper, ServicesTestsCollectionFixture collectionFixture)
 {
     this.TestContext = new TestContext(testOutputHelper, collectionFixture);
     prepareTestData();
 }