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

            _testStore = SqliteTestStore.CreateScratch();

            var optionsBuilder = new DbContextOptionsBuilder();

            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)
                );

                CREATE TABLE Plant (
                    Genus int NOT NULL,
                    Species nvarchar(100) NOT NULL PRIMARY KEY,
                    Name nvarchar(100) NOT NULL,
                    CountryId int,
                    HasThorns bit,

                    FOREIGN KEY(countryId) REFERENCES Country(Id)
                );
            ");

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

            _testStore = SqliteTestStore.CreateScratch();

            var optionsBuilder = new DbContextOptionsBuilder();

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

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

                AddTestData(context);
            }
        }
        public void Exists_returns_true_when_database_exists()
        {
            using (var testStore = SqliteTestStore.CreateScratch())
            {
                var creator = GetDatabaseCreator(testStore.ConnectionString);

                Assert.True(creator.Exists());
            }
        }
        public AutoincrementTest()
        {
            _testStore = SqliteTestStore.CreateScratch();

            var provider = new ServiceCollection()
                           .AddEntityFrameworkSqlite()
                           .BuildServiceProvider();

            _options = new DbContextOptionsBuilder()
                       .UseInternalServiceProvider(provider)
                       .UseSqlite(_testStore.Connection)
                       .Options;
        }
        public AutoincrementTest()
        {
            _testStore = SqliteTestStore.CreateScratch();

            var builder = new DbContextOptionsBuilder();

            builder.UseSqlite(_testStore.Connection);
            _options  = builder.Options;
            _provider = new ServiceCollection()
                        .AddEntityFramework()
                        .AddSqlite()
                        .AddDbContext <BatContext>()
                        .ServiceCollection()
                        .BuildServiceProvider();
        }
        public BuiltInDataTypesSqliteFixture()
        {
            _testStore = SqliteTestStore.CreateScratch();

            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkSqlite()
                                  .AddSingleton(TestModelSource.GetFactory(OnModelCreating))
                                  .BuildServiceProvider();

            _options = new DbContextOptionsBuilder()
                       .UseSqlite(_testStore.Connection)
                       .UseInternalServiceProvider(serviceProvider)
                       .Options;

            using (var context = new DbContext(_options))
            {
                context.Database.EnsureClean();
            }
        }
Esempio n. 7
0
        public OneToOneQuerySqliteFixture()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkSqlite()
                                  .AddSingleton(TestModelSource.GetFactory(OnModelCreating))
                                  .AddSingleton <ILoggerFactory>(TestSqlLoggerFactory)
                                  .BuildServiceProvider();

            _testStore = SqliteTestStore.CreateScratch();

            _options = new DbContextOptionsBuilder()
                       .UseSqlite(_testStore.ConnectionString)
                       .UseInternalServiceProvider(serviceProvider)
                       .Options;

            using (var context = new DbContext(_options))
            {
                context.Database.EnsureClean();

                AddTestData(context);
            }
        }
Esempio n. 8
0
 public SqliteForeignKeyTest()
 {
     _testStore = SqliteTestStore.CreateScratch();
 }