Ejemplo n.º 1
0
            public override DbContext CreateContext(NpgsqlTestStore testStore)
            {
                var optionsBuilder = new DbContextOptionsBuilder();

                optionsBuilder.UseNpgsql(testStore.Connection);

                var context = new StoreGeneratedContext(_serviceProvider, optionsBuilder.Options);

                context.Database.UseTransaction(testStore.Transaction);

                return(context);
            }
Ejemplo n.º 2
0
            public override NpgsqlTestStore CreateTestStore()
            {
                return(NpgsqlTestStore.GetOrCreateShared(DatabaseName, () =>
                {
                    var optionsBuilder = new DbContextOptionsBuilder();
                    optionsBuilder.UseNpgsql(NpgsqlTestStore.CreateConnectionString(DatabaseName));

                    using (var context = new StoreGeneratedContext(_serviceProvider, optionsBuilder.Options))
                    {
                        context.Database.EnsureDeleted();
                        context.Database.EnsureCreated();
                    }
                }));
            }
Ejemplo n.º 3
0
        public NorthwindQueryNpgsqlFixture()
        {
            _testStore = NpgsqlNorthwindContext.GetSharedStore();

            _serviceProvider = new ServiceCollection()
                               .AddEntityFramework()
                               .AddNpgsql()
                               .ServiceCollection()
                               .AddSingleton(TestNpgsqlModelSource.GetFactory(OnModelCreating))
                               .AddInstance <ILoggerFactory>(new TestSqlLoggerFactory())
                               .BuildServiceProvider();

            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.UseNpgsql(_testStore.Connection.ConnectionString);
            _options = optionsBuilder.Options;

            _serviceProvider.GetRequiredService <ILoggerFactory>()
            .MinimumLevel = LogLevel.Debug;
        }
        public BuiltInDataTypesNpgsqlFixture()
        {
            _testStore = NpgsqlTestStore.CreateScratch();

            _serviceProvider = new ServiceCollection()
                               .AddEntityFramework()
                               .AddNpgsql()
                               .ServiceCollection()
                               .AddSingleton(TestNpgsqlModelSource.GetFactory(OnModelCreating))
                               .BuildServiceProvider();

            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.UseNpgsql(_testStore.Connection);

            _options = optionsBuilder.Options;

            using (var context = new DbContext(_serviceProvider, _options))
            {
                context.Database.EnsureCreated();
            }
        }