From 0eca3c27cb6e19b2fb16afcae9a646c66499793e Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 1 Nov 2024 21:30:40 +1100 Subject: [PATCH] Make combinations respect Recording.Pause (#1339) * make-combinations-respect-pause * Update Directory.Build.props --- src/Directory.Build.props | 2 +- ...ationTests.RecordingPausedTest.verified.txt | 18 ++++++++++++++++++ src/Verify.Tests/CombinationTests.cs | 16 ++++++++++++++++ src/Verify/Combinations/CombinationRunner.cs | 7 ++++++- src/Verify/Recording/Recording.cs | 7 +++++++ 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/Verify.Tests/CombinationTests.RecordingPausedTest.verified.txt diff --git a/src/Directory.Build.props b/src/Directory.Build.props index c1a33bea9..cc4eca3d0 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,7 +2,7 @@ CS1591;CS0649;xUnit1026;xUnit1013;CS1573;VerifyTestsProjectDir;VerifySetParameters;PolyFillTargetsForNuget - 28.1.1 + 28.1.2 enable preview 1.0.0 diff --git a/src/Verify.Tests/CombinationTests.RecordingPausedTest.verified.txt b/src/Verify.Tests/CombinationTests.RecordingPausedTest.verified.txt new file mode 100644 index 000000000..4a5be2c59 --- /dev/null +++ b/src/Verify.Tests/CombinationTests.RecordingPausedTest.verified.txt @@ -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 + } +} \ No newline at end of file diff --git a/src/Verify.Tests/CombinationTests.cs b/src/Verify.Tests/CombinationTests.cs index 227fea81f..874921efb 100644 --- a/src/Verify.Tests/CombinationTests.cs +++ b/src/Verify.Tests/CombinationTests.cs @@ -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); + } } \ No newline at end of file diff --git a/src/Verify/Combinations/CombinationRunner.cs b/src/Verify/Combinations/CombinationRunner.cs index c3efd9f2e..d78bcd2a5 100644 --- a/src/Verify/Combinations/CombinationRunner.cs +++ b/src/Verify/Combinations/CombinationRunner.cs @@ -17,11 +17,16 @@ Task RunWithReturn(Func> 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); diff --git a/src/Verify/Recording/Recording.cs b/src/Verify/Recording/Recording.cs index 9ec28ebc7..78cf6d9cb 100644 --- a/src/Verify/Recording/Recording.cs +++ b/src/Verify/Recording/Recording.cs @@ -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();