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.
- Loading branch information
1 parent
ac11491
commit c09d282
Showing
2 changed files
with
69 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using MyMessages.Messages; | ||
using MyService; | ||
using NServiceBus; | ||
using NServiceBus.AcceptanceTesting; | ||
using NServiceBus.DelayedDelivery; | ||
using NServiceBus.IntegrationTesting; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace MySystem.AcceptanceTests | ||
{ | ||
public class When_requesting_a_timeout | ||
{ | ||
[Test] | ||
public async Task It_should_be_rescheduled_and_handled() | ||
{ | ||
var theExpectedSagaId = Guid.NewGuid(); | ||
var context = await Scenario.Define<IntegrationScenarioContext>(ctx=> | ||
{ | ||
ctx.RegisterTimeoutRescheduleRule<ASaga.MyTimeout>(currentDelay => | ||
{ | ||
return new DoNotDeliverBefore(DateTime.Now.AddSeconds(5)); | ||
}); | ||
}) | ||
.WithEndpoint<MyServiceEndpoint>(g => | ||
{ | ||
g.When(session => session.Send("MyService", new StartASaga() { SomeId = theExpectedSagaId })); | ||
}) | ||
.Done(c => | ||
{ | ||
return | ||
( | ||
c.SagaHandledMessage<ASaga, ASaga.MyTimeout>() | ||
) | ||
|| c.HasFailedMessages(); | ||
}) | ||
.Run(); | ||
|
||
var invokedSagas = context.InvokedSagas.Where(s => s.SagaType == typeof(ASaga)); | ||
var newSaga = invokedSagas.SingleOrDefault(s => s.IsNew); | ||
var completedSaga = invokedSagas.SingleOrDefault(s => s.IsCompleted); | ||
|
||
Assert.IsNotNull(newSaga); | ||
Assert.IsNotNull(completedSaga); | ||
Assert.False(context.HasFailedMessages()); | ||
Assert.False(context.HasHandlingErrors()); | ||
} | ||
|
||
class MyServiceEndpoint : EndpointConfigurationBuilder | ||
{ | ||
public MyServiceEndpoint() | ||
{ | ||
EndpointSetup<EndpointTemplate<MyServiceConfiguration>>(); | ||
} | ||
} | ||
} | ||
} |