-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MartenOps.StartStream() can guard against empty or null stream keys w…
…hen using string identified streams. Closes GH-1269
- Loading branch information
1 parent
6bd7d41
commit 76539a6
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
src/Persistence/MartenTests/validate_empty_stream_key_on_start_stream.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,69 @@ | ||
using IntegrationTests; | ||
using Marten; | ||
using Marten.Events; | ||
using MartenTests.Distribution.TripDomain; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Oakton.Resources; | ||
using Shouldly; | ||
using Wolverine; | ||
using Wolverine.Marten; | ||
|
||
namespace MartenTests; | ||
|
||
public class validate_empty_stream_key_on_start_stream: PostgresqlContext, IAsyncLifetime | ||
{ | ||
private IHost _host; | ||
private IDocumentStore _store; | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
_host = await Host.CreateDefaultBuilder() | ||
.UseWolverine(opts => | ||
{ | ||
opts.Services | ||
.AddMarten(m => | ||
{ | ||
m.Connection(Servers.PostgresConnectionString); | ||
m.DatabaseSchemaName = "start_stream"; | ||
m.Events.StreamIdentity = StreamIdentity.AsString; | ||
}) | ||
.IntegrateWithWolverine(); | ||
|
||
opts.Policies.AutoApplyTransactions(); | ||
|
||
opts.Services.AddResourceSetupOnStartup(); | ||
}).StartAsync(); | ||
|
||
_store = _host.Services.GetRequiredService<IDocumentStore>(); | ||
|
||
await _store.Advanced.Clean.DeleteDocumentsByTypeAsync(typeof(NamedDocument)); | ||
} | ||
|
||
public async Task DisposeAsync() | ||
{ | ||
await _host.StopAsync(); | ||
_host.Dispose(); | ||
} | ||
|
||
[Fact] | ||
public void assert_empty_stream_key() | ||
{ | ||
using var session = _store.LightweightSession(); | ||
|
||
// No stream key supplied | ||
var op = MartenOps.StartStream<Trip>(new TripStarted()); | ||
|
||
Should.Throw<InvalidOperationException>(() => op.Execute(session)); | ||
} | ||
|
||
[Fact] | ||
public void happy_path_execution() | ||
{ | ||
using var session = _store.LightweightSession(); | ||
|
||
// No stream key supplied | ||
var op = MartenOps.StartStream<Trip>("a good key", new TripStarted()); | ||
op.Execute(session); | ||
} | ||
} |
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