-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringExtensionsTests.cs
More file actions
75 lines (63 loc) · 2.26 KB
/
Copy pathStringExtensionsTests.cs
File metadata and controls
75 lines (63 loc) · 2.26 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
using System;
using System.Collections.Generic;
using Kattbot.Common.Utils;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Kattbot.Tests;
[TestClass]
public class StringExtensionsTests
{
[TestMethod]
[DataRow("This is a test string", 10, new[] { "This is a", "test", "string" })]
[DataRow("This is a test string", 12, new[] { "This is a", "test string" })]
[DataRow("This is another test string", 10, new[] { "This is", "another", "test", "string" })]
public void SplitString_WithValidStringInput_ReturnsExpectedStrings(
string input,
int chunkLength,
string[] expected)
{
// Act
List<string> actual = input.SplitString(chunkLength);
// Assert
CollectionAssert.AreEqual(expected.AsReadOnly(), actual);
}
[TestMethod]
[DataRow("This is a test string", 10, new[] { "This is a", "[wat]test", "[wat]string" })]
[DataRow("This is a test string", 12, new[] { "This is a", "[wat]test", "[wat]string" })]
[DataRow("This is another test string", 10, new[] { "This is", "[wat]another", "[wat]test", "[wat]string" })]
public void SplitString_WithValidInputAndSplitToken_ReturnsExpectedStrings(
string input,
int chunkLength,
string[] expected)
{
// Arrange
const string splitToken = "[wat]";
// Act
List<string> actual = input.SplitString(chunkLength, splitToken);
// Assert
CollectionAssert.AreEqual(expected.AsReadOnly(), actual);
}
[TestMethod]
public void SplitString_WithEmptyStringInput_ReturnsEmptyList()
{
// Arrange
var input = string.Empty;
var chunkLength = 1;
var expected = new List<string>();
// Act
List<string> actual = input.SplitString(chunkLength);
// Assert
CollectionAssert.AreEqual(expected, actual);
}
[TestMethod]
public void SplitString_WithSplitTokenLongerThanChunkLength_ThrowsArgumentException()
{
// Arrange
var input = string.Empty;
const int chunkLength = 1;
const string token = "ab";
// Act
Func<List<string>> actual = () => input.SplitString(chunkLength, token);
// Assert
Assert.Throws<ArgumentException>(actual);
}
}