Skip to content

Commit

Permalink
Added support of sequential When in AAA.
Browse files Browse the repository at this point in the history
  • Loading branch information
hennadiilu committed Jun 30, 2018
1 parent 1d3f716 commit 6f6b6c4
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 52 deletions.
Binary file modified Docs/images/AAA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 0 additions & 35 deletions Heleonix.Testing.NUnit.Tests/Aaa/AaaSpecTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,40 +250,5 @@ public static void When()
Assert.That(node.NestingLevel, Is.EqualTo(0));
Assert.That(node.Parent, Is.EqualTo(rootNode));
}

/// <summary>
/// Tests integration of specs.
/// </summary>
[MemberTest(Name = nameof(Example))]
public static void Example()
{
AaaSpec.Arrange(() => { });

AaaSpec.Act(() => { });

AaaSpec.Teardown(() => { });

AaaSpec.When("When 1", () =>
{
AaaSpec.Arrange(() => { });

AaaSpec.Act(() => { });

AaaSpec.Teardown(() => { });

AaaSpec.Should("Should 1", () => { });

AaaSpec.And("And 1", () =>
{
AaaSpec.Arrange(() => { });

AaaSpec.Act(() => { });

AaaSpec.Teardown(() => { });

AaaSpec.Should("Should 2", () => { });
});
});
}
}
}
29 changes: 29 additions & 0 deletions Heleonix.Testing.NUnit.Tests/Aaa/Examples/MyComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// <copyright file="MyComponent.cs" company="Heleonix - Hennadii Lutsyshyn">
// Copyright (c) 2018-present Heleonix - Hennadii Lutsyshyn. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the repository root for full license information.
// </copyright>

namespace Heleonix.Testing.NUnit.Tests.Aaa.Examples
{
/// <summary>
/// Dummy component.
/// </summary>
public static class MyComponent
{
/// <summary>
/// Dummy member.
/// </summary>
public static void Member1()
{
// Dummy member.
}

/// <summary>
/// Dummy member.
/// </summary>
public static void Member2()
{
// Dummy member.
}
}
}
131 changes: 131 additions & 0 deletions Heleonix.Testing.NUnit.Tests/Aaa/Examples/MyComponentTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// <copyright file="MyComponentTests.cs" company="Heleonix - Hennadii Lutsyshyn">
// Copyright (c) 2018-present Heleonix - Hennadii Lutsyshyn. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the repository root for full license information.
// </copyright>

namespace Heleonix.Testing.NUnit.Tests.Aaa.Examples
{
using Heleonix.Testing.NUnit.Aaa;
using static Heleonix.Testing.NUnit.Aaa.AaaSpec;

/// <summary>
/// Tests the <see cref="MyComponent"/>.
/// </summary>
[ComponentTest(Type = typeof(MyComponent))]
public static class MyComponentTests
{
/// <summary>
/// Tests the <see cref="MyComponent.Member1"/>.
/// </summary>
[MemberTest(Name = nameof(MyComponent.Member1))]
public static void Member1()
{
Arrange(() =>
{
});

Act(() =>
{
});

Teardown(() =>
{
});

When("the condition #1 is true", () =>
{
Arrange(() =>
{
});

Act(() =>
{
});

Teardown(() =>
{
});

Should("lead to the result #1", () =>
{
});
});

When("the condition #2 is true", () =>
{
Arrange(() =>
{
});

Act(() =>
{
});

Teardown(() =>
{
});

Should("lead to the result #2", () =>
{
});
});
}

/// <summary>
/// Tests the <see cref="MyComponent.Member2"/>.
/// </summary>
[MemberTest(Name = nameof(MyComponent.Member2))]
public static void Member2()
{
Arrange(() =>
{
});

Act(() =>
{
});

Teardown(() =>
{
});

When("the action #1 is executed", () =>
{
Arrange(() =>
{
});

Act(() =>
{
});

Teardown(() =>
{
});

Should("lead to the result #1", () =>
{
});

And("the condition #1 is true", () =>
{
Arrange(() =>
{
});

Act(() =>
{
});

Teardown(() =>
{
});

Should("lead to the result #2", () =>
{
});
});
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void SpecStructureRules()

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

Assert.That(rules[SpecNodeType.And].SpecExecutionStackRule, Is.EqualTo("^(And,)*(When)"));
Assert.That(rules[SpecNodeType.And].PredecessorsRule, Is.EqualTo("^(Arrange)|^(Act)|^(Should)|^(Teardown)|^(And)|^$"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Aaa\AaaSpecTests.cs" />
<Compile Include="Aaa\Examples\MyComponent.cs" />
<Compile Include="Aaa\Examples\MyComponentTests.cs" />
<Compile Include="Aaa\Internal\AaaTestHostTests.cs" />
<Compile Include="Bdd\BddSpecTests.cs" />
<Compile Include="Bdd\Internal\BddTestHostTests.cs" />
Expand Down Expand Up @@ -100,12 +102,18 @@
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers">
<Version>2.6.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk">
<Version>15.7.2</Version>
</PackageReference>
<PackageReference Include="moq">
<Version>4.8.2</Version>
</PackageReference>
<PackageReference Include="nunit">
<Version>3.9.0</Version>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter">
<Version>3.10.0</Version>
</PackageReference>
<PackageReference Include="RoslynSecurityGuard">
<Version>2.3.0</Version>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion Heleonix.Testing.NUnit/Aaa/Internal/AaaTestHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class AaaTestHost : TestHost
protected override IDictionary<SpecNodeType, SpecStructureRule> SpecStructureRules { get; } =
new Dictionary<SpecNodeType, SpecStructureRule>
{
{ SpecNodeType.When, new SpecStructureRule("^$", "^(Arrange)|^(Act)|^(Teardown)|^$") },
{ SpecNodeType.When, new SpecStructureRule("^$", "^(Arrange)|^(Act)|^(Teardown)|^(When)|^$") },
{
SpecNodeType.And, new SpecStructureRule(
"^(And,)*(When)",
Expand Down
115 changes: 100 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,122 @@ https://www.nuget.org/packages/Heleonix.Testing.NUnit
using Heleonix.Testing.NUnit.Aaa;
using static Heleonix.Testing.NUnit.Aaa.AaaSpec;

[ComponentTest(Type = typeof(Component))]
public static class ComponentTests
/// <summary>
/// Tests the <see cref="MyComponent"/>.
/// </summary>
[ComponentTest(Type = typeof(MyComponent))]
public static class MyComponentTests
{
[MemberTest(Name = nameof(Component.Member))]
public static void Member()
/// <summary>
/// Tests the <see cref="MyComponent.Member1"/>.
/// </summary>
[MemberTest(Name = nameof(MyComponent.Member1))]
public static void Member1()
{
Arrange(() => { });
Arrange(() =>
{
});

Act(() =>
{
});

Teardown(() =>
{
});

Act(() => { });
When("the condition #1 is true", () =>
{
Arrange(() =>
{
});

Act(() =>
{
});

Teardown(() => { });
Teardown(() =>
{
});

Should("lead to the result #1", () =>
{
});
});

When("the condition #2 is true", () =>
{
Arrange(() =>
{
});

Act(() =>
{
});

Teardown(() =>
{
});

Should("lead to the result #2", () =>
{
});
});
}

/// <summary>
/// Tests the <see cref="MyComponent.Member2"/>.
/// </summary>
[MemberTest(Name = nameof(MyComponent.Member2))]
public static void Member2()
{
Arrange(() =>
{
});

Act(() =>
{
});

Teardown(() =>
{
});

When("the action #1 is executed", () =>
{
Arrange(() => { });
Arrange(() =>
{
});

Act(() => { });
Act(() =>
{
});

Teardown(() => { });
Teardown(() =>
{
});

Should("lead to the result #1", () => { });
Should("lead to the result #1", () =>
{
});

And("the condition #1 is true", () =>
{
Arrange(() => { });
Arrange(() =>
{
});

Act(() => { });
Act(() =>
{
});

Teardown(() => { });
Teardown(() =>
{
});

Should("lead to the result #2", () => { });
Should("lead to the result #2", () =>
{
});
});
});
}
Expand Down

0 comments on commit 6f6b6c4

Please sign in to comment.