Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the embarrassing bug w/ mandatory stream markers. Closes GH-3482 #3486

Merged
merged 1 commit into from
Oct 17, 2024
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
25 changes: 25 additions & 0 deletions src/EventSourcingTests/mandatory_stream_type_behavior.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using EventSourcingTests.Aggregation;
using JasperFx.Core;
using Marten;
using Marten.Events;
using Marten.Exceptions;
Expand Down Expand Up @@ -87,6 +88,30 @@ await Should.ThrowAsync<NonExistentStreamException>(async () =>
});
}

[Fact]
public async Task happy_path_usage_with_guid()
{
StoreOptions(opts => opts.Events.UseMandatoryStreamTypeDeclaration = true);

theSession.Events.StartStream<MyAggregate>(Guid.NewGuid(), new AEvent());

await theSession.SaveChangesAsync();
}

[Fact]
public async Task happy_path_usage_with_string()
{
StoreOptions(opts =>
{
opts.Events.UseMandatoryStreamTypeDeclaration = true;
opts.Events.StreamIdentity = StreamIdentity.AsString;
});

theSession.Events.StartStream<MyAggregate>(Guid.NewGuid().ToString(), new AEvent());

await theSession.SaveChangesAsync();
}

public static void configure_mandatory_stream_type()
{
#region sample_UseMandatoryStreamTypeDeclaration
Expand Down
2 changes: 0 additions & 2 deletions src/Marten/Events/EventGraph.Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ internal StreamAction Append(DocumentSessionBase session, string stream, params
internal StreamAction StartStream(DocumentSessionBase session, Guid id, params object[] events)
{
EnsureAsGuidStorage(session);
if (UseMandatoryStreamTypeDeclaration) throw new StreamTypeMissingException();

if (id == Guid.Empty)
{
Expand Down Expand Up @@ -123,7 +122,6 @@ internal StreamAction StartEmptyStream(DocumentSessionBase session, string key,
internal StreamAction StartStream(DocumentSessionBase session, string streamKey, params object[] events)
{
EnsureAsStringStorage(session);
if (UseMandatoryStreamTypeDeclaration) throw new StreamTypeMissingException();

if (streamKey.IsEmpty())
{
Expand Down
3 changes: 3 additions & 0 deletions src/Marten/Events/EventStore.StartStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Marten.Exceptions;
using Marten.Schema.Identity;

namespace Marten.Events;
Expand Down Expand Up @@ -62,6 +63,7 @@ public StreamAction StartStream(Guid id, IEnumerable<object> events)

public StreamAction StartStream(Guid id, params object[] events)
{
if (_store.Events.UseMandatoryStreamTypeDeclaration) throw new StreamTypeMissingException();
return _store.Events.StartStream(_session, id, events);
}

Expand All @@ -72,6 +74,7 @@ public StreamAction StartStream(string streamKey, IEnumerable<object> events)

public StreamAction StartStream(string streamKey, params object[] events)
{
if (_store.Events.UseMandatoryStreamTypeDeclaration) throw new StreamTypeMissingException();
return _store.Events.StartStream(_session, streamKey, events);
}

Expand Down
Loading