diff --git a/src/EventSourcingTests/mandatory_stream_type_behavior.cs b/src/EventSourcingTests/mandatory_stream_type_behavior.cs index a78daf9469..9bf20f5038 100644 --- a/src/EventSourcingTests/mandatory_stream_type_behavior.cs +++ b/src/EventSourcingTests/mandatory_stream_type_behavior.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using EventSourcingTests.Aggregation; +using JasperFx.Core; using Marten; using Marten.Events; using Marten.Exceptions; @@ -87,6 +88,30 @@ await Should.ThrowAsync(async () => }); } + [Fact] + public async Task happy_path_usage_with_guid() + { + StoreOptions(opts => opts.Events.UseMandatoryStreamTypeDeclaration = true); + + theSession.Events.StartStream(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(Guid.NewGuid().ToString(), new AEvent()); + + await theSession.SaveChangesAsync(); + } + public static void configure_mandatory_stream_type() { #region sample_UseMandatoryStreamTypeDeclaration diff --git a/src/Marten/Events/EventGraph.Actions.cs b/src/Marten/Events/EventGraph.Actions.cs index 1233036098..c1a1cf6c49 100644 --- a/src/Marten/Events/EventGraph.Actions.cs +++ b/src/Marten/Events/EventGraph.Actions.cs @@ -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) { @@ -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()) { diff --git a/src/Marten/Events/EventStore.StartStream.cs b/src/Marten/Events/EventStore.StartStream.cs index 44af9bda69..e6933bea00 100644 --- a/src/Marten/Events/EventStore.StartStream.cs +++ b/src/Marten/Events/EventStore.StartStream.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Marten.Exceptions; using Marten.Schema.Identity; namespace Marten.Events; @@ -62,6 +63,7 @@ public StreamAction StartStream(Guid id, IEnumerable events) public StreamAction StartStream(Guid id, params object[] events) { + if (_store.Events.UseMandatoryStreamTypeDeclaration) throw new StreamTypeMissingException(); return _store.Events.StartStream(_session, id, events); } @@ -72,6 +74,7 @@ public StreamAction StartStream(string streamKey, IEnumerable events) public StreamAction StartStream(string streamKey, params object[] events) { + if (_store.Events.UseMandatoryStreamTypeDeclaration) throw new StreamTypeMissingException(); return _store.Events.StartStream(_session, streamKey, events); }