Skip to content

Commit

Permalink
Backport #384 to release-7.4 (#385)
Browse files Browse the repository at this point in the history
Co-authored-by: David Boike <[email protected]>
  • Loading branch information
timbussmann and DavidBoike authored Apr 27, 2022
1 parent d374e8d commit 7223e5f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/NServiceBus.Testing.Tests/Sagas/SagaCompletion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace NServiceBus.Testing.Tests.Sagas
{
using System;
using System.Threading.Tasks;
using NUnit.Framework;

[TestFixture]
public class SagaCompletion
{
[Test]
public async Task MarkStartedSagaAsComplete()
{
var saga = new TestableSaga<TestSaga, TestSagaData>();

var result = await saga.Handle(new StartSagaMessage() { CorrelationId = Guid.NewGuid() });

Assert.IsTrue(result.Completed);
}

class TestSaga : NServiceBus.Saga<TestSagaData>, IAmStartedByMessages<StartSagaMessage>
{
protected override void ConfigureHowToFindSaga(SagaPropertyMapper<TestSagaData> mapper) => mapper
.MapSaga(d => d.CorrelationId)
.ToMessage<StartSagaMessage>(m => m.CorrelationId);

public Task Handle(StartSagaMessage message, IMessageHandlerContext context)
{
MarkAsComplete();
return Task.FromResult(0);
}
}

class TestSagaData : ContainSagaData
{
public Guid CorrelationId { get; set; }
}

class StartSagaMessage : IMessage
{
public Guid CorrelationId { get; set; }
}
}
}
5 changes: 5 additions & 0 deletions src/NServiceBus.Testing/Sagas/TestableSaga.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ async Task SaveSagaData(TSaga saga, bool isNew, object mappedValue, Synchronized
{
if (saga.Completed)
{
if (isNew)
{
// Can't update a brand new but already-completed saga
return;
}
await persister.Complete(saga.Entity, session, contextBag).ConfigureAwait(false);
}
else if (isNew)
Expand Down

0 comments on commit 7223e5f

Please sign in to comment.