Created
October 13, 2014 23:14
-
-
Save johnsimons/e4d5ce122846220392c4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| namespace NServiceBus.AcceptanceTests.Sagas | |
| { | |
| using System; | |
| using NServiceBus.AcceptanceTesting; | |
| using NServiceBus.AcceptanceTests.EndpointTemplates; | |
| using NServiceBus.Saga; | |
| using NUnit.Framework; | |
| public class When_reply_to_a_saga : NServiceBusAcceptanceTest | |
| { | |
| [Test] | |
| public void Reply_message_should_start_other_sagas() | |
| { | |
| var context = Scenario.Define<Context>() | |
| .WithEndpoint<SagaEndpoint>(b => b.Given(bus => | |
| { | |
| var message = new StartMySaga(); | |
| bus.SendLocal(message); | |
| })) | |
| .Done(c => c.MySagaAnotherMessageCalled && c.MyOtherSagaAnotherMessageCalled) | |
| .Run(); | |
| Assert.True(context.MySagaAnotherMessageCalled); | |
| Assert.True(context.MyOtherSagaAnotherMessageCalled); | |
| } | |
| class RaiseAnotherMessageHandler : IHandleMessages<RaiseAnotherMessage> | |
| { | |
| public IBus Bus { get; set; } | |
| public void Handle(RaiseAnotherMessage message) | |
| { | |
| Bus.Reply(new AnotherMessage{CorrelationId = message.CorrelationId}); | |
| } | |
| } | |
| class MySaga : Saga<MySaga.SagaData>, IAmStartedByMessages<StartMySaga>, | |
| IHandleMessages<AnotherMessage> | |
| { | |
| public Context Context { get; set; } | |
| public class SagaData : ContainSagaData | |
| { | |
| public Guid CorrelationId { get; set; } | |
| } | |
| public void Handle(StartMySaga message) | |
| { | |
| Data.CorrelationId = message.CorrelationId; | |
| Bus.SendLocal(new RaiseAnotherMessage { CorrelationId = Data.CorrelationId }); | |
| } | |
| public void Handle(AnotherMessage message) | |
| { | |
| MarkAsComplete(); | |
| Context.MySagaAnotherMessageCalled = true; | |
| } | |
| public override void ConfigureHowToFindSaga() | |
| { | |
| ConfigureMapping<StartMySaga>(m => m.CorrelationId).ToSaga(s => s.CorrelationId); | |
| ConfigureMapping<AnotherMessage>(m => m.CorrelationId).ToSaga(s => s.CorrelationId); | |
| } | |
| } | |
| class MyOtherSaga : Saga<MyOtherSaga.SagaData>, IAmStartedByMessages<AnotherMessage> | |
| { | |
| public Context Context { get; set; } | |
| public class SagaData : ContainSagaData | |
| { | |
| public Guid CorrelationId { get; set; } | |
| } | |
| public void Handle(AnotherMessage message) | |
| { | |
| MarkAsComplete(); | |
| Context.MyOtherSagaAnotherMessageCalled = true; | |
| } | |
| public override void ConfigureHowToFindSaga() | |
| { | |
| ConfigureMapping<AnotherMessage>(m => m.CorrelationId).ToSaga(s => s.CorrelationId); | |
| } | |
| } | |
| class Context : ScenarioContext | |
| { | |
| public bool MySagaAnotherMessageCalled { get; set; } | |
| public bool MyOtherSagaAnotherMessageCalled { get; set; } | |
| } | |
| public class SagaEndpoint : EndpointConfigurationBuilder | |
| { | |
| public SagaEndpoint() | |
| { | |
| EndpointSetup<DefaultServer>(); | |
| } | |
| } | |
| public class StartMySaga : IMessage | |
| { | |
| public Guid CorrelationId { get; set; } | |
| } | |
| public class AnotherMessage : IMessage | |
| { | |
| public Guid CorrelationId { get; set; } | |
| } | |
| public class RaiseAnotherMessage : IMessage | |
| { | |
| public Guid CorrelationId { get; set; } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment