-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
TestingIncoming.cs
155 lines (112 loc) · 5.61 KB
/
TestingIncoming.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
146
147
148
149
150
151
152
153
154
155
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedVariable
class IncomingAttachment
{
public static void InjectAttachmentsInstance()
{
#region InjectAttachmentsInstance
var context = new RecordingHandlerContext();
var mockMessageAttachments = new MyMessageAttachments();
context.InjectAttachmentsInstance(mockMessageAttachments);
#endregion
}
}
public class TestingIncoming
{
#region CustomMockMessageAttachments
public class CustomMockMessageAttachments :
MockMessageAttachments
{
public override Task<AttachmentBytes> GetBytes(Cancel cancel = default)
{
GetBytesWasCalled = true;
return Task.FromResult(new AttachmentBytes("name", [5]));
}
public bool GetBytesWasCalled { get; private set; }
}
#endregion
#region TestIncomingHandler
public class Handler :
IHandleMessages<MyMessage>
{
public async Task Handle(MyMessage message, HandlerContext context)
{
var attachment = context.Attachments();
var bytes = await attachment.GetBytes(context.CancellationToken);
}
}
#endregion
#region TestIncoming
[Fact]
public async Task TestIncomingAttachment()
{
//Arrange
var context = new RecordingHandlerContext();
var handler = new Handler();
var mockMessageAttachments = new CustomMockMessageAttachments();
context.InjectAttachmentsInstance(mockMessageAttachments);
//Act
await handler.Handle(new(), context);
//Assert
Assert.True(mockMessageAttachments.GetBytesWasCalled);
}
#endregion
}
class MyMessageAttachments :
IMessageAttachments
{
public Task<AttachmentStream> GetStream(Cancel cancel = default) =>
throw new NotImplementedException();
public Task<AttachmentStream> GetStream(string name, Cancel cancel = default) =>
throw new NotImplementedException();
public Task<AttachmentStream> GetStreamForMessage(string messageId, Cancel cancel = default) =>
throw new NotImplementedException();
public Task<AttachmentStream> GetStreamForMessage(string messageId, string name, Cancel cancel = default) =>
throw new NotImplementedException();
public Task CopyTo(string name, Stream target, Cancel cancel = default) =>
throw new NotImplementedException();
public Task CopyTo(Stream target, Cancel cancel = default) =>
throw new NotImplementedException();
public Task ProcessStream(string name, Func<AttachmentStream, Cancel, Task> action, Cancel cancel = default) =>
throw new NotImplementedException();
public Task ProcessStream(Func<AttachmentStream, Cancel, Task> action, Cancel cancel = default) =>
throw new NotImplementedException();
public Task ProcessStreams(Func<AttachmentStream, Cancel, Task> action, Cancel cancel = default) =>
throw new NotImplementedException();
public IAsyncEnumerable<AttachmentInfo> GetMetadata(Cancel cancel = default) =>
throw new NotImplementedException();
public Task<AttachmentBytes> GetBytes(Cancel cancel = default) =>
throw new NotImplementedException();
public Task<MemoryStream> GetMemoryStream(Cancel cancel = default) =>
throw new NotImplementedException();
public Task<AttachmentBytes> GetBytes(string name, Cancel cancel = default) =>
throw new NotImplementedException();
public Task<MemoryStream> GetMemoryStream(string name, Cancel cancel = default) =>
throw new NotImplementedException();
public Task<AttachmentString> GetString(Encoding? encoding, Cancel cancel = default) =>
throw new NotImplementedException();
public Task<AttachmentString> GetString(string name, Encoding? encoding, Cancel cancel = default) =>
throw new NotImplementedException();
public Task CopyToForMessage(string messageId, string name, Stream target, Cancel cancel = default) =>
throw new NotImplementedException();
public Task CopyToForMessage(string messageId, Stream target, Cancel cancel = default) =>
throw new NotImplementedException();
public Task ProcessStreamForMessage(string messageId, string name, Func<AttachmentStream, Cancel, Task> action, Cancel cancel = default) =>
throw new NotImplementedException();
public Task ProcessStreamForMessage(string messageId, Func<AttachmentStream, Cancel, Task> action, Cancel cancel = default) =>
throw new NotImplementedException();
public Task ProcessStreamsForMessage(string messageId, Func<AttachmentStream, Cancel, Task> action, Cancel cancel = default) =>
throw new NotImplementedException();
public Task<AttachmentBytes> GetBytesForMessage(string messageId, Cancel cancel = default) =>
throw new NotImplementedException();
public Task<MemoryStream> GetMemoryStreamForMessage(string messageId, Cancel cancel = default) =>
throw new NotImplementedException();
public Task<AttachmentBytes> GetBytesForMessage(string messageId, string name, Cancel cancel = default) =>
throw new NotImplementedException();
public Task<MemoryStream> GetMemoryStreamForMessage(string messageId, string name, Cancel cancel = default) =>
throw new NotImplementedException();
public Task<AttachmentString> GetStringForMessage(string messageId, Encoding? encoding, Cancel cancel = default) =>
throw new NotImplementedException();
public Task<AttachmentString> GetStringForMessage(string messageId, string name, Encoding? encoding, Cancel cancel = default) =>
throw new NotImplementedException();
}