generated from mauroservienti/code-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support inheritance in completion conditions (#104)
* Support inheritance in MessageWasProcessedByHandler * minor styling tweaks * simpler tests * Support inheritance in MessageWasProcessed * Support inheritance in MessageWasProcessedBySaga
- Loading branch information
1 parent
7411607
commit ceed0b6
Showing
3 changed files
with
209 additions
and
4 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
src/NServiceBus.IntegrationTesting.Tests/When_capturing_handlers_invocations.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,104 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
|
||
namespace NServiceBus.IntegrationTesting.Tests | ||
{ | ||
public class When_capturing_handlers_invocations | ||
{ | ||
class TestMessage : IMessage | ||
{ | ||
|
||
} | ||
|
||
interface IMessageInterface: IMessage | ||
{ | ||
|
||
} | ||
|
||
class InheritedMessage : IMessageInterface | ||
{ | ||
|
||
} | ||
|
||
class TestMessageHandler : IHandleMessages<TestMessage> | ||
{ | ||
public Task Handle(TestMessage message, IMessageHandlerContext context) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
class MessageInterfaceHandler : IHandleMessages<IMessageInterface> | ||
{ | ||
public Task Handle(IMessageInterface message, IMessageHandlerContext context) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
[Test] | ||
public void MessageWasProcessedByHandler_condition_should_match_type() | ||
{ | ||
var scenarioContext = new IntegrationScenarioContext(); | ||
scenarioContext.CaptureInvokedHandler(new HandlerInvocation() | ||
{ | ||
Message = new TestMessage(), | ||
EndpointName = "fake-endpoint", | ||
HandlerType = typeof(TestMessageHandler), | ||
HandlingError = null, | ||
MessageType = typeof(TestMessage) | ||
}); | ||
|
||
Assert.IsTrue(scenarioContext.MessageWasProcessedByHandler<TestMessage, TestMessageHandler>()); | ||
} | ||
|
||
[Test] | ||
public void MessageWasProcessedByHandler_condition_should_match_base_type() | ||
{ | ||
var scenarioContext = new IntegrationScenarioContext(); | ||
scenarioContext.CaptureInvokedHandler(new HandlerInvocation() | ||
{ | ||
Message = new InheritedMessage(), | ||
EndpointName = "fake-endpoint", | ||
HandlerType = typeof(MessageInterfaceHandler), | ||
HandlingError = null, | ||
MessageType = typeof(InheritedMessage) | ||
}); | ||
|
||
Assert.IsTrue(scenarioContext.MessageWasProcessedByHandler<IMessageInterface, MessageInterfaceHandler>()); | ||
} | ||
|
||
[Test] | ||
public void MessageWasProcessed_condition_should_match_type() | ||
{ | ||
var scenarioContext = new IntegrationScenarioContext(); | ||
scenarioContext.CaptureInvokedHandler(new HandlerInvocation() | ||
{ | ||
Message = new TestMessage(), | ||
EndpointName = "fake-endpoint", | ||
HandlerType = typeof(TestMessageHandler), | ||
HandlingError = null, | ||
MessageType = typeof(TestMessage) | ||
}); | ||
|
||
Assert.IsTrue(scenarioContext.MessageWasProcessed<TestMessage>()); | ||
} | ||
|
||
[Test] | ||
public void MessageWasProcessed_condition_should_match_base_type() | ||
{ | ||
var scenarioContext = new IntegrationScenarioContext(); | ||
scenarioContext.CaptureInvokedHandler(new HandlerInvocation() | ||
{ | ||
Message = new InheritedMessage(), | ||
EndpointName = "fake-endpoint", | ||
HandlerType = typeof(MessageInterfaceHandler), | ||
HandlingError = null, | ||
MessageType = typeof(InheritedMessage) | ||
}); | ||
|
||
Assert.IsTrue(scenarioContext.MessageWasProcessed<IMessageInterface>()); | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
src/NServiceBus.IntegrationTesting.Tests/When_capturing_sagas_invocations.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,101 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
|
||
namespace NServiceBus.IntegrationTesting.Tests | ||
{ | ||
public class When_capturing_sagas_invocations | ||
{ | ||
class TestMessage : IMessage | ||
{ | ||
} | ||
|
||
interface IMessageInterface : IMessage | ||
{ | ||
} | ||
|
||
class InheritedMessage : IMessageInterface | ||
{ | ||
} | ||
|
||
class TestSaga : Saga<TestSaga.Data>, | ||
IHandleMessages<TestMessage>, | ||
IHandleMessages<IMessageInterface> | ||
{ | ||
internal class Data : ContainSagaData | ||
{ | ||
} | ||
|
||
protected override void ConfigureHowToFindSaga(SagaPropertyMapper<Data> mapper) | ||
{ | ||
/**/ | ||
} | ||
|
||
public Task Handle(TestMessage message, IMessageHandlerContext context) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task Handle(IMessageInterface message, IMessageHandlerContext context) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
[Test] | ||
public void MessageWasProcessedBySaga_condition_should_match_type() | ||
{ | ||
var scenarioContext = new IntegrationScenarioContext(); | ||
scenarioContext.CaptureInvokedSaga(new SagaInvocation() | ||
{ | ||
Message = new TestMessage(), EndpointName = "fake-endpoint", SagaType = typeof(TestSaga), MessageType = typeof(TestMessage) | ||
}); | ||
|
||
Assert.IsTrue(scenarioContext.MessageWasProcessedBySaga<TestMessage, TestSaga>()); | ||
} | ||
|
||
[Test] | ||
public void MessageWasProcessedBySaga_condition_should_match_base_type() | ||
{ | ||
var scenarioContext = new IntegrationScenarioContext(); | ||
scenarioContext.CaptureInvokedSaga(new SagaInvocation() | ||
{ | ||
Message = new InheritedMessage(), EndpointName = "fake-endpoint", SagaType = typeof(TestSaga), MessageType = typeof(InheritedMessage) | ||
}); | ||
|
||
Assert.IsTrue(scenarioContext.MessageWasProcessedBySaga<IMessageInterface, TestSaga>()); | ||
} | ||
|
||
[Test] | ||
public void MessageWasProcessed_condition_should_match_type() | ||
{ | ||
var scenarioContext = new IntegrationScenarioContext(); | ||
scenarioContext.CaptureInvokedSaga(new SagaInvocation() | ||
{ | ||
Message = new TestMessage(), | ||
EndpointName = "fake-endpoint", | ||
SagaType = typeof(TestSaga), | ||
HandlingError = null, | ||
MessageType = typeof(TestMessage) | ||
}); | ||
|
||
Assert.IsTrue(scenarioContext.MessageWasProcessed<TestMessage>()); | ||
} | ||
|
||
[Test] | ||
public void MessageWasProcessed_condition_should_match_base_type() | ||
{ | ||
var scenarioContext = new IntegrationScenarioContext(); | ||
scenarioContext.CaptureInvokedSaga(new SagaInvocation() | ||
{ | ||
Message = new InheritedMessage(), | ||
EndpointName = "fake-endpoint", | ||
SagaType = typeof(TestSaga), | ||
HandlingError = null, | ||
MessageType = typeof(InheritedMessage) | ||
}); | ||
|
||
Assert.IsTrue(scenarioContext.MessageWasProcessed<IMessageInterface>()); | ||
} | ||
} | ||
} |
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