Skip to content

Commit 7e48e35

Browse files
authored
Added InverseFishForMessage and nuget package fluent-assertertions (#5430)
1 parent a9859db commit 7e48e35

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/core/Akka.TestKit/Akka.TestKit.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<ItemGroup>
1313
<EmbeddedResource Include="Configs\TestScheduler.conf;Internal\Reference.conf" />
14+
<PackageReference Include="FluentAssertions" Version="5.10.3" />
1415
<ProjectReference Include="..\Akka\Akka.csproj" />
1516
</ItemGroup>
1617

src/core/Akka.TestKit/TestKitBase_Receive.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
using System.Collections.Generic;
1010
using System.Linq;
1111
using System.Threading;
12+
using System.Threading.Tasks;
1213
using Akka.TestKit.Internal;
14+
using FluentAssertions;
1315

1416
namespace Akka.TestKit
1517
{
@@ -56,6 +58,23 @@ public T FishForMessage<T>(Predicate<T> isMessage, TimeSpan? max = null, string
5658
}
5759
}
5860

61+
/// <summary>
62+
/// Receives messages until <paramref name="max"/>. Ignores all messages except for a message of type <typeparamref name="T"/>. Asserts that all messages are not of the of type <typeparamref name="T"/>. Note that when comparing types, inheritance is ignored, in other words, only perfectly matching types are asserted.
63+
/// </summary>
64+
/// <typeparam name="T">The type that the message is not supposed to be.</typeparam>
65+
/// <param name="probe"></param>
66+
/// <param name="max"></param>
67+
public async static Task InverseFishForMessage<T>(TestProbe probe, TimeSpan? max = null)
68+
{
69+
await Task.Run(() =>
70+
{
71+
probe.ReceiveWhile<object>(max: max, shouldIgnore: x =>
72+
{
73+
x.Should().NotBeOfType<T>();
74+
return false; // we are not returning anything
75+
});
76+
});
77+
}
5978

6079
/// <summary>
6180
/// Receive one message from the internal queue of the TestActor.

0 commit comments

Comments
 (0)