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

            var 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))
                  .AddInstance <ILoggerFactory>(new TestSqlLoggerFactory())
                  .BuildServiceProvider();

            var database = SqliteTestStore.CreateScratch();

            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.UseSqlite(database.Connection.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.Connection.ConnectionString);

                Assert.True(creator.Exists());
            }
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
        public BuiltInDataTypesSqliteFixture()
        {
            _testStore = SqliteTestStore.CreateScratch();

            _serviceProvider = new ServiceCollection()
                               .AddEntityFramework()
                               .AddSqlite()
                               .ServiceCollection()
                               .AddSingleton(TestSqliteModelSource.GetFactory(OnModelCreating))
                               .BuildServiceProvider();

            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.UseSqlite(_testStore.Connection);

            _options = optionsBuilder.Options;

            using (var context = new DbContext(_serviceProvider, _options))
            {
                context.Database.EnsureCreated();
            }
        }
Exemplo n.º 6
0
 public SqliteForeignKeyTest()
 {
     _testStore = SqliteTestStore.CreateScratch();
 }