Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make combinations respect Recording.Pause #1339

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading