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.
dedicated behavior to reschedule timeouts, integration test
- Loading branch information
1 parent
c09d282
commit 528d86d
Showing
7 changed files
with
108 additions
and
66 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
48 changes: 48 additions & 0 deletions
48
src/NServiceBus.IntegrationTesting.Tests/Reschedule_Timeout_Behavior.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,48 @@ | ||
using MyMessages.Messages; | ||
using NServiceBus.DelayedDelivery; | ||
using NServiceBus.DeliveryConstraints; | ||
using NServiceBus.Pipeline; | ||
using NServiceBus.Testing; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace NServiceBus.IntegrationTesting.Tests | ||
{ | ||
public class Reschedule_Timeout_Behavior | ||
{ | ||
[Test] | ||
public async Task Should_Reschedule_Timeouts() | ||
{ | ||
var expectedDeliveryAt = new DateTime(2020, 1, 1); | ||
|
||
var scenarioContext = new IntegrationScenarioContext(); | ||
scenarioContext.RegisterTimeoutRescheduleRule<AMessage>(currentDelay => | ||
{ | ||
return new DoNotDeliverBefore(expectedDeliveryAt); | ||
}); | ||
|
||
var context = new TestableOutgoingSendContext | ||
{ | ||
Message = new OutgoingLogicalMessage(typeof(AMessage), new AMessage()) | ||
}; | ||
context.Headers.Add(Headers.SagaId, "a-saga-id"); | ||
context.Headers.Add(Headers.SagaType, "a-saga-type"); | ||
context.Headers.Add(Headers.IsSagaTimeoutMessage, bool.TrueString); | ||
|
||
var constraints = new List<DeliveryConstraint> | ||
{ | ||
new DoNotDeliverBefore(new DateTime(2030, 1, 1)) | ||
}; | ||
context.Extensions.Set(constraints); | ||
|
||
var sut = new RescheduleTimeoutsBehavior(scenarioContext); ; | ||
await sut.Invoke(context, () => Task.CompletedTask).ConfigureAwait(false); | ||
|
||
var rescheduledDoNotDeliverBefore = constraints.OfType<DoNotDeliverBefore>().Single(); | ||
Assert.AreEqual(expectedDeliveryAt, rescheduledDoNotDeliverBefore.At); | ||
} | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/NServiceBus.IntegrationTesting/InterceptPhysicalDispatch.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,35 @@ | ||
using NServiceBus.DelayedDelivery; | ||
using NServiceBus.DeliveryConstraints; | ||
using NServiceBus.Pipeline; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace NServiceBus.IntegrationTesting | ||
{ | ||
class RescheduleTimeoutsBehavior : Behavior<IOutgoingSendContext> | ||
{ | ||
readonly IntegrationScenarioContext integrationContext; | ||
|
||
public RescheduleTimeoutsBehavior(IntegrationScenarioContext integrationContext) | ||
{ | ||
this.integrationContext = integrationContext; | ||
} | ||
|
||
public override Task Invoke(IOutgoingSendContext context, Func<Task> next) | ||
{ | ||
if (integrationContext.TryGetTimeoutRescheduleRule(context.Message.MessageType, out Func<DoNotDeliverBefore, DoNotDeliverBefore> rule)) | ||
{ | ||
var constraints = context.Extensions.Get<List<DeliveryConstraint>>(); | ||
var doNotDeliverBefore = constraints.OfType<DoNotDeliverBefore>().SingleOrDefault(); | ||
|
||
var newDoNotDeliverBefore = rule(doNotDeliverBefore); | ||
constraints.Remove(doNotDeliverBefore); | ||
constraints.Add(newDoNotDeliverBefore); | ||
} | ||
|
||
return next(); | ||
} | ||
} | ||
} |
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