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.
Merge pull request #54 from mauroservienti/capture-outgoing-messages
Capture outgoing operations
- Loading branch information
Showing
15 changed files
with
332 additions
and
24 deletions.
There are no files selected for viewing
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
23 changes: 23 additions & 0 deletions
23
src/NServiceBus.IntegrationTesting.Tests/NServiceBus.IntegrationTesting.Tests.csproj
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,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" /> | ||
<PackageReference Include="NETStandard.Library" Version="2.0.3" /> | ||
<PackageReference Include="NServiceBus.Testing" Version="7.2.0" /> | ||
<PackageReference Include="NUnit" Version="3.12.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\MyMessages\MyMessages.csproj" /> | ||
<ProjectReference Include="..\NServiceBus.IntegrationTesting\NServiceBus.IntegrationTesting.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
31 changes: 31 additions & 0 deletions
31
src/NServiceBus.IntegrationTesting.Tests/Publish_Operation_Interceptor.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,31 @@ | ||
using MyMessages.Messages; | ||
using NServiceBus.Pipeline; | ||
using NServiceBus.Testing; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace NServiceBus.IntegrationTesting.Tests | ||
{ | ||
public class Publish_Operation_Interceptor | ||
{ | ||
[Test] | ||
public async Task Should_Capture_Publish_Message_Operation() | ||
{ | ||
var scenarioContext = new IntegrationScenarioContext(); | ||
var context = new TestableOutgoingPublishContext | ||
{ | ||
Message = new OutgoingLogicalMessage(typeof(AMessage), new AMessage()) | ||
}; | ||
|
||
var sut = new InterceptPublishOperations("fake-endpoint", scenarioContext); | ||
await sut.Invoke(context, () => Task.CompletedTask).ConfigureAwait(false); | ||
|
||
var operation = scenarioContext.OutgoingMessageOperations.SingleOrDefault() as PublishOperation; | ||
|
||
Assert.AreEqual(1, scenarioContext.OutgoingMessageOperations.Count()); | ||
Assert.IsNotNull(operation); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/NServiceBus.IntegrationTesting.Tests/Reply_Operation_Interceptor.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,31 @@ | ||
using MyMessages.Messages; | ||
using NServiceBus.Pipeline; | ||
using NServiceBus.Testing; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace NServiceBus.IntegrationTesting.Tests | ||
{ | ||
public class Reply_Operation_Interceptor | ||
{ | ||
[Test] | ||
public async Task Should_Capture_Reply_Message_Operation() | ||
{ | ||
var scenarioContext = new IntegrationScenarioContext(); | ||
var context = new TestableOutgoingReplyContext | ||
{ | ||
Message = new OutgoingLogicalMessage(typeof(AMessage), new AMessage()) | ||
}; | ||
|
||
var sut = new InterceptReplyOperations("fake-endpoint", scenarioContext); | ||
await sut.Invoke(context, () => Task.CompletedTask).ConfigureAwait(false); | ||
|
||
var operation = scenarioContext.OutgoingMessageOperations.SingleOrDefault() as ReplyOperation; | ||
|
||
Assert.AreEqual(1, scenarioContext.OutgoingMessageOperations.Count()); | ||
Assert.IsNotNull(operation); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/NServiceBus.IntegrationTesting.Tests/Send_Operation_Interceptor.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,57 @@ | ||
using MyMessages.Messages; | ||
using NServiceBus.Pipeline; | ||
using NServiceBus.Testing; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace NServiceBus.IntegrationTesting.Tests | ||
{ | ||
public class Send_Operation_Interceptor | ||
{ | ||
[Test] | ||
public async Task Should_Capture_Sent_Message_Operation() | ||
{ | ||
var scenarioContext = new IntegrationScenarioContext(); | ||
var context = new TestableOutgoingSendContext | ||
{ | ||
Message = new OutgoingLogicalMessage(typeof(AMessage), new AMessage()) | ||
}; | ||
|
||
var sut = new InterceptSendOperations("fake-endpoint", scenarioContext); | ||
await sut.Invoke(context, () => Task.CompletedTask).ConfigureAwait(false); | ||
|
||
var sendOperation = scenarioContext.OutgoingMessageOperations.SingleOrDefault() as SendOperation; | ||
|
||
Assert.AreEqual(1, scenarioContext.OutgoingMessageOperations.Count()); | ||
Assert.IsNotNull(sendOperation); | ||
} | ||
|
||
[Test] | ||
public async Task Should_Capture_TimeoutRequest_Operation() | ||
{ | ||
var expectedSagaId = "a-saga-id"; | ||
var expectedSagaType = "a-saga-type"; | ||
|
||
var scenarioContext = new IntegrationScenarioContext(); | ||
var context = new TestableOutgoingSendContext | ||
{ | ||
Message = new OutgoingLogicalMessage(typeof(AMessage), new AMessage()) | ||
}; | ||
context.Headers.Add(Headers.SagaId, expectedSagaId); | ||
context.Headers.Add(Headers.SagaType, expectedSagaType); | ||
context.Headers.Add(Headers.IsSagaTimeoutMessage, bool.TrueString); | ||
|
||
var sut = new InterceptSendOperations("fake-endpoint", scenarioContext); ; | ||
await sut.Invoke(context, () => Task.CompletedTask).ConfigureAwait(false); | ||
|
||
var requestTimeoutOperation = scenarioContext.OutgoingMessageOperations.SingleOrDefault() as RequestTimeoutOperation; | ||
|
||
Assert.AreEqual(1, scenarioContext.OutgoingMessageOperations.Count()); | ||
Assert.IsNotNull(requestTimeoutOperation); | ||
Assert.AreEqual(expectedSagaId, requestTimeoutOperation.SagaId); | ||
Assert.AreEqual(expectedSagaType, requestTimeoutOperation.SagaTypeAssemblyQualifiedName); | ||
} | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
src/NServiceBus.IntegrationTesting/InterceptPublishOperations.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,41 @@ | ||
using NServiceBus.Pipeline; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace NServiceBus.IntegrationTesting | ||
{ | ||
class InterceptPublishOperations : Behavior<IOutgoingPublishContext> | ||
{ | ||
readonly string endpointName; | ||
readonly IntegrationScenarioContext integrationContext; | ||
|
||
public InterceptPublishOperations(string endpointName, IntegrationScenarioContext integrationContext) | ||
{ | ||
this.endpointName = endpointName; | ||
this.integrationContext = integrationContext; | ||
} | ||
|
||
public override async Task Invoke(IOutgoingPublishContext context, Func<Task> next) | ||
{ | ||
var sendOperation = new PublishOperation | ||
{ | ||
SenderEndpoint = endpointName, | ||
MessageId = context.MessageId, | ||
MessageType = context.Message.MessageType, | ||
MessageInstance = context.Message.Instance, | ||
MessageHeaders = context.Headers | ||
}; | ||
|
||
integrationContext.AddOutogingOperation(sendOperation); | ||
try | ||
{ | ||
await next(); | ||
} | ||
catch(Exception sendError) | ||
{ | ||
sendOperation.OperationError = sendError; | ||
throw; | ||
} | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/NServiceBus.IntegrationTesting/InterceptReplyOperations.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,41 @@ | ||
using NServiceBus.Pipeline; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace NServiceBus.IntegrationTesting | ||
{ | ||
class InterceptReplyOperations : Behavior<IOutgoingReplyContext> | ||
{ | ||
readonly string endpointName; | ||
readonly IntegrationScenarioContext integrationContext; | ||
|
||
public InterceptReplyOperations(string endpointName, IntegrationScenarioContext integrationContext) | ||
{ | ||
this.endpointName = endpointName; | ||
this.integrationContext = integrationContext; | ||
} | ||
|
||
public override async Task Invoke(IOutgoingReplyContext context, Func<Task> next) | ||
{ | ||
var sendOperation = new ReplyOperation | ||
{ | ||
SenderEndpoint = endpointName, | ||
MessageId = context.MessageId, | ||
MessageType = context.Message.MessageType, | ||
MessageInstance = context.Message.Instance, | ||
MessageHeaders = context.Headers | ||
}; | ||
|
||
integrationContext.AddOutogingOperation(sendOperation); | ||
try | ||
{ | ||
await next(); | ||
} | ||
catch(Exception sendError) | ||
{ | ||
sendOperation.OperationError = sendError; | ||
throw; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.