public void TestCleanup() { var context = new AuditLogContext(_options); context.Set <AuditLogItem>().RemoveRange(context.Set <AuditLogItem>()); context.SaveChanges(); }
protected static void WriteToLog(AuditLog logItem) { using (var context = new AuditLogContext()) { context.AuditLogs.AddObject(logItem); context.SaveChanges(); } }
private void SeedData() { using var context = new AuditLogContext(_options); var logEntries = new List <LogEntry> { new LogEntry { Timestamp = new DateTime(2019, 5, 8).Ticks, RoutingKey = "Test.*", EventJson = "{'title': 'Some title'}", EventType = "DomainEvent" }, new LogEntry { Timestamp = new DateTime(2019, 7, 2).Ticks, RoutingKey = "Test.#", EventJson = "{'title': 'Some title'}", EventType = "DomainEvent" }, new LogEntry { Timestamp = new DateTime(2019, 7, 2).Ticks, RoutingKey = "Test.#", EventJson = "{'title': 'Some title'}", EventType = "DomainEvent" }, new LogEntry { Timestamp = new DateTime(2019, 8, 15).Ticks, RoutingKey = "Test2.#", EventJson = "{'title': 'Some title'}", EventType = "DomainEvent" } }; context.LogEntries.AddRange(logEntries); context.SaveChanges(); }
/// <summary> /// Inject data directly into the context /// </summary> private void InjectData(params AuditLogItem[] items) { using var context = new AuditLogContext(_options); context.AuditLogItems.AddRange(items); context.SaveChanges(); }
/// <summary> /// Save a log item to the database /// </summary> public void Save(AuditLogItem item) { _auditLogContext.AuditLogItems.Add(item); _auditLogContext.SaveChanges(); }