-
-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathConvertEventToMessage.cs
More file actions
141 lines (120 loc) · 4.41 KB
/
ConvertEventToMessage.cs
File metadata and controls
141 lines (120 loc) · 4.41 KB
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
using Eventuous.Azure.ServiceBus.Producers;
using Eventuous.Azure.ServiceBus.Shared;
namespace Eventuous.Tests.Azure.ServiceBus;
public class ConvertEventToMessage {
readonly Guid _messageId = Guid.NewGuid();
readonly ServiceBusMessage _message;
public ConvertEventToMessage() {
var builder = new ServiceBusMessageBuilder(
EventSerializer.Default,
"test-stream",
new(),
new() {
Subject = "test-subject",
To = "test-to",
ReplyTo = "test-reply-to",
TimeToLive = TimeSpan.FromMinutes(5)
}
);
_message = builder.CreateServiceBusMessage(
new(
new SomeEvent {
Id = "event-id",
Name = "Test Event"
},
new() {
[MetaTags.CorrelationId] = "correlation-id",
[MetaTags.CausationId] = "causation-id",
["AAA"] = 1111
},
new() { ["BBB"] = "12345" },
_messageId
)
);
}
[Test]
public async Task ContentType() {
await Assert.That(_message.ContentType).IsEqualTo("application/json");
}
[Test]
public async Task MessageId() {
await Assert.That(_message.MessageId).IsEqualTo(_messageId.ToString());
}
[Test]
public async Task Subject() {
await Assert.That(_message.Subject).IsEqualTo("test-subject");
}
[Test]
public async Task To() {
await Assert.That(_message.To).IsEqualTo("test-to");
}
[Test]
public async Task ReplyTo() {
await Assert.That(_message.ReplyTo).IsEqualTo("test-reply-to");
}
[Test]
public async Task TimeToLive() {
await Assert.That(_message.TimeToLive).IsEqualTo(TimeSpan.FromMinutes(5));
}
[Test]
public async Task CorrelationId() {
await Assert.That(_message.CorrelationId).IsEqualTo("correlation-id");
}
[Test]
[Arguments("MessageId")]
[Arguments("CorrelationId")]
public async Task ApplicationPropertiesHasNoReservedAttributes(string propertyName) {
await Assert.That(_message.ApplicationProperties.ContainsKey(propertyName)).IsFalse();
}
[Test]
[Arguments(MetaTags.CausationId, "causation-id")]
[Arguments("AAA", 1111)]
[Arguments("BBB", "12345")]
public async Task ApplicationPropertiesHasAttributes(string propertyName, object expectedValue) {
await Assert.That(_message.ApplicationProperties[propertyName]).IsEqualTo(expectedValue);
}
public class WithMessagePropertiesInMetaData {
readonly ServiceBusMessage _message;
public WithMessagePropertiesInMetaData() {
var attributeNames = new ServiceBusMessageAttributeNames();
var builder = new ServiceBusMessageBuilder(EventSerializer.Default, "test-stream", attributeNames, new());
_message = builder.CreateServiceBusMessage(
new(
new SomeEvent {
Id = "event-id",
Name = "Test Event"
},
new() {
[attributeNames.MessageId] = "12345",
[attributeNames.CorrelationId] = "correlation-id",
[attributeNames.CausationId] = "causation-id",
[attributeNames.ReplyTo] = "test-reply-to",
[attributeNames.Subject] = "test-subject",
[attributeNames.To] = "test-to"
},
new()
)
);
}
[Test]
public async Task MessageId() {
await Assert.That(_message.MessageId).IsEqualTo("12345");
}
[Test]
public async Task Subject() {
await Assert.That(_message.Subject).IsEqualTo("test-subject");
}
[Test]
public async Task To() {
await Assert.That(_message.To).IsEqualTo("test-to");
}
[Test]
public async Task ReplyTo() {
await Assert.That(_message.ReplyTo).IsEqualTo("test-reply-to");
}
[Test]
public async Task CorrelationId() {
await Assert.That(_message.CorrelationId).IsEqualTo("correlation-id");
}
}
}