public void It_enforces_foreign_key(bool suppress)
        {
            using (var testStore = (SqliteTestStore)SqliteTestStore.GetOrCreate("ForeignKeyTest")
                                   .Initialize(null, t => new MyContext(t.AddProviderOptions(new DbContextOptionsBuilder()).Options), null))
            {
                testStore.CloseConnection();

                var builder = testStore.AddProviderOptions(new DbContextOptionsBuilder());
                new SqliteDbContextOptionsBuilder(builder).SuppressForeignKeyEnforcement(suppress);

                using (var context = new MyContext(builder.Options))
                {
                    context.Add(
                        new Child
                    {
                        ParentId = 4
                    });
                    if (suppress)
                    {
                        context.SaveChanges();
                    }
                    else
                    {
                        var ex = Assert.Throws <DbUpdateException>(() => context.SaveChanges());
                        // ReSharper disable once PossibleNullReferenceException
                        Assert.Contains("FOREIGN KEY constraint failed", ex.InnerException.Message, StringComparison.OrdinalIgnoreCase);
                    }
                }
            }
        }
Пример #2
0
        public async Task Create_sets_journal_mode_to_wal(bool async)
        {
            using var testStore = SqliteTestStore.GetOrCreate("Create");
            using var context   = CreateContext(testStore.ConnectionString);
            var creator = context.GetService <IRelationalDatabaseCreator>();

            if (async)
            {
                await creator.CreateAsync();
            }
            else
            {
                creator.Create();
            }

            testStore.OpenConnection();
            var journalMode = testStore.ExecuteScalar <string>("PRAGMA journal_mode;");

            Assert.Equal("wal", journalMode);
        }