-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose CreaedOn and Metadata to event wrapper
- Loading branch information
1 parent
731d07f
commit a8977cd
Showing
5 changed files
with
76 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 10 additions & 2 deletions
12
src/LogOtter.CosmosDb.EventStore/CatchUpSubscriptions/Event.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
namespace LogOtter.CosmosDb.EventStore; | ||
|
||
public class Event<TBaseEvent>(string streamId, int eventNumber, TBaseEvent body) | ||
public class Event<TBaseEvent>(string streamId, int eventNumber, TBaseEvent body, DateTimeOffset createdOn, Dictionary<string, string> metadata) | ||
where TBaseEvent : class | ||
{ | ||
public string StreamId { get; } = streamId; | ||
public int EventNumber { get; } = eventNumber; | ||
public TBaseEvent Body { get; } = body; | ||
public DateTimeOffset CreatedOn { get; } = createdOn; | ||
public Dictionary<string, string> Metadata { get; } = metadata; | ||
|
||
public static Event<TBaseEvent> FromStorageEvent(StorageEvent<TBaseEvent> storageEvent) | ||
{ | ||
return new Event<TBaseEvent>(storageEvent.StreamId, storageEvent.EventNumber, (TBaseEvent)storageEvent.EventBody); | ||
return new Event<TBaseEvent>( | ||
storageEvent.StreamId, | ||
storageEvent.EventNumber, | ||
(TBaseEvent)storageEvent.EventBody, | ||
storageEvent.CreatedOn, | ||
storageEvent.Metadata | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/LogOtter.CosmosDb.EventStore.Tests/EventDataConversionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using LogOtter.CosmosDb.EventStore.Tests.TestEvents; | ||
|
||
namespace LogOtter.CosmosDb.EventStore.Tests; | ||
|
||
public class EventDataConversionTests | ||
{ | ||
[Fact] | ||
public void WrapperEventIsCreatedFromStorageEvent() | ||
{ | ||
var id = Guid.NewGuid().ToString(); | ||
var name = "Bob Bobertson"; | ||
|
||
var testEvent = new TestEventCreated(id, name); | ||
var eventId = Guid.NewGuid(); | ||
|
||
var createdOn = DateTimeOffset.UtcNow; | ||
var eventData = new EventData<TestEvent>(eventId, testEvent, createdOn, new Dictionary<string, string> { { "key1", "value1" } }); | ||
var storageEvent = new StorageEvent<TestEvent>(id, eventData, 3); | ||
var wrapperEvent = Event<TestEvent>.FromStorageEvent(storageEvent); | ||
|
||
wrapperEvent.StreamId.Should().Be(id); | ||
wrapperEvent.EventNumber.Should().Be(3); | ||
wrapperEvent.CreatedOn.Should().Be(createdOn); | ||
wrapperEvent.Metadata.Should().ContainKey("key1").WhoseValue.Should().Be("value1"); | ||
} | ||
} |