Skip to content

Commit 7d9c0b5

Browse files
committed
Add ReqnrollPlugins.xRetry sample project
1 parent c426fbf commit 7d9c0b5

File tree

7 files changed

+148
-0
lines changed

7 files changed

+148
-0
lines changed

ReqnrollPlugins/ReqnrollPlugins.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReqnrollPlugins.OldBoDi", "
1313
EndProject
1414
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReqnrollPlugins.Verify", "ReqnrollPlugins.Verify\ReqnrollPlugins.Verify.csproj", "{7683F7AD-5D0C-47A0-A890-B922E5FA438A}"
1515
EndProject
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReqnrollPlugins.xRetry", "ReqnrollPlugins.xRetry\ReqnrollPlugins.xRetry.csproj", "{DC7F1E57-11B7-431C-9604-CDB71CE11370}"
17+
EndProject
1618
Global
1719
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1820
Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,10 @@ Global
3941
{7683F7AD-5D0C-47A0-A890-B922E5FA438A}.Debug|Any CPU.Build.0 = Debug|Any CPU
4042
{7683F7AD-5D0C-47A0-A890-B922E5FA438A}.Release|Any CPU.ActiveCfg = Release|Any CPU
4143
{7683F7AD-5D0C-47A0-A890-B922E5FA438A}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{DC7F1E57-11B7-431C-9604-CDB71CE11370}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{DC7F1E57-11B7-431C-9604-CDB71CE11370}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{DC7F1E57-11B7-431C-9604-CDB71CE11370}.Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{DC7F1E57-11B7-431C-9604-CDB71CE11370}.Release|Any CPU.Build.0 = Release|Any CPU
4248
EndGlobalSection
4349
GlobalSection(SolutionProperties) = preSolution
4450
HideSolutionNode = FALSE
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Feature: Calculator
2+
3+
Run tests with
4+
dotnet test --logger "console;verbosity=detailed"
5+
to see retries.
6+
7+
@retry
8+
Scenario: Add two numbers
9+
Given the first number is 50
10+
And the second number is 70
11+
When the two numbers are added
12+
Then the result should be around 120
13+
14+
@retry
15+
Scenario Outline: Multiply two numbers
16+
Given the first number is 5
17+
And the second number is 7
18+
When the two numbers are multiplied
19+
Then the result should be around 35
20+
Examples:
21+
| a | b | result |
22+
| 5 | 7 | 35 |
23+
| 2 | 3 | 6 |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
global using Xunit;
2+
global using Reqnroll;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<LangVersion>latest</LangVersion>
8+
<RootNamespace>ReqnrollPlugins.XRetryPlugin</RootNamespace>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
13+
<PackageReference Include="Reqnroll.xUnit" Version="2.2.0-local" />
14+
<PackageReference Include="xRetry.Reqnroll" Version="1.0.0" />
15+
<PackageReference Include="xunit" Version="2.9.0" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<ProjectReference Include="..\CalculatorApp\CalculatorApp.csproj" />
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<None Update="xunit.runner.json">
28+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
29+
</None>
30+
</ItemGroup>
31+
32+
</Project>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using CalculatorApp;
2+
using ReqnrollPlugins.XRetryPlugin.Support;
3+
using System.Collections;
4+
5+
namespace ReqnrollPlugins.XRetryPlugin.StepDefinitions;
6+
7+
[Binding]
8+
public sealed class CalculatorStepDefinitions
9+
{
10+
private readonly ScenarioContext _scenarioContext;
11+
private readonly ICalculator _calculator;
12+
13+
public CalculatorStepDefinitions(ScenarioContext scenarioContext)
14+
{
15+
_scenarioContext = scenarioContext;
16+
_calculator = new Calculator(new TestCalculatorConfiguration());
17+
}
18+
19+
[Given("the first number is {int}")]
20+
public void GivenTheFirstNumberIs(int number)
21+
{
22+
_calculator.Reset();
23+
_calculator.Enter(number);
24+
}
25+
26+
[Given("the second number is {int}")]
27+
public void GivenTheSecondNumberIs(int number)
28+
{
29+
_calculator.Enter(number);
30+
}
31+
32+
[When("the two numbers are added")]
33+
public void WhenTheTwoNumbersAreAdded()
34+
{
35+
_calculator.Add();
36+
}
37+
38+
[When("the two numbers are multiplied")]
39+
public void WhenTheTwoNumbersAreMultiplied()
40+
{
41+
_calculator.Multiply();
42+
}
43+
44+
[Then("the result should be {int}")]
45+
public void ThenTheResultShouldBe(int result)
46+
{
47+
Assert.Equal(result, _calculator.GetResult());
48+
}
49+
50+
private const int RetryCount = 3;
51+
private static readonly Dictionary<string, int> RemainingRetries = new();
52+
53+
private string GetScenarioTitle(ScenarioContext scenarioContext)
54+
{
55+
if (scenarioContext.ScenarioInfo.Arguments == null || scenarioContext.ScenarioInfo.Arguments.Count == 0)
56+
return scenarioContext.ScenarioInfo.Title;
57+
58+
return $"{scenarioContext.ScenarioInfo.Title} / {string.Join(",", scenarioContext.ScenarioInfo.Arguments.OfType<DictionaryEntry>().Select(a => a.Value))}";
59+
}
60+
61+
[Then("the result should be around {int}")]
62+
public void ThenTheResultShouldBeAround(int result)
63+
{
64+
var scenarioTitle = GetScenarioTitle(_scenarioContext);
65+
if (!RemainingRetries.TryGetValue(scenarioTitle, out var remainingRetries))
66+
{
67+
remainingRetries = RetryCount;
68+
}
69+
result -= (--remainingRetries);
70+
RemainingRetries[scenarioTitle] = remainingRetries;
71+
Assert.Equal(result, _calculator.GetResult());
72+
}
73+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using CalculatorApp;
2+
3+
namespace ReqnrollPlugins.XRetryPlugin.Support;
4+
5+
internal class TestCalculatorConfiguration : ICalculatorConfiguration
6+
{
7+
public bool AllowMultiply => true;
8+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
3+
"diagnosticMessages": true
4+
}

0 commit comments

Comments
 (0)