Skip to content

Commit

Permalink
Make combinations respect Recording.Pause (#1339)
Browse files Browse the repository at this point in the history
* make-combinations-respect-pause

* Update Directory.Build.props
  • Loading branch information
SimonCropp authored Nov 1, 2024
1 parent 63b9aee commit 0eca3c2
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649;xUnit1026;xUnit1013;CS1573;VerifyTestsProjectDir;VerifySetParameters;PolyFillTargetsForNuget</NoWarn>
<Version>28.1.1</Version>
<Version>28.1.2</Version>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
Expand Down
18 changes: 18 additions & 0 deletions src/Verify.Tests/CombinationTests.RecordingPausedTest.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
1, Smith St : {
target: 1 Smith St,
key: recorded 1 Smith St
},
1, Wallace St: {
target: 1 Wallace St,
key: recorded 1 Wallace St
},
10, Smith St : {
target: 10 Smith St,
key: recorded 10 Smith St
},
10, Wallace St: {
target: 10 Wallace St,
key: recorded 10 Wallace St
}
}
16 changes: 16 additions & 0 deletions src/Verify.Tests/CombinationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,20 @@ public Task RecordingTest()
params1,
params2);
}

[Fact]
public Task RecordingPausedTest()
{
Recording.Start();
return Combination()
.Verify(
(param1, param2) =>
{
Recording.Add("key", $"recorded {param1} {param2}");
Recording.Pause();
return SimpleReturnMethod(param1, param2);
},
params1,
params2);
}
}
7 changes: 6 additions & 1 deletion src/Verify/Combinations/CombinationRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ Task<CombinationResults> RunWithReturn<TReturn>(Func<object?[], Task<TReturn>> m
InnerRun(async keys =>
{
object? value = await method(keys);
if (Recording.IsRecording())
var paused = Recording.IsPaused();
if (Recording.IsRecording() || paused)
{
var appends = Recording.Values().ToList();
value = new InfoBuilder(value, appends);
Recording.Clear();
if (paused)
{
Recording.Resume();
}
}
return (CombinationResult.ForValue(keys, value), value);
Expand Down
7 changes: 7 additions & 0 deletions src/Verify/Recording/Recording.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ public static void Pause() =>
CurrentState()
.Pause();

public static bool IsPaused()
{
var value = asyncLocal.Value;

return value is {Paused: true};
}

public static void TryPause() =>
asyncLocal.Value?.Pause();

Expand Down

0 comments on commit 0eca3c2

Please sign in to comment.