-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
322 additions
and
35 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/NServiceBus.AcceptanceTests/MessageMutators/Issue_1980.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,83 @@ | ||
namespace NServiceBus.AcceptanceTests.Sagas | ||
{ | ||
using System; | ||
using EndpointTemplates; | ||
using AcceptanceTesting; | ||
using MessageMutator; | ||
using NUnit.Framework; | ||
|
||
public class Issue_1980 : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public void Run() | ||
{ | ||
var context = new Context(); | ||
|
||
Scenario.Define(context) | ||
.WithEndpoint<Endpoint>(b => b.Given((bus, c) => bus.SendLocal(new V1Message()))) | ||
.Done(c => c.V2MessageReceived) | ||
.Run(); | ||
|
||
Assert.IsTrue(context.V2MessageReceived); | ||
Assert.IsFalse(context.V1MessageReceived); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
public bool V1MessageReceived { get; set; } | ||
public bool V2MessageReceived { get; set; } | ||
} | ||
|
||
public class Endpoint : EndpointConfigurationBuilder | ||
{ | ||
public Endpoint() | ||
{ | ||
EndpointSetup<DefaultServer>( | ||
c => c.Configurer.ConfigureComponent<MutateIncomingMessages>(DependencyLifecycle.InstancePerCall)); | ||
} | ||
|
||
class MutateIncomingMessages : IMutateIncomingMessages | ||
{ | ||
public object MutateIncoming(object message) | ||
{ | ||
if (message is V1Message) | ||
{ | ||
return new V2Message(); | ||
} | ||
|
||
return message; | ||
} | ||
} | ||
|
||
class V2MessageHandler : IHandleMessages<V2Message> | ||
{ | ||
public Context Context { get; set; } | ||
|
||
public void Handle(V2Message message) | ||
{ | ||
Context.V2MessageReceived = true; | ||
} | ||
} | ||
|
||
class V1MessageHandler : IHandleMessages<V1Message> | ||
{ | ||
public Context Context { get; set; } | ||
|
||
public void Handle(V1Message message) | ||
{ | ||
Context.V1MessageReceived = true; | ||
} | ||
} | ||
} | ||
|
||
[Serializable] | ||
public class V1Message : ICommand | ||
{ | ||
} | ||
|
||
[Serializable] | ||
public class V2Message : ICommand | ||
{ | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...iceBus.AcceptanceTests/MessageMutators/When_outgoing_mutator_replaces_message_instance.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,83 @@ | ||
namespace NServiceBus.AcceptanceTests.Sagas | ||
{ | ||
using System; | ||
using AcceptanceTesting; | ||
using EndpointTemplates; | ||
using MessageMutator; | ||
using NUnit.Framework; | ||
|
||
public class When_outgoing_mutator_replaces_message_instance : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public void Message_sent_should_be_new_instance() | ||
{ | ||
var context = new Context(); | ||
|
||
Scenario.Define(context) | ||
.WithEndpoint<Endpoint>(b => b.Given((bus, c) => bus.SendLocal(new V1Message()))) | ||
.Done(c => c.V2MessageReceived) | ||
.Run(); | ||
|
||
Assert.IsTrue(context.V2MessageReceived); | ||
Assert.IsFalse(context.V1MessageReceived); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
public bool V1MessageReceived { get; set; } | ||
public bool V2MessageReceived { get; set; } | ||
} | ||
|
||
public class Endpoint : EndpointConfigurationBuilder | ||
{ | ||
public Endpoint() | ||
{ | ||
EndpointSetup<DefaultServer>( | ||
c => c.Configurer.ConfigureComponent<MutateOutgoingMessages>(DependencyLifecycle.InstancePerCall)); | ||
} | ||
|
||
class MutateOutgoingMessages : IMutateOutgoingMessages | ||
{ | ||
public object MutateOutgoing(object message) | ||
{ | ||
if (message is V1Message) | ||
{ | ||
return new V2Message(); | ||
} | ||
|
||
return message; | ||
} | ||
} | ||
|
||
class V2MessageHandler : IHandleMessages<V2Message> | ||
{ | ||
public Context Context { get; set; } | ||
|
||
public void Handle(V2Message message) | ||
{ | ||
Context.V2MessageReceived = true; | ||
} | ||
} | ||
|
||
class V1MessageHandler : IHandleMessages<V1Message> | ||
{ | ||
public Context Context { get; set; } | ||
|
||
public void Handle(V1Message message) | ||
{ | ||
Context.V1MessageReceived = true; | ||
} | ||
} | ||
} | ||
|
||
[Serializable] | ||
public class V1Message : ICommand | ||
{ | ||
} | ||
|
||
[Serializable] | ||
public class V2Message : ICommand | ||
{ | ||
} | ||
} | ||
} |
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
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,99 @@ | ||
namespace NServiceBus.AcceptanceTests.Sagas | ||
{ | ||
using System; | ||
using EndpointTemplates; | ||
using AcceptanceTesting; | ||
using NUnit.Framework; | ||
using Saga; | ||
|
||
public class Issue_2044 : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public void Run() | ||
{ | ||
var context = new Context(); | ||
|
||
Scenario.Define(context) | ||
.WithEndpoint<Sender>(b => b.Given((bus, c) => bus.Send(new MessageToSaga()))) | ||
.WithEndpoint<ReceiverWithSaga>() | ||
.Done(c => c.ReplyReceived) | ||
.Run(); | ||
|
||
Assert.IsTrue(context.ReplyReceived); | ||
} | ||
|
||
public class Context : ScenarioContext | ||
{ | ||
public bool ReplyReceived { get; set; } | ||
} | ||
|
||
public class Sender : EndpointConfigurationBuilder | ||
{ | ||
public Sender() | ||
{ | ||
EndpointSetup<DefaultServer>() | ||
.AddMapping<MessageToSaga>(typeof(ReceiverWithSaga)); | ||
} | ||
|
||
public class ReplyHandler : IHandleMessages<Reply> | ||
{ | ||
public Context Context { get; set; } | ||
|
||
|
||
public void Handle(Reply message) | ||
{ | ||
Context.ReplyReceived = true; | ||
} | ||
} | ||
} | ||
|
||
public class ReceiverWithSaga : EndpointConfigurationBuilder | ||
{ | ||
public ReceiverWithSaga() | ||
{ | ||
EndpointSetup<DefaultServer>(); | ||
} | ||
|
||
public class Saga1 : Saga<Saga1.Saga1Data>, IAmStartedByMessages<StartSaga1>, IHandleMessages<MessageToSaga> | ||
{ | ||
|
||
public void Handle(StartSaga1 message) | ||
{ | ||
} | ||
|
||
public void Handle(MessageToSaga message) | ||
{ | ||
} | ||
|
||
public class Saga1Data : ContainSagaData | ||
{ | ||
} | ||
} | ||
|
||
public class SagaNotFound : IHandleSagaNotFound | ||
{ | ||
public IBus Bus { get; set; } | ||
|
||
public void Handle(object message) | ||
{ | ||
Bus.Reply(new Reply()); | ||
} | ||
} | ||
} | ||
|
||
[Serializable] | ||
public class StartSaga1 : ICommand | ||
{ | ||
} | ||
|
||
[Serializable] | ||
public class MessageToSaga : ICommand | ||
{ | ||
} | ||
|
||
[Serializable] | ||
public class Reply : IMessage | ||
{ | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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
Oops, something went wrong.