Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
[Akka.TestKit] TestKitBase should take arbitrary ActorSystem without …
…throwing (#6092)

(cherry picked from commit 015de37)
  • Loading branch information
Arkatufus committed Sep 13, 2022
commit 77b94d59b42bff5825d4788fa116a3322147d403
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