-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test to prove that 305 works. Closes GH-305
- Loading branch information
Jeremy D. Miller
authored and
Jeremy D. Miller
committed
Apr 11, 2023
1 parent
939dc2d
commit be938fb
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...ts/Marten/Bugs/Bug_305_invoke_async_with_return_not_publishing_with_tuple_return_value.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,81 @@ | ||
using IntegrationTests; | ||
using Marten; | ||
using Microsoft.Extensions.Hosting; | ||
using Shouldly; | ||
using Wolverine; | ||
using Wolverine.Marten; | ||
using Wolverine.Tracking; | ||
using Xunit; | ||
|
||
namespace PersistenceTests.Marten.Bugs; | ||
|
||
public class Bug_305_invoke_async_with_return_not_publishing_with_tuple_return_value : PostgresqlContext | ||
{ | ||
[Fact] | ||
public async Task should_publish_the_return_value() | ||
{ | ||
using var host = await Host.CreateDefaultBuilder() | ||
.UseWolverine(opts => | ||
{ | ||
opts.Services.AddMarten(Servers.PostgresConnectionString).IntegrateWithWolverine(); | ||
// Add the auto transaction middleware attachment policy | ||
opts.Policies.AutoApplyTransactions(); | ||
}).StartAsync(); | ||
|
||
var (tracked, created) = await host.InvokeMessageAndWaitAsync<ItemCreated>(new CreateItemCommand { Name = "Trevor" }); | ||
|
||
created.Name.ShouldBe("Trevor"); | ||
|
||
tracked.Sent.SingleMessage<ItemCreated>().Name.ShouldBe("Trevor"); | ||
tracked.Sent.SingleMessage<SecondItemCreated>().Name.ShouldBe("Trevor"); | ||
} | ||
} | ||
|
||
public class CreateItemCommand | ||
{ | ||
public string Name { get; set; } = string.Empty; | ||
} | ||
|
||
public class CreateItemCommandHandler | ||
{ | ||
public async Task<(ItemCreated, SecondItemCreated)> Handle(CreateItemCommand command, IDocumentSession session) | ||
{ | ||
var item = new Item | ||
{ | ||
Id = Guid.NewGuid(), | ||
Name = command.Name | ||
}; | ||
|
||
session.Store(item); | ||
|
||
return (new ItemCreated(item.Id, item.Name), new SecondItemCreated(item.Id, item.Name)); | ||
} | ||
} | ||
|
||
public record ItemCreated(Guid Id, string Name); | ||
|
||
public record SecondItemCreated(Guid Id, string Name); | ||
|
||
public class ItemCreatedHandler | ||
{ | ||
public Task Handle(ItemCreated message) | ||
{ | ||
Console.WriteLine($"Item created {message.Id} {message.Name}"); | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
public class SecondItemCreatedHandler | ||
{ | ||
public Task Handle(SecondItemCreated message) | ||
{ | ||
Console.WriteLine($"Second Item created {message.Id} {message.Name}"); | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
public class Item | ||
{ | ||
public Guid Id { get; set; } | ||
public string Name { get; set; } = string.Empty; | ||
} |