Skip to content

Commit ce8475d

Browse files
committed
Add some tests to ensure exceptions are thrown on string splitter with null/empty message or maxchunksize <1
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
1 parent a8f5117 commit ce8475d

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

ManualTests/ManualTests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@
99
<ProjectReference Include="..\Matterhook.NET.MatterhookClient\Matterhook.NET.MatterhookClient.csproj" />
1010
</ItemGroup>
1111

12+
<ItemGroup>
13+
<None Update="config.json">
14+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
15+
</None>
16+
</ItemGroup>
17+
1218
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using Xunit;
5+
6+
namespace Matterhook.NET.MatterhookClient.Tests
7+
{
8+
public class MiscTests
9+
{
10+
11+
[Fact]
12+
public void StringSplitterThrowsExceptionWhenNullStringPassed()
13+
{
14+
Assert.Throws<ArgumentException>(() => StringSplitter.SplitTextIntoChunks(null, 250, false));
15+
}
16+
17+
[Fact]
18+
public void StringSplitterThrowsExceptionWhenChunkSizeOfLessThan1()
19+
{
20+
Assert.Throws<ArgumentException>(() => StringSplitter.SplitTextIntoChunks("A message", 0, false));
21+
}
22+
23+
}
24+
}

Matterhook.NET.MatterhookClient/MatterhookClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public async Task<HttpResponseMessage> PostAsync(MattermostMessage inMessage, in
108108

109109
foreach (var msg in outMessages)
110110
{
111-
var msgJson = msg.SerializeToJson();
111+
var msgJson = msg.SerializeToJson();
112112
response = await _httpClient.PostAsync(_webhookUrl,
113113
new StringContent(msgJson, Encoding.UTF8, "application/json")).ConfigureAwait(false);
114114
}

Matterhook.NET.MatterhookClient/MattermostMessage.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ internal MattermostMessage Clone()
5151
};
5252
}
5353

54-
5554
public string SerializeToJson()
5655
{
5756
return JsonConvert.SerializeObject(this, new MattermostJsonSerializerSettings());

0 commit comments

Comments
 (0)