diff --git a/src/core/Akka.TestKit.Tests/TestKitSpec.cs b/src/core/Akka.TestKit.Tests/TestKitSpec.cs new file mode 100644 index 00000000000..5071af9d7e4 --- /dev/null +++ b/src/core/Akka.TestKit.Tests/TestKitSpec.cs @@ -0,0 +1,59 @@ +// ----------------------------------------------------------------------- +// +// Copyright (C) 2009-2022 Lightbend Inc. +// Copyright (C) 2013-2022 .NET Foundation +// +// ----------------------------------------------------------------------- + +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(); + message.Should().Be("message"); + }).Should().NotThrow(); + } + } + + [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(); + message.Should().Be("message"); + }).Should().NotThrow(); + } + } + } +} \ No newline at end of file diff --git a/src/core/Akka.TestKit/TestKitBase.cs b/src/core/Akka.TestKit/TestKitBase.cs index 0dd2786b423..49f1c86410d 100644 --- a/src/core/Akka.TestKit/TestKitBase.cs +++ b/src/core/Akka.TestKit/TestKitBase.cs @@ -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;