generated from mauroservienti/code-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
When_doing_something.cs
65 lines (57 loc) · 1.93 KB
/
When_doing_something.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using MyMessages.Messages;
using MyOtherService;
using MyService;
using NServiceBus;
using NServiceBus.AcceptanceTesting;
using NServiceBus.IntegrationTesting;
using NUnit.Framework;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace MySystem.AcceptanceTests
{
public class When_doing_something
{
[Test]
public async Task something_should_happen()
{
var expectedSomeId = Guid.NewGuid();
var context = await Scenario.Define<Context>()
.WithEndpoint<MyServiceEndpoint>(g => g.When(b => b.Send(new AMessage() { ThisWillBeTheSagaId = expectedSomeId })))
.WithEndpoint<MyOtherServiceEndpoint>()
.Done(c =>
{
return
(
c.HandlerWasInvoked<AMessageHandler>()
&& c.HandlerWasInvoked<AReplyMessageHandler>()
&& c.SagaWasInvoked<ASaga>()
)
|| c.HasFailedMessages();
})
.Run();
var invokedSaga = context.InvokedSagas.Single(s => s.SagaType == typeof(ASaga));
Assert.True(invokedSaga.IsNew);
Assert.True(((ASagaData)invokedSaga.SagaData).SomeId == expectedSomeId);
Assert.False(context.HasFailedMessages());
Assert.False(context.HasHandlingErrors());
}
class Context : IntegrationContext
{
}
class MyServiceEndpoint : EndpointConfigurationBuilder
{
public MyServiceEndpoint()
{
EndpointSetup<ServiceTemplate<MyServiceConfiguration>>();
}
}
class MyOtherServiceEndpoint : EndpointConfigurationBuilder
{
public MyOtherServiceEndpoint()
{
EndpointSetup<ServiceTemplate<MyOtherServiceConfiguration>>();
}
}
}
}