Testing Audit Trail¶
Deepstaging provides TestAuditStore — a test double for IAuditStore with call recording and typed query APIs. No mocking libraries needed.
TestAuditStore¶
Records every SaveAsync call. Query recorded entries by entity, actor, or action.
var store = new TestAuditStore();
// ... run your handler that creates audit entries ...
// Assert an audit entry was recorded for a specific entity
var entries = store.EntriesForEntity("Order", "order-123");
await Assert.That(entries).Count().IsEqualTo(1);
await Assert.That(entries[0].Action).IsEqualTo("created");
await Assert.That(entries[0].Actor).IsEqualTo("user-42");
Call Recording¶
| Property | Type | Description |
|---|---|---|
SavedEntries |
IReadOnlyList<AuditEntry> |
All recorded audit entries |
Typed Queries¶
| Method | Returns | Description |
|---|---|---|
EntriesForEntity(string entityType, string entityId) |
IReadOnlyList<AuditEntry> |
Entries for a specific entity |
EntriesByActor(string actor) |
IReadOnlyList<AuditEntry> |
Entries by a specific actor |
EntriesByAction(string action) |
IReadOnlyList<AuditEntry> |
Entries for a specific action type |
Usage Example¶
var store = new TestAuditStore();
// ... run a command that audits multiple actions ...
// Assert by actor
var adminActions = store.EntriesByActor("admin");
await Assert.That(adminActions).Count().IsGreaterThanOrEqualTo(1);
// Assert by action type
var deletions = store.EntriesByAction("deleted");
await Assert.That(deletions).Count().IsEqualTo(0); // no deletions occurred