/
When_sending_from_a_saga_timeout.cs
88 lines (71 loc) · 2.33 KB
/
When_sending_from_a_saga_timeout.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
namespace NServiceBus.AcceptanceTests.Sagas
{
using System;
using EndpointTemplates;
using AcceptanceTesting;
using NUnit.Framework;
using Saga;
using ScenarioDescriptors;
public class When_sending_from_a_saga_timeout : NServiceBusAcceptanceTest
{
[Test]
public void Should_match_different_saga()
{
Scenario.Define<Context>()
.WithEndpoint<Endpoint>(b => b.Given(bus => bus.SendLocal(new StartSaga1())))
.Done(c => c.DidSaga2ReceiveMessage)
.Repeat(r => r.For(Transports.Default))
.Should(c => Assert.True(c.DidSaga2ReceiveMessage))
.Run(TimeSpan.FromSeconds(20));
}
public class Context : ScenarioContext
{
public bool DidSaga2ReceiveMessage { get; set; }
}
public class Endpoint : EndpointConfigurationBuilder
{
public Endpoint()
{
EndpointSetup<DefaultServer>();
}
public class Saga1 : Saga<Saga1.Saga1Data>, IAmStartedByMessages<StartSaga1>, IHandleTimeouts<Saga1Timeout>
{
public Context Context { get; set; }
public void Handle(StartSaga1 message)
{
RequestTimeout(TimeSpan.FromSeconds(1), new Saga1Timeout());
}
public void Timeout(Saga1Timeout state)
{
Bus.SendLocal(new StartSaga2());
MarkAsComplete();
}
public class Saga1Data : ContainSagaData
{
}
}
public class Saga2 : Saga<Saga2.Saga2Data>, IAmStartedByMessages<StartSaga2>
{
public Context Context { get; set; }
public void Handle(StartSaga2 message)
{
Context.DidSaga2ReceiveMessage = true;
}
public class Saga2Data : ContainSagaData
{
}
}
}
[Serializable]
public class StartSaga1 : ICommand
{
}
[Serializable]
public class StartSaga2 : ICommand
{
}
public class Saga1Timeout : IMessage
{
}
}
}