public OneToOneQuerySqliteFixture()
        {
            _serviceProvider
                = new ServiceCollection()
                  .AddEntityFramework()
                  .AddSqlite()
                  .ServiceCollection()
                  .AddSingleton(TestSqliteModelSource.GetFactory(OnModelCreating))
                  .AddInstance <ILoggerFactory>(new TestSqlLoggerFactory())
                  .BuildServiceProvider();

            var database = SqliteTestStore.CreateScratch();

            var optionsBuilder = new EntityOptionsBuilder();

            optionsBuilder.UseSqlite(database.Connection.ConnectionString);
            _options = optionsBuilder.Options;

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

                AddTestData(context);
            }
        }
        public void Can_add_extension_with_connection_string()
        {
            var optionsBuilder = new EntityOptionsBuilder();
            optionsBuilder.UseSqlite("Database=Crunchie");

            var extension = optionsBuilder.Options.Extensions.OfType<SqliteOptionsExtension>().Single();

            Assert.Equal("Database=Crunchie", extension.ConnectionString);
            Assert.Null(extension.Connection);
        }
        public void Can_add_extension_with_connection_string_using_generic_options()
        {
            var optionsBuilder = new EntityOptionsBuilder<DbContext>();
            optionsBuilder.UseSqlite("Database=Whisper");

            var extension = optionsBuilder.Options.Extensions.OfType<SqliteOptionsExtension>().Single();

            Assert.Equal("Database=Whisper", extension.ConnectionString);
            Assert.Null(extension.Connection);
        }
示例#4
0
        public override NullSemanticsContext CreateContext(SqliteTestStore testStore)
        {
            var optionsBuilder = new EntityOptionsBuilder();

            optionsBuilder.UseSqlite(testStore.Connection);

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

            context.Database.AsRelational().Connection.UseTransaction(testStore.Transaction);
            return(context);
        }
        public void Can_add_extension_with_connection_string_using_generic_options()
        {
            var optionsBuilder = new EntityOptionsBuilder <DbContext>();

            optionsBuilder.UseSqlite("Database=Whisper");

            var extension = optionsBuilder.Options.Extensions.OfType <SqliteOptionsExtension>().Single();

            Assert.Equal("Database=Whisper", extension.ConnectionString);
            Assert.Null(extension.Connection);
        }
        public void Can_add_extension_with_connection_string()
        {
            var optionsBuilder = new EntityOptionsBuilder();

            optionsBuilder.UseSqlite("Database=Crunchie");

            var extension = optionsBuilder.Options.Extensions.OfType <SqliteOptionsExtension>().Single();

            Assert.Equal("Database=Crunchie", extension.ConnectionString);
            Assert.Null(extension.Connection);
        }
        public void Can_add_extension_with_connection_using_generic_options()
        {
            var optionsBuilder = new EntityOptionsBuilder <DbContext>();
            var connection     = new SqliteConnection();

            optionsBuilder.UseSqlite(connection);

            var extension = optionsBuilder.Options.Extensions.OfType <SqliteOptionsExtension>().Single();

            Assert.Same(connection, extension.Connection);
            Assert.Null(extension.ConnectionString);
        }
            public override SqliteTestStore CreateTestStore()
            {
                return(SqliteTestStore.GetOrCreateShared(DatabaseName, () =>
                {
                    var optionsBuilder = new EntityOptionsBuilder();
                    optionsBuilder.UseSqlite(SqliteTestStore.CreateConnectionString(DatabaseName));

                    using (var context = new StoreGeneratedContext(_serviceProvider, optionsBuilder.Options))
                    {
                        context.Database.EnsureDeleted();
                        context.Database.EnsureCreated();
                    }
                }));
            }
        public InheritanceSqliteFixture()
        {
            _serviceProvider
                = new ServiceCollection()
                  .AddEntityFramework()
                  .AddSqlite()
                  .ServiceCollection()
                  .AddSingleton(TestSqliteModelSource.GetFactory(OnModelCreating))
                  .AddInstance <ILoggerFactory>(new TestSqlLoggerFactory())
                  .BuildServiceProvider();

            var testStore = SqliteTestStore.CreateScratch();

            var optionsBuilder = new EntityOptionsBuilder();

            optionsBuilder.UseSqlite(testStore.Connection);
            _options = optionsBuilder.Options;

            // TODO: Do this via migrations & update pipeline

            testStore.ExecuteNonQuery(@"
                DROP TABLE IF EXISTS Country;
                DROP TABLE IF EXISTS Animal;

                CREATE TABLE Country (
                    Id int NOT NULL PRIMARY KEY,
                    Name nvarchar(100) NOT NULL
                );

                CREATE TABLE Animal (
                    Species nvarchar(100) NOT NULL PRIMARY KEY,
                    Name nvarchar(100) NOT NULL,
                    CountryId int NOT NULL ,
                    IsFlightless bit NOT NULL,
                    EagleId nvarchar(100),
                    'Group' int,
                    FoundOn tinyint,
                    Discriminator nvarchar(255),

                    FOREIGN KEY(countryId) REFERENCES Country(Id),
                    FOREIGN KEY(EagleId) REFERENCES Animal(Species)
                );
            ");

            using (var context = CreateContext())
            {
                SeedData(context);
            }
            TestSqlLoggerFactory.Reset();
        }
        public InheritanceSqliteFixture()
        {
            _serviceProvider
                = new ServiceCollection()
                    .AddEntityFramework()
                    .AddSqlite()
                    .ServiceCollection()
                    .AddSingleton(TestSqliteModelSource.GetFactory(OnModelCreating))
                    .AddInstance<ILoggerFactory>(new TestSqlLoggerFactory())
                    .BuildServiceProvider();

            var testStore = SqliteTestStore.CreateScratch();

            var optionsBuilder = new EntityOptionsBuilder();
            optionsBuilder.UseSqlite(testStore.Connection);
            _options = optionsBuilder.Options;

            // TODO: Do this via migrations & update pipeline

            testStore.ExecuteNonQuery(@"
                DROP TABLE IF EXISTS Country;
                DROP TABLE IF EXISTS Animal;

                CREATE TABLE Country (
                    Id int NOT NULL PRIMARY KEY,
                    Name nvarchar(100) NOT NULL
                );

                CREATE TABLE Animal (
                    Species nvarchar(100) NOT NULL PRIMARY KEY,
                    Name nvarchar(100) NOT NULL,
                    CountryId int NOT NULL ,
                    IsFlightless bit NOT NULL,
                    EagleId nvarchar(100),
                    'Group' int,
                    FoundOn tinyint,
                    Discriminator nvarchar(255),

                    FOREIGN KEY(countryId) REFERENCES Country(Id),
                    FOREIGN KEY(EagleId) REFERENCES Animal(Species)
                );
            ");

            using (var context = CreateContext())
            {
                SeedData(context);
            }
            TestSqlLoggerFactory.Reset();
        }
示例#11
0
        public MappingQuerySqliteFixture()
        {
            _serviceProvider = new ServiceCollection()
                               .AddEntityFramework()
                               .AddSqlite()
                               .ServiceCollection()
                               .AddInstance <ILoggerFactory>(new TestSqlLoggerFactory())
                               .BuildServiceProvider();

            _testDatabase = SqliteNorthwindContext.GetSharedStore();

            var optionsBuilder = new EntityOptionsBuilder().UseModel(CreateModel());

            optionsBuilder.UseSqlite(_testDatabase.Connection.ConnectionString);
            _options = optionsBuilder.Options;
        }
            public NullKeysSqliteFixture()
            {
                _serviceProvider = new ServiceCollection()
                                   .AddEntityFramework()
                                   .AddSqlite()
                                   .ServiceCollection()
                                   .AddSingleton(TestSqliteModelSource.GetFactory(OnModelCreating))
                                   .BuildServiceProvider();

                var optionsBuilder = new EntityOptionsBuilder();

                optionsBuilder.UseSqlite(SqliteTestStore.CreateConnectionString("StringsContext"));
                _options = optionsBuilder.Options;

                EnsureCreated();
            }
示例#13
0
        public override SqliteTestStore CreateTestStore() =>
        SqliteTestStore.GetOrCreateShared(
            DatabaseName,
            () =>
        {
            var optionsBuilder = new EntityOptionsBuilder();
            optionsBuilder.UseSqlite(_connectionString);

            using (var context = new ComplexNavigationsContext(_serviceProvider, optionsBuilder.Options))
            {
                if (context.Database.EnsureCreated())
                {
                    ComplexNavigationsModelInitializer.Seed(context);
                }

                TestSqlLoggerFactory.SqlStatements.Clear();
            }
        });
        public NorthwindQuerySqliteFixture()
        {
            _testStore = SqliteNorthwindContext.GetSharedStore();

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

            var optionsBuilder = new EntityOptionsBuilder();
            optionsBuilder.UseSqlite(_testStore.Connection.ConnectionString);
            _options = optionsBuilder.Options;

            _serviceProvider.GetRequiredService<ILoggerFactory>()
                .MinimumLevel = LogLevel.Debug;
        }
示例#15
0
        public override CrossStoreContext CreateContext(TestStore testStore)
        {
            var inMemoryTestStore = testStore as InMemoryTestStore;

            if (inMemoryTestStore != null)
            {
                var optionsBuilder = new EntityOptionsBuilder();
                optionsBuilder.UseInMemoryStore();

                return(new CrossStoreContext(_serviceProvider, optionsBuilder.Options));
            }

            var sqliteTestStore = testStore as SqliteTestStore;

            if (sqliteTestStore != null)
            {
                var optionsBuilder = new EntityOptionsBuilder();
                optionsBuilder.UseSqlite(sqliteTestStore.Connection);

                var context = new CrossStoreContext(_serviceProvider, optionsBuilder.Options);
                context.Database.EnsureCreated();
                context.Database.AsRelational().Connection.UseTransaction(sqliteTestStore.Transaction);

                return(context);
            }

            var sqlServerTestStore = testStore as SqlServerTestStore;

            if (sqlServerTestStore != null)
            {
                var optionsBuilder = new EntityOptionsBuilder();
                optionsBuilder.UseSqlServer(sqlServerTestStore.Connection);

                var context = new CrossStoreContext(_serviceProvider, optionsBuilder.Options);
                context.Database.EnsureCreated();
                context.Database.AsRelational().Connection.UseTransaction(sqlServerTestStore.Transaction);

                return(context);
            }

            throw new NotImplementedException();
        }
示例#16
0
        public override SqliteTestStore CreateTestStore()
        {
            return(SqliteTestStore.GetOrCreateShared(DatabaseName, () =>
            {
                var optionsBuilder = new EntityOptionsBuilder();
                optionsBuilder.UseSqlite(_connectionString);

                using (var context = new NullSemanticsContext(_serviceProvider, optionsBuilder.Options))
                {
                    // TODO: Delete DB if model changed

                    if (context.Database.EnsureCreated())
                    {
                        NullSemanticsModelInitializer.Seed(context);
                    }

                    TestSqlLoggerFactory.SqlStatements.Clear();
                }
            }));
        }
        public NorthwindQuerySqliteFixture()
        {
            _testStore = SqliteNorthwindContext.GetSharedStore();

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

            var optionsBuilder = new EntityOptionsBuilder();

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

            _serviceProvider.GetRequiredService <ILoggerFactory>()
            .MinimumLevel = LogLevel.Debug;
        }
        public override CrossStoreContext CreateContext(TestStore testStore)
        {
            var inMemoryTestStore = testStore as InMemoryTestStore;
            if (inMemoryTestStore != null)
            {
                var optionsBuilder = new EntityOptionsBuilder();
                optionsBuilder.UseInMemoryStore();

                return new CrossStoreContext(_serviceProvider, optionsBuilder.Options);
            }

            var sqliteTestStore = testStore as SqliteTestStore;
            if (sqliteTestStore != null)
            {
                var optionsBuilder = new EntityOptionsBuilder();
                optionsBuilder.UseSqlite(sqliteTestStore.Connection);

                var context = new CrossStoreContext(_serviceProvider, optionsBuilder.Options);
                context.Database.EnsureCreated();
                context.Database.AsRelational().Connection.UseTransaction(sqliteTestStore.Transaction);

                return context;
            }

            var sqlServerTestStore = testStore as SqlServerTestStore;
            if (sqlServerTestStore != null)
            {
                var optionsBuilder = new EntityOptionsBuilder();
                optionsBuilder.UseSqlServer(sqlServerTestStore.Connection);

                var context = new CrossStoreContext(_serviceProvider, optionsBuilder.Options);
                context.Database.EnsureCreated();
                context.Database.AsRelational().Connection.UseTransaction(sqlServerTestStore.Transaction);

                return context;
            }

            throw new NotImplementedException();
        }
        public OneToOneQuerySqliteFixture()
        {
            _serviceProvider
                = new ServiceCollection()
                    .AddEntityFramework()
                    .AddSqlite()
                    .ServiceCollection()
                    .AddSingleton(TestSqliteModelSource.GetFactory(OnModelCreating))
                    .AddInstance<ILoggerFactory>(new TestSqlLoggerFactory())
                    .BuildServiceProvider();

            var database = SqliteTestStore.CreateScratch();

            var optionsBuilder = new EntityOptionsBuilder();
            optionsBuilder.UseSqlite(database.Connection.ConnectionString);
            _options = optionsBuilder.Options;

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

                AddTestData(context);
            }
        }
        public void Can_add_extension_with_connection_using_generic_options()
        {
            var optionsBuilder = new EntityOptionsBuilder<DbContext>();
            var connection = new SqliteConnection();

            optionsBuilder.UseSqlite(connection);

            var extension = optionsBuilder.Options.Extensions.OfType<SqliteOptionsExtension>().Single();

            Assert.Same(connection, extension.Connection);
            Assert.Null(extension.ConnectionString);
        }