-
Notifications
You must be signed in to change notification settings - Fork 368
/
EventRoutingSlipTests.cs
145 lines (108 loc) · 4.54 KB
/
EventRoutingSlipTests.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using FluentAssertions;
using System;
using System.Collections.Generic;
using Xunit;
namespace Microsoft.DotNet.Interactive.Tests;
public class EventRoutingSlipTests
{
[Fact]
public void can_be_stamped_with_kernel_uri()
{
var routingSlip = new EventRoutingSlip();
routingSlip.Stamp(new Uri("kernel://1"));
var other = new EventRoutingSlip();
other.Stamp(new Uri("kernel://1"));
routingSlip.StartsWith(other).Should().BeTrue();
}
[Fact]
public void cannot_can_be_stamped_with_kernel_uri_twice()
{
var routingSlip = new EventRoutingSlip();
routingSlip.Stamp(new Uri("kernel://1"));
var markAgain = () => routingSlip.Stamp(new Uri("kernel://1"));
markAgain.Should().ThrowExactly<InvalidOperationException>()
.WithMessage("The uri kernel://1/ is already in the routing slip");
}
[Fact]
public void can_continue_a_routingSlip_with_another()
{
var original = new EventRoutingSlip();
original.Stamp(new Uri("kernel://1"));
original.Stamp(new Uri("kernel://2"));
var continuation = new EventRoutingSlip();
continuation.Stamp(new Uri("kernel://3"));
continuation.Stamp(new Uri("kernel://4"));
original.ContinueWith(continuation);
original.ToUriArray().Should().ContainInOrder(
"kernel://1/",
"kernel://2/",
"kernel://3/",
"kernel://4/");
}
[Theory]
[MemberData(nameof(EventRoutingSlipsToTest))]
public void starts_with_urls(EventRoutingSlip other, bool startsWith)
{
var original = new EventRoutingSlip();
original.Stamp(new Uri("kernel://1"));
original.Stamp(new Uri("kernel://2"));
original.Stamp(new Uri("kernel://3"));
original.StartsWith(other).Should().Be(startsWith);
}
public static IEnumerable<object[]> EventRoutingSlipsToTest()
{
var routingSlip = new EventRoutingSlip();
yield return new object[] { routingSlip, false};
routingSlip = new EventRoutingSlip();
routingSlip.Stamp(new Uri("kernel://1"));
yield return new object[] { routingSlip, true};
routingSlip = new EventRoutingSlip();
routingSlip.Stamp(new Uri("kernel://1"));
routingSlip.Stamp(new Uri("kernel://2"));
yield return new object[] {routingSlip, true };
routingSlip = new EventRoutingSlip();
routingSlip.Stamp(new Uri("kernel://1"));
routingSlip.Stamp(new Uri("kernel://2"));
routingSlip.Stamp(new Uri("kernel://3"));
yield return new object[] { routingSlip, true };
routingSlip = new EventRoutingSlip();
routingSlip.Stamp(new Uri("kernel://1"));
routingSlip.Stamp(new Uri("kernel://2"));
routingSlip.Stamp(new Uri("kernel://4"));
yield return new object[] { routingSlip, false };
}
[Fact]
public void can_continue_a_routingSlip_to_another_skipping_entries_if_the_other_contains_it()
{
var original = new EventRoutingSlip();
original.Stamp(new Uri("kernel://1"));
original.Stamp(new Uri("kernel://2"));
var continuation = new EventRoutingSlip();
continuation.Stamp(new Uri("kernel://1"));
continuation.Stamp(new Uri("kernel://2"));
continuation.Stamp(new Uri("kernel://3"));
continuation.Stamp(new Uri("kernel://4"));
original.ContinueWith(continuation);
original.ToUriArray().Should().ContainInOrder(
"kernel://1/",
"kernel://2/",
"kernel://3/",
"kernel://4/");
}
[Fact]
public void throws_exception_when_continuing_a_routingSlip_with_another_if_they_do_not_start_with_same_uri_sequence()
{
var original = new EventRoutingSlip();
original.Stamp(new Uri("kernel://1"));
original.Stamp(new Uri("kernel://2"));
original.Stamp(new Uri("kernel://3"));
var continuation = new EventRoutingSlip();
continuation.Stamp(new Uri("kernel://1"));
continuation.Stamp(new Uri("kernel://3"));
continuation.Stamp(new Uri("kernel://4"));
var appendAction = () => original.ContinueWith(continuation);
appendAction.Should().ThrowExactly<InvalidOperationException>().WithMessage("The uri kernel://1/ is already in the routing slip");
}
}