Skip to content

Commit 6f6b6c4

Browse files
committed
Added support of sequential When in AAA.
1 parent 1d3f716 commit 6f6b6c4

8 files changed

Lines changed: 270 additions & 52 deletions

File tree

Docs/images/AAA.png

6.55 KB
Loading

Heleonix.Testing.NUnit.Tests/Aaa/AaaSpecTests.cs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -250,40 +250,5 @@ public static void When()
250250
Assert.That(node.NestingLevel, Is.EqualTo(0));
251251
Assert.That(node.Parent, Is.EqualTo(rootNode));
252252
}
253-
254-
/// <summary>
255-
/// Tests integration of specs.
256-
/// </summary>
257-
[MemberTest(Name = nameof(Example))]
258-
public static void Example()
259-
{
260-
AaaSpec.Arrange(() => { });
261-
262-
AaaSpec.Act(() => { });
263-
264-
AaaSpec.Teardown(() => { });
265-
266-
AaaSpec.When("When 1", () =>
267-
{
268-
AaaSpec.Arrange(() => { });
269-
270-
AaaSpec.Act(() => { });
271-
272-
AaaSpec.Teardown(() => { });
273-
274-
AaaSpec.Should("Should 1", () => { });
275-
276-
AaaSpec.And("And 1", () =>
277-
{
278-
AaaSpec.Arrange(() => { });
279-
280-
AaaSpec.Act(() => { });
281-
282-
AaaSpec.Teardown(() => { });
283-
284-
AaaSpec.Should("Should 2", () => { });
285-
});
286-
});
287-
}
288253
}
289254
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// <copyright file="MyComponent.cs" company="Heleonix - Hennadii Lutsyshyn">
2+
// Copyright (c) 2018-present Heleonix - Hennadii Lutsyshyn. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the repository root for full license information.
4+
// </copyright>
5+
6+
namespace Heleonix.Testing.NUnit.Tests.Aaa.Examples
7+
{
8+
/// <summary>
9+
/// Dummy component.
10+
/// </summary>
11+
public static class MyComponent
12+
{
13+
/// <summary>
14+
/// Dummy member.
15+
/// </summary>
16+
public static void Member1()
17+
{
18+
// Dummy member.
19+
}
20+
21+
/// <summary>
22+
/// Dummy member.
23+
/// </summary>
24+
public static void Member2()
25+
{
26+
// Dummy member.
27+
}
28+
}
29+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// <copyright file="MyComponentTests.cs" company="Heleonix - Hennadii Lutsyshyn">
2+
// Copyright (c) 2018-present Heleonix - Hennadii Lutsyshyn. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the repository root for full license information.
4+
// </copyright>
5+
6+
namespace Heleonix.Testing.NUnit.Tests.Aaa.Examples
7+
{
8+
using Heleonix.Testing.NUnit.Aaa;
9+
using static Heleonix.Testing.NUnit.Aaa.AaaSpec;
10+
11+
/// <summary>
12+
/// Tests the <see cref="MyComponent"/>.
13+
/// </summary>
14+
[ComponentTest(Type = typeof(MyComponent))]
15+
public static class MyComponentTests
16+
{
17+
/// <summary>
18+
/// Tests the <see cref="MyComponent.Member1"/>.
19+
/// </summary>
20+
[MemberTest(Name = nameof(MyComponent.Member1))]
21+
public static void Member1()
22+
{
23+
Arrange(() =>
24+
{
25+
});
26+
27+
Act(() =>
28+
{
29+
});
30+
31+
Teardown(() =>
32+
{
33+
});
34+
35+
When("the condition #1 is true", () =>
36+
{
37+
Arrange(() =>
38+
{
39+
});
40+
41+
Act(() =>
42+
{
43+
});
44+
45+
Teardown(() =>
46+
{
47+
});
48+
49+
Should("lead to the result #1", () =>
50+
{
51+
});
52+
});
53+
54+
When("the condition #2 is true", () =>
55+
{
56+
Arrange(() =>
57+
{
58+
});
59+
60+
Act(() =>
61+
{
62+
});
63+
64+
Teardown(() =>
65+
{
66+
});
67+
68+
Should("lead to the result #2", () =>
69+
{
70+
});
71+
});
72+
}
73+
74+
/// <summary>
75+
/// Tests the <see cref="MyComponent.Member2"/>.
76+
/// </summary>
77+
[MemberTest(Name = nameof(MyComponent.Member2))]
78+
public static void Member2()
79+
{
80+
Arrange(() =>
81+
{
82+
});
83+
84+
Act(() =>
85+
{
86+
});
87+
88+
Teardown(() =>
89+
{
90+
});
91+
92+
When("the action #1 is executed", () =>
93+
{
94+
Arrange(() =>
95+
{
96+
});
97+
98+
Act(() =>
99+
{
100+
});
101+
102+
Teardown(() =>
103+
{
104+
});
105+
106+
Should("lead to the result #1", () =>
107+
{
108+
});
109+
110+
And("the condition #1 is true", () =>
111+
{
112+
Arrange(() =>
113+
{
114+
});
115+
116+
Act(() =>
117+
{
118+
});
119+
120+
Teardown(() =>
121+
{
122+
});
123+
124+
Should("lead to the result #2", () =>
125+
{
126+
});
127+
});
128+
});
129+
}
130+
}
131+
}

Heleonix.Testing.NUnit.Tests/Aaa/Internal/AaaTestHostTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static void SpecStructureRules()
3838

3939
// Assert
4040
Assert.That(rules[SpecNodeType.When].SpecExecutionStackRule, Is.EqualTo("^$"));
41-
Assert.That(rules[SpecNodeType.When].PredecessorsRule, Is.EqualTo("^(Arrange)|^(Act)|^(Teardown)|^$"));
41+
Assert.That(rules[SpecNodeType.When].PredecessorsRule, Is.EqualTo("^(Arrange)|^(Act)|^(Teardown)|^(When)|^$"));
4242

4343
Assert.That(rules[SpecNodeType.And].SpecExecutionStackRule, Is.EqualTo("^(And,)*(When)"));
4444
Assert.That(rules[SpecNodeType.And].PredecessorsRule, Is.EqualTo("^(Arrange)|^(Act)|^(Should)|^(Teardown)|^(And)|^$"));

Heleonix.Testing.NUnit.Tests/Heleonix.Testing.NUnit.Tests.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
<Link>Properties\SharedAssemblyInfo.cs</Link>
5757
</Compile>
5858
<Compile Include="Aaa\AaaSpecTests.cs" />
59+
<Compile Include="Aaa\Examples\MyComponent.cs" />
60+
<Compile Include="Aaa\Examples\MyComponentTests.cs" />
5961
<Compile Include="Aaa\Internal\AaaTestHostTests.cs" />
6062
<Compile Include="Bdd\BddSpecTests.cs" />
6163
<Compile Include="Bdd\Internal\BddTestHostTests.cs" />
@@ -100,12 +102,18 @@
100102
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers">
101103
<Version>2.6.0</Version>
102104
</PackageReference>
105+
<PackageReference Include="Microsoft.NET.Test.Sdk">
106+
<Version>15.7.2</Version>
107+
</PackageReference>
103108
<PackageReference Include="moq">
104109
<Version>4.8.2</Version>
105110
</PackageReference>
106111
<PackageReference Include="nunit">
107112
<Version>3.9.0</Version>
108113
</PackageReference>
114+
<PackageReference Include="NUnit3TestAdapter">
115+
<Version>3.10.0</Version>
116+
</PackageReference>
109117
<PackageReference Include="RoslynSecurityGuard">
110118
<Version>2.3.0</Version>
111119
</PackageReference>

Heleonix.Testing.NUnit/Aaa/Internal/AaaTestHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal class AaaTestHost : TestHost
2323
protected override IDictionary<SpecNodeType, SpecStructureRule> SpecStructureRules { get; } =
2424
new Dictionary<SpecNodeType, SpecStructureRule>
2525
{
26-
{ SpecNodeType.When, new SpecStructureRule("^$", "^(Arrange)|^(Act)|^(Teardown)|^$") },
26+
{ SpecNodeType.When, new SpecStructureRule("^$", "^(Arrange)|^(Act)|^(Teardown)|^(When)|^$") },
2727
{
2828
SpecNodeType.And, new SpecStructureRule(
2929
"^(And,)*(When)",

README.md

Lines changed: 100 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,122 @@ https://www.nuget.org/packages/Heleonix.Testing.NUnit
1111
using Heleonix.Testing.NUnit.Aaa;
1212
using static Heleonix.Testing.NUnit.Aaa.AaaSpec;
1313

14-
[ComponentTest(Type = typeof(Component))]
15-
public static class ComponentTests
14+
/// <summary>
15+
/// Tests the <see cref="MyComponent"/>.
16+
/// </summary>
17+
[ComponentTest(Type = typeof(MyComponent))]
18+
public static class MyComponentTests
1619
{
17-
[MemberTest(Name = nameof(Component.Member))]
18-
public static void Member()
20+
/// <summary>
21+
/// Tests the <see cref="MyComponent.Member1"/>.
22+
/// </summary>
23+
[MemberTest(Name = nameof(MyComponent.Member1))]
24+
public static void Member1()
1925
{
20-
Arrange(() => { });
26+
Arrange(() =>
27+
{
28+
});
29+
30+
Act(() =>
31+
{
32+
});
33+
34+
Teardown(() =>
35+
{
36+
});
2137

22-
Act(() => { });
38+
When("the condition #1 is true", () =>
39+
{
40+
Arrange(() =>
41+
{
42+
});
43+
44+
Act(() =>
45+
{
46+
});
2347

24-
Teardown(() => { });
48+
Teardown(() =>
49+
{
50+
});
51+
52+
Should("lead to the result #1", () =>
53+
{
54+
});
55+
});
56+
57+
When("the condition #2 is true", () =>
58+
{
59+
Arrange(() =>
60+
{
61+
});
62+
63+
Act(() =>
64+
{
65+
});
66+
67+
Teardown(() =>
68+
{
69+
});
70+
71+
Should("lead to the result #2", () =>
72+
{
73+
});
74+
});
75+
}
76+
77+
/// <summary>
78+
/// Tests the <see cref="MyComponent.Member2"/>.
79+
/// </summary>
80+
[MemberTest(Name = nameof(MyComponent.Member2))]
81+
public static void Member2()
82+
{
83+
Arrange(() =>
84+
{
85+
});
86+
87+
Act(() =>
88+
{
89+
});
90+
91+
Teardown(() =>
92+
{
93+
});
2594

2695
When("the action #1 is executed", () =>
2796
{
28-
Arrange(() => { });
97+
Arrange(() =>
98+
{
99+
});
29100

30-
Act(() => { });
101+
Act(() =>
102+
{
103+
});
31104

32-
Teardown(() => { });
105+
Teardown(() =>
106+
{
107+
});
33108

34-
Should("lead to the result #1", () => { });
109+
Should("lead to the result #1", () =>
110+
{
111+
});
35112

36113
And("the condition #1 is true", () =>
37114
{
38-
Arrange(() => { });
115+
Arrange(() =>
116+
{
117+
});
39118

40-
Act(() => { });
119+
Act(() =>
120+
{
121+
});
41122

42-
Teardown(() => { });
123+
Teardown(() =>
124+
{
125+
});
43126

44-
Should("lead to the result #2", () => { });
127+
Should("lead to the result #2", () =>
128+
{
129+
});
45130
});
46131
});
47132
}

0 commit comments

Comments
 (0)