diff options
author | crupest <crupest@outlook.com> | 2021-02-12 17:08:54 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-02-12 17:08:54 +0800 |
commit | 31e467d72bc9b3cc7a7bb8c5bec4d2998ca49916 (patch) | |
tree | be3f2b075b6127ba2d2484fd0391df2096d5f04e /BackEnd/Timeline.Tests | |
parent | 3b60ec8b8fe13710f954338c27ed98b46e1ed1fd (diff) | |
download | timeline-31e467d72bc9b3cc7a7bb8c5bec4d2998ca49916.tar.gz timeline-31e467d72bc9b3cc7a7bb8c5bec4d2998ca49916.tar.bz2 timeline-31e467d72bc9b3cc7a7bb8c5bec4d2998ca49916.zip |
test: Add some helper function.
Diffstat (limited to 'BackEnd/Timeline.Tests')
-rw-r--r-- | BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs | 8 | ||||
-rw-r--r-- | BackEnd/Timeline.Tests/XUnitHelper.cs | 44 |
2 files changed, 45 insertions, 7 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs index 0f264774..85db0908 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs @@ -401,13 +401,7 @@ namespace Timeline.Tests.IntegratedTests testDataList.AddRange(testData.Select(d => new List<HttpTimelinePostCreateRequestData>() { d! }));
- foreach (var generatorTestData in TimelineNameGeneratorTestData())
- {
- var generator = generatorTestData[0];
-
- foreach (var d in testDataList)
- yield return new object?[] { generator, d };
- }
+ return TimelineNameGeneratorTestData().AppendTestData(testDataList);
}
[Theory]
diff --git a/BackEnd/Timeline.Tests/XUnitHelper.cs b/BackEnd/Timeline.Tests/XUnitHelper.cs new file mode 100644 index 00000000..a2812ad3 --- /dev/null +++ b/BackEnd/Timeline.Tests/XUnitHelper.cs @@ -0,0 +1,44 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Timeline.Tests
+{
+ public static class XUnitHelper
+ {
+ public static IEnumerable<object?[]> ComposeTestData(params IEnumerable<object?[]>[] testDatas)
+ {
+ return ComposeTestData(new ArraySegment<IEnumerable<object?[]>>(testDatas));
+ }
+
+ public static IEnumerable<object?[]> ComposeTestData(ArraySegment<IEnumerable<object?[]>> testDatas)
+ {
+ if (testDatas.Count == 0)
+ throw new ArgumentException("Test data list can't be empty.", nameof(testDatas));
+
+ if (testDatas.Count == 1)
+ {
+ foreach (var d in testDatas[0])
+ yield return d;
+ }
+ else
+ {
+ foreach (var head in testDatas[0])
+ foreach (var rest in ComposeTestData(testDatas.Slice(1)))
+ yield return head.Concat(rest).ToArray();
+ }
+ }
+
+ public static IEnumerable<object?[]> AppendTestData(this IEnumerable<object?[]> origin, params IEnumerable<object?>[] toAppend)
+ {
+ IEnumerable<object?[]> result = origin;
+
+ foreach (var oneToAppend in toAppend)
+ {
+ result = ComposeTestData(result, oneToAppend.Select(testData => new object?[] { testData }));
+ }
+
+ return result;
+ }
+ }
+}
|