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

Convert Akka.TestKit.Tests.TestKitBaseTests.AwaitAssertTests to async #5870

Merged
Changes from 2 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
42 changes: 35 additions & 7 deletions src/core/Akka.TestKit.Tests/TestKitBaseTests/AwaitAssertTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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<EqualException>(() =>
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<EqualException>();
});
}

[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<EqualException>();
});
}
}
Expand Down