public void Db_Insert_Audit(FakeDbModel fakeDbModel) { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <FakeAuditRDbContext>() .UseSqlite(connection) .Options; try { using (var context = new FakeAuditRDbContext(() => _auditUser, _auditRConfiguration, options)) { context.Database.EnsureCreated(); } using (var context = new FakeAuditRDbContext(() => _auditUser, _auditRConfiguration, options)) { context.FakeDbModels.Add(fakeDbModel); context.SaveChanges(); } using (var context = new FakeAuditRDbContext(() => _auditUser, _auditRConfiguration, options)) { Assert.True(context.FakeDbModels.Any()); Assert.True(context.AuditEntries.Any()); Assert.True(context.AuditEntryProperties.Any()); } } finally { connection.Close(); } }
public void Db_Update_Audit(FakeDbModel fakeDbModel) { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <FakeAuditRDbContext>() .UseSqlite(connection) .Options; try { var config = new AuditRConfiguration(addChangesetWhenInsert: false); using (var context = new FakeAuditRDbContext(() => _auditUser, config, options)) { context.Database.EnsureCreated(); } using (var context = new FakeAuditRDbContext(() => _auditUser, config, options)) { context.FakeDbModels.Add(fakeDbModel); context.SaveChanges(); fakeDbModel.Name = "test_data"; context.SaveChanges(); } using (var context = new FakeAuditRDbContext(() => _auditUser, config, options)) { Assert.True(context.FakeDbModels.Any()); Assert.True(context.AuditEntryProperties.Count() == 1); Assert.True(context.AuditEntries.Count() == 2); } } finally { connection.Close(); } }