Skip to content

Commit

Permalink
[Akka.TestKit] TestKitBase should take arbitrary ActorSystem without …
Browse files Browse the repository at this point in the history
…throwing (#6092) (#6094)

(cherry picked from commit 015de37)
  • Loading branch information
Arkatufus authored Sep 14, 2022
1 parent 63639b9 commit e2b1d73
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/core/Akka.TestKit.Tests/TestKitSpec.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// -----------------------------------------------------------------------
// <copyright file="TestKitSpec.cs" company="Akka.NET Project">
// Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2022 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------

using Akka.Actor;
using Akka.Actor.Dsl;
using Akka.Configuration;
using Xunit;
using Xunit.Abstractions;
using FluentAssertions;
using static FluentAssertions.FluentActions;

namespace Akka.TestKit.Tests
{
public class TestKitSpec
{
private readonly ITestOutputHelper _output;

public TestKitSpec(ITestOutputHelper output)
{
_output = output;
}

[Fact(DisplayName = "TestKit should accept arbitrary ActorSystem")]
public void TestKitBaseTest()
{
using (var sys = ActorSystem.Create(nameof(TestKitSpec)))
{
var testkit = new TestKit.Xunit2.TestKit(sys, _output);
var echoActor = testkit.Sys.ActorOf(c => c.ReceiveAny((m, ctx) => testkit.TestActor.Tell(m)));
Invoking(() =>
{
echoActor.Tell("message");
var message = testkit.ExpectMsg<string>();
message.Should().Be("message");
}).Should().NotThrow<ConfigurationException>();
}
}

[Fact(DisplayName = "TestKit should accept ActorSystem with TestKit.DefaultConfig")]
public void TestKitConfigTest()
{
using (var sys = ActorSystem.Create(nameof(TestKitSpec), TestKit.Xunit2.TestKit.DefaultConfig))
{
var testkit = new TestKit.Xunit2.TestKit(sys, _output);
var echoActor = testkit.Sys.ActorOf(c => c.ReceiveAny((m, ctx) => testkit.TestActor.Tell(m)));
Invoking(() =>
{
echoActor.Tell("message");
var message = testkit.ExpectMsg<string>();
message.Should().Be("message");
}).Should().NotThrow<ConfigurationException>();
}
}
}
}
4 changes: 4 additions & 0 deletions src/core/Akka.TestKit/TestKitBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ protected virtual void InitializeTest(ActorSystem system, ActorSystemSetup confi
}
system = ActorSystem.Create(actorSystemName ?? "test", config.WithSetup(newBootstrap));
}
else
{
system.Settings.InjectTopLevelFallback(_defaultConfig);
}

_testState.System = system;

Expand Down

0 comments on commit e2b1d73

Please sign in to comment.