Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Version>8.8.2</Version>
<Version>8.9.0</Version>
<LangVersion>12.0</LangVersion>
<Authors>Jeremy D. Miller;Babu Annamalai;Jaedyn Tonee</Authors>
<PackageIconUrl>https://martendb.io/logo.png</PackageIconUrl>
Expand Down
25 changes: 25 additions & 0 deletions src/EventSourcingTests/Metadata/overriding_metadata_on_appends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,31 @@ public async Task set_header_on_individual_events(EventAppendMode mode)
events[2].Headers["color"].ShouldBe("green");
}

[Theory]
[InlineData(JasperFx.Events.EventAppendMode.Rich)]
[InlineData(JasperFx.Events.EventAppendMode.QuickWithServerTimestamps)]
public async Task override_header_on_event_with_as_type_then_get_header_but_declared_as_object(EventAppendMode mode)
{
EventAppendMode = mode;
var streamId = Guid.NewGuid();

var action = theSession.Events.StartStream(streamId, new AEvent(), new BEvent(), new CEvent());
action.Events[0].SetHeader("color", "red");
action.Events[1].SetHeader("color", "blue");
action.Events[2].SetHeader("color", "green");

await theSession.SaveChangesAsync();

object data = new AEvent();
var withHeader = theSession.Events.BuildEvent(data).WithHeader("color", "orange");
withHeader.ShouldBeOfType<Event<AEvent>>();
theSession.Events.Append(streamId, withHeader);
await theSession.SaveChangesAsync();

var events = await theSession.Events.FetchStreamAsync(streamId);
events.Last().Headers["color"].ShouldBe("orange");
}

/* TODO
Do this w/ FetchForWriting where you pass in Event<T> on new and old, quick and rich
Append by passing in Event<T>
Expand Down
6 changes: 6 additions & 0 deletions src/Marten/Events/EventStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public EventStore(DocumentSessionBase session, DocumentStore store, Tenant tenan
_store = store;
}

public IEvent BuildEvent(object data)
{
if (data == null) throw new ArgumentNullException(nameof(data));
return _store.Events.BuildEvent(data);
}

public void OverwriteEvent(IEvent e)
{
var op = new OverwriteEventOperation(_store.Events, e);
Expand Down
8 changes: 8 additions & 0 deletions src/Marten/Events/IEventStoreOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ namespace Marten.Events;

public interface IEventStoreOperations: IEventOperations, IQueryEventStore
{
/// <summary>
/// Helper to create an event wrapper as part of appending events if you need
/// to express custom metadata
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
IEvent BuildEvent(object data);

/// <summary>
/// Append one or more events in order to an existing stream and verify that maximum event id for the stream
/// matches supplied expected version or transaction is aborted.
Expand Down
Loading