-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMockAsyncCaptureExtensionsTests.cs
More file actions
99 lines (83 loc) · 2.79 KB
/
MockAsyncCaptureExtensionsTests.cs
File metadata and controls
99 lines (83 loc) · 2.79 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using Concepts.Tests.Fixtures;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Concepts.Tests
{
[TestClass]
public class MockAsyncCaptureExtensionsTests
{
[TestMethod]
public async Task ShouldBeAbleToCaptureSingleParameterMethodArguments()
{
var expected = new[]
{
"first",
"second",
"third",
};
var mock = new Mock<ICaptureFixture>();
var results = new List<string>();
mock
.Setup(f => f.DoSomethingAsync(It.IsAny<string>()))
.Capture(results)
.Returns(Task.CompletedTask);
foreach (var key in expected)
{
await mock.Object.DoSomethingAsync(key);
}
CollectionAssert.AreEqual(expected, results);
}
[TestMethod]
public async Task ShouldBeAbleToCaptureTwoParameterMethodArgumentsAsTuples()
{
var expected = new[]
{
new Tuple<string, int>("first", 42),
new Tuple<string, int>("second", 43),
new Tuple<string, int>("third", 44),
};
var mock = new Mock<ICaptureFixture>();
var results = new List<Tuple<string, int>>();
mock
.Setup(f => f.DoSomethingAsync(It.IsAny<string>(), It.IsAny<int>()))
.Capture(results)
.Returns(Task.CompletedTask);
foreach (var tuple in expected)
{
await mock.Object.DoSomethingAsync(tuple.Item1, tuple.Item2);
}
CollectionAssert.AreEqual(expected, results);
}
[TestMethod]
public void ShouldBeAbleToCaptureTwoParameterMethodArgumentsAsLists()
{
var expectedStrings = new[]
{
"first",
"second",
"third",
};
var expectedInts = new[]
{
42,
43,
44
};
var mock = new Mock<ICaptureFixture>();
var stringResults = new List<string>();
var intResults = new List<int>();
mock
.Setup(f => f.DoSomethingAsync(It.IsAny<string>(), It.IsAny<int>()))
.Capture(stringResults, intResults);
for (var i = 0; i < expectedStrings.Length; i++)
{
mock.Object.DoSomethingAsync(expectedStrings[i], expectedInts[i]);
}
CollectionAssert.AreEqual(expectedStrings, stringResults);
CollectionAssert.AreEqual(expectedInts, intResults);
}
}
}