forked from fixie/fixie
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCaseSourceAttributeCalculatorTests.cs
More file actions
137 lines (122 loc) · 4.57 KB
/
TestCaseSourceAttributeCalculatorTests.cs
File metadata and controls
137 lines (122 loc) · 4.57 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System;
using System.Text;
using Should;
namespace Fixie.Samples.Parameterized
{
using System.Collections.Generic;
public class TestCaseSourceAttributeCalculatorTests : IDisposable
{
readonly Calculator calculator;
readonly StringBuilder log;
public TestCaseSourceAttributeCalculatorTests()
{
calculator = new Calculator();
log = new StringBuilder();
log.WhereAmI();
}
public static IEnumerable<object[]> CustomFieldSource = new List<object[]>
{
new object[] { 10, 30, 40 },
new object[] { 2, 14, 16 }
};
public static IEnumerable<object[]> CustomMethodSource()
{
return new List<object[]>
{
new object[]{1, 3, 4},
new object[]{12, 15, 27}
};
}
public static IEnumerable<object[]> CustomPropertySource => new List<object[]>
{
new object[] { 8, 5, 3 },
new object[] { 5, 3, 2 },
new object[] { 10, 5, 5 }
};
[TestCaseSource("CustomFieldSource")]
public void ShouldAddFromFieldSource(int a, int b, int expectedSum)
{
log.AppendFormat("ShouldAdd({0}, {1}, {2})", a, b, expectedSum);
log.AppendLine();
calculator.Add(a, b).ShouldEqual(expectedSum);
}
[TestCaseSource("CustomFieldSource", typeof(ExternalSourceOfTestCaseData))]
public void ShouldAddFromExternalFieldSource(int a, int b, int expectedSum)
{
log.AppendFormat("ShouldAdd({0}, {1}, {2})", a, b, expectedSum);
log.AppendLine();
calculator.Add(a, b).ShouldEqual(expectedSum);
}
[TestCaseSource("CustomMethodSource")]
public void ShouldAddFromMethodSource(int a, int b, int expectedSum)
{
log.AppendFormat("ShouldAdd({0}, {1}, {2})", a, b, expectedSum);
log.AppendLine();
calculator.Add(a, b).ShouldEqual(expectedSum);
}
[TestCaseSource("CustomMethodSource", typeof(ExternalSourceOfTestCaseData))]
public void ShouldAddFromExternalMethodSource(int a, int b, int expectedSum)
{
log.AppendFormat("ShouldAdd({0}, {1}, {2})", a, b, expectedSum);
log.AppendLine();
calculator.Add(a, b).ShouldEqual(expectedSum);
}
[TestCaseSource("CustomPropertySource")]
public void ShouldSubtractFromPropertySource(int a, int b, int expectedDifference)
{
log.AppendFormat("ShouldSubtract({0}, {1}, {2})", a, b, expectedDifference);
log.AppendLine();
calculator.Subtract(a, b).ShouldEqual(expectedDifference);
}
[TestCaseSource("CustomPropertySource", typeof(ExternalSourceOfTestCaseData))]
public void ShouldSubtractFromExternalPropertySource(int a, int b, int expectedDifference)
{
log.AppendFormat("ShouldSubtract({0}, {1}, {2})", a, b, expectedDifference);
log.AppendLine();
calculator.Subtract(a, b).ShouldEqual(expectedDifference);
}
public void Dispose()
{
log.WhereAmI();
log.ShouldHaveLines(
".ctor",
"ShouldAdd(100, 300, 400)",
"ShouldAdd(22, 34, 56)",
"ShouldAdd(11, 33, 44)",
"ShouldAdd(110, 115, 225)",
"ShouldAdd(10, 30, 40)",
"ShouldAdd(2, 14, 16)",
"ShouldAdd(1, 3, 4)",
"ShouldAdd(12, 15, 27)",
"ShouldSubtract(100, 35, 65)",
"ShouldSubtract(18, 5, 13)",
"ShouldSubtract(25, 23, 2)",
"ShouldSubtract(10, 5, 5)",
"ShouldSubtract(5, 3, 2)",
"ShouldSubtract(8, 5, 3)",
"Dispose");
}
}
public class ExternalSourceOfTestCaseData
{
public static IEnumerable<object[]> CustomFieldSource = new List<object[]>
{
new object[] { 100, 300, 400 },
new object[] { 22, 34, 56 }
};
public static IEnumerable<object[]> CustomMethodSource()
{
return new List<object[]>
{
new object[]{11, 33, 44},
new object[]{110, 115, 225}
};
}
public static IEnumerable<object[]> CustomPropertySource => new List<object[]>
{
new object[] { 18, 5, 13 },
new object[] { 25, 23, 2 },
new object[] { 100, 35, 65 }
};
}
}