Skip to content

Commit 2d6fed3

Browse files
Implement tests.
1 parent 9eb3dd0 commit 2d6fed3

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

test/StreamMerge.App.Tests/Quiz/StreamRepositoryTests.cs

+28
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,35 @@ public class StreamRepositoryTests
1313
[Fact]
1414
public async Task GetNextAsync_MergesTwoStreams()
1515
{
16+
const int stream1StepSize = 3;
17+
const int stream2StepSize = 7;
18+
const string stream1Name = "stream1";
19+
const string stream2Name = "stream2";
20+
var stream1 = GetInfiniteSequence(stream1StepSize);
21+
var stream2 = GetInfiniteSequence(stream2StepSize);
22+
var streams = new Dictionary<string, IEnumerator<int>>(StreamNameComparer.Comparer)
23+
{
24+
{ stream1Name, stream1.GetEnumerator() },
25+
{ stream2Name, stream2.GetEnumerator() }
26+
};
27+
28+
var systemUnderTest = new StreamRepository(new FakeStreamClient(streams), new StreamStore());
1629

30+
const int numToCheck = 50;
31+
int last = int.MinValue;
32+
for (int index = 0; index < numToCheck; index++)
33+
{
34+
var next = await systemUnderTest.GetNextAsync(stream1Name, stream2Name);
35+
Assert.True(next.CurrentValue >= last, "The next value from the stream should be greater than or equal to the previous one.");
36+
Assert.True(
37+
next.CurrentValue % stream1StepSize == 0 || next.CurrentValue % stream2StepSize == 0,
38+
"The values from the merged stream should come from either of the source streams.");
39+
if (last != int.MinValue)
40+
{
41+
Assert.True(last == next.LastValue, "The returned last value should match the previous invocation's current value.");
42+
}
43+
last = next.CurrentValue;
44+
}
1745
}
1846

1947
#region Fake Data Helpers

test/StreamMerge.App.Tests/project.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"dependencies": {
1010
"StreamMerge.App": "1.0.0-*",
1111
"Newtonsoft.Json": "7.0.1-beta3",
12-
"xunit": "2.1.0-beta2-build2981"
12+
"xunit": "2.1.0-*",
13+
"xunit.runner.dnx": "2.1.0-*"
1314
},
1415

1516
"frameworks": {
@@ -22,5 +23,8 @@
2223
"Microsoft.CSharp": "4.0.0-beta-22816"
2324
}
2425
}
26+
},
27+
"commands": {
28+
"test": "xunit.runner.dnx"
2529
}
2630
}

0 commit comments

Comments
 (0)