From 9bb74f1dab785f6933e1201ee3ecf578a81c3e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Gr=C3=BCtzmacher?= <44983012+lg2de@users.noreply.github.com> Date: Sat, 19 Nov 2022 17:23:38 +0100 Subject: [PATCH] New unit test to verify CompleteWithinAsync behaves correctly in an assertion scope (#2033) * Add new unit test to verify #2004 * fix test name --- .../Specialized/TaskOfTAssertionSpecs.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Tests/FluentAssertions.Specs/Specialized/TaskOfTAssertionSpecs.cs b/Tests/FluentAssertions.Specs/Specialized/TaskOfTAssertionSpecs.cs index 4d4c74e796..8e18081243 100644 --- a/Tests/FluentAssertions.Specs/Specialized/TaskOfTAssertionSpecs.cs +++ b/Tests/FluentAssertions.Specs/Specialized/TaskOfTAssertionSpecs.cs @@ -143,6 +143,28 @@ public async Task When_task_completes_late_it_should_fail() await action.Should().ThrowAsync(); } + [Fact] + public async Task When_task_completes_late_it_in_assertion_scope_should_fail() + { + // Arrange + var timer = new FakeClock(); + var taskFactory = new TaskCompletionSource(); + + // Act + Func action = () => + { + Func> func = () => taskFactory.Task; + + using var _ = new AssertionScope(); + return func.Should(timer).CompleteWithinAsync(100.Milliseconds()); + }; + + timer.Complete(); + + // Assert + await action.Should().ThrowAsync(); + } + [Fact] public async Task When_task_consumes_time_in_sync_portion_it_should_fail() {