public void Exists_returns_true_when_database_exists()
        {
            using (var testStore = SqliteTestStore.GetOrCreateInitialized("Empty"))
            {
                var creator = GetDatabaseCreator(testStore.ConnectionString);

                Assert.True(creator.Exists());
            }
        }
Пример #2
0
        public async Task HasTables_returns_false_when_database_is_empty(bool async)
        {
            using var testStore = SqliteTestStore.GetOrCreateInitialized("Empty");
            var context = CreateContext(testStore.ConnectionString);

            var creator = context.GetService <IRelationalDatabaseCreator>();

            Assert.False(async ? await creator.HasTablesAsync() : creator.HasTables());
        }
Пример #3
0
        public async Task HasTables_returns_true_when_database_is_not_empty(bool async)
        {
            using (var testStore = SqliteTestStore.GetOrCreateInitialized($"HasATable{(async ? 'A' : 'S')}"))
            {
                var context = CreateContext(testStore.ConnectionString);
                context.Database.ExecuteSqlRaw("CREATE TABLE Dummy (Foo INTEGER)");

                var creator = context.GetService <IRelationalDatabaseCreator>();
                Assert.True(async ? await creator.HasTablesAsync() : creator.HasTables());
            }
        }
Пример #4
0
        public async Task Exists_returns_true_when_database_exists(bool async, bool useCanConnect)
        {
            using var testStore = SqliteTestStore.GetOrCreateInitialized("Empty");
            var context = CreateContext(testStore.ConnectionString);

            if (useCanConnect)
            {
                Assert.True(async ? await context.Database.CanConnectAsync() : context.Database.CanConnect());
            }
            else
            {
                var creator = context.GetService <IRelationalDatabaseCreator>();
                Assert.True(async ? await creator.ExistsAsync() : creator.Exists());
            }
        }
Пример #5
0
        public void It_allows_foreign_key_to_unique_index()
        {
            using (var testStore = SqliteTestStore.GetOrCreateInitialized("ForeignKeyIndexTest"))
            {
                var options = testStore
                              .AddProviderOptions(new DbContextOptionsBuilder())
                              .UseInternalServiceProvider(new ServiceCollection().AddEntityFrameworkSqlite().BuildServiceProvider())
                              .Options;

                testStore.ExecuteNonQuery(
                    @"
CREATE TABLE User (
    Id INTEGER PRIMARY KEY,
    AltId INTEGER NOT NULL UNIQUE
);
CREATE TABLE Comment (
    Id INTEGER PRIMARY KEY,
    UserAltId INTEGER NOT NULL,
    Comment TEXT,
    FOREIGN KEY (UserAltId) REFERENCES User (AltId)
);");

                long id;
                using (var context = new BloggingContext(options))
                {
                    var entry = context.User.Add(
                        new User
                    {
                        AltId = 1356524
                    });
                    context.Comments.Add(
                        new Comment
                    {
                        User = entry.Entity
                    });
                    context.SaveChanges();
                    id = entry.Entity.Id;
                }

                using (var context = new BloggingContext(options))
                {
                    var comment = context.Comments.Include(u => u.User).Single();
                    Assert.Equal(id, comment.User.Id);
                }
            }
        }