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 (akkadotnet#6092)
  • Loading branch information
Arkatufus authored Sep 13, 2022
1 parent 3b4ed91 commit 015de37
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 @@ -149,6 +149,10 @@ protected void InitializeTest(ActorSystem system, ActorSystemSetup config, strin
}
system = ActorSystem.Create(actorSystemName ?? "test", config.WithSetup(newBootstrap));
}
else
{
system.Settings.InjectTopLevelFallback(_defaultConfig);
}

_testState.System = system;

Expand Down

0 comments on commit 015de37

Please sign in to comment.