diff --git a/src/core/Akka.TestKit.Tests/TestKitBaseTests/AwaitAssertTests.cs b/src/core/Akka.TestKit.Tests/TestKitBaseTests/AwaitAssertTests.cs index fea3bfb7084..fa3b66a5499 100644 --- a/src/core/Akka.TestKit.Tests/TestKitBaseTests/AwaitAssertTests.cs +++ b/src/core/Akka.TestKit.Tests/TestKitBaseTests/AwaitAssertTests.cs @@ -6,10 +6,13 @@ //----------------------------------------------------------------------- using System; +using System.Threading.Tasks; +using FluentAssertions; using Xunit; using Xunit.Sdk; +using static FluentAssertions.FluentActions; -namespace Akka.TestKit.Tests.Xunit2.TestKitBaseTests +namespace Akka.TestKit.Tests.TestKitBaseTests { public class AwaitAssertTests : TestKit.Xunit2.TestKit { @@ -18,18 +21,43 @@ public AwaitAssertTests() : base("akka.test.timefactor=2") } [Fact] - public void AwaitAssert_must_not_throw_any_exception_when_assertion_is_valid() + public async Task AwaitAssertAsync_must_not_throw_any_exception_when_assertion_is_valid() { - AwaitAssert(() => Assert.Equal("foo", "foo")); + await AwaitAssertAsync(() => Assert.Equal("foo", "foo")); } [Fact] - public void AwaitAssert_must_throw_exception_when_assertion_is_invalid() + public async Task AwaitAssertAsync_with_async_delegate_must_not_throw_any_exception_when_assertion_is_valid() { - Within(TimeSpan.FromMilliseconds(300), TimeSpan.FromSeconds(1), () => + await AwaitAssertAsync(() => { - Assert.Throws(() => - AwaitAssert(() => Assert.Equal("foo", "bar"), TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(300))); + Assert.Equal("foo", "foo"); + return Task.CompletedTask; + }); + } + + [Fact] + public async Task AwaitAssertAsync_must_throw_exception_when_assertion_is_invalid() + { + await WithinAsync(TimeSpan.FromMilliseconds(300), TimeSpan.FromSeconds(1), async () => + { + await Awaiting(async () => + await AwaitAssertAsync(() => Assert.Equal("foo", "bar"), TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(300))) + .Should().ThrowAsync(); + }); + } + + [Fact] + public async Task AwaitAssertAsync_with_async_delegate_must_throw_exception_when_assertion_is_invalid() + { + await WithinAsync(TimeSpan.FromMilliseconds(300), TimeSpan.FromSeconds(1), async () => + { + await Awaiting(async () => await AwaitAssertAsync(() => + { + Assert.Equal("foo", "bar"); + return Task.CompletedTask; + }, TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(300))) + .Should().ThrowAsync(); }); } }