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 StoreGeneratedSqliteFixture()
 {
     _serviceProvider = new ServiceCollection()
                        .AddEntityFramework()
                        .AddSqlite()
                        .ServiceCollection()
                        .AddSingleton(TestSqliteModelSource.GetFactory(OnModelCreating))
                        .BuildServiceProvider();
 }
Пример #4
0
 protected GraphUpdatesSqliteFixtureBase()
 {
     _serviceProvider = new ServiceCollection()
                        .AddEntityFramework()
                        .AddSqlite()
                        .ServiceCollection()
                        .AddSingleton(TestSqliteModelSource.GetFactory(OnModelCreating))
                        .BuildServiceProvider();
 }
Пример #5
0
 public GearsOfWarQuerySqliteFixture()
 {
     _serviceProvider = new ServiceCollection()
                        .AddEntityFramework()
                        .AddSqlite()
                        .ServiceCollection()
                        .AddSingleton(TestSqliteModelSource.GetFactory(OnModelCreating))
                        .AddSingleton <ILoggerFactory>(new TestSqlLoggerFactory())
                        .BuildServiceProvider();
 }
Пример #6
0
 public DataAnnotationSqliteFixture()
 {
     _serviceProvider = new ServiceCollection()
                        .AddEntityFramework()
                        .AddSqlite()
                        .ServiceCollection()
                        .AddSingleton(TestSqliteModelSource.GetFactory(OnModelCreating))
                        .AddInstance <ILoggerFactory>(new TestSqlLoggerFactory())
                        .BuildServiceProvider();
 }
        public NorthwindQuerySqliteFixture()
        {
            _serviceProvider
                = new ServiceCollection()
                  .AddEntityFramework()
                  .AddSqlite()
                  .ServiceCollection()
                  .AddSingleton(TestSqliteModelSource.GetFactory(OnModelCreating))
                  .AddSingleton <ILoggerFactory>(_testSqlLoggerFactory)
                  .BuildServiceProvider();

            _options = BuildOptions();

            _serviceProvider.GetRequiredService <ILoggerFactory>();
        }
Пример #8
0
            public NullKeysSqliteFixture()
            {
                _serviceProvider = new ServiceCollection()
                                   .AddEntityFramework()
                                   .AddSqlite()
                                   .ServiceCollection()
                                   .AddSingleton(TestSqliteModelSource.GetFactory(OnModelCreating))
                                   .BuildServiceProvider();

                var optionsBuilder = new DbContextOptionsBuilder();

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

                EnsureCreated();
            }
Пример #9
0
        public NorthwindQuerySqliteFixture()
        {
            _testStore = SqliteNorthwindContext.GetSharedStore();

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

            var optionsBuilder = new DbContextOptionsBuilder();

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

            _serviceProvider.GetRequiredService <ILoggerFactory>()
            .MinimumLevel = LogLevel.Debug;
        }
Пример #10
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();
            }
        }