-
Notifications
You must be signed in to change notification settings - Fork 17
Add MS Test support to Akka.Hosting.TestKit #432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jaydeboer
wants to merge
3
commits into
akkadotnet:dev
Choose a base branch
from
jaydeboer:feature/add-mstest-support
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/Akka.Hosting.TestKit.MsTest.Tests/Akka.Hosting.TestKit.MsTest.Tests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(TestsNetCoreFramework)</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" /> | ||
<PackageReference Include="FluentAssertions" Version="6.12.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="3.2.1" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="$(MsTestVersion)" /> | ||
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="$(MicrosoftTestPlatformTestHostVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Akka.Hosting.TestKit.MsTest\Akka.Hosting.TestKit.MsTest.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="DiPropsFailTest.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using Akka.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Akka.Hosting.TestKit.MsTest.Tests; | ||
|
||
// Regression test for https://github.com/akkadotnet/Akka.Hosting/issues/343 | ||
|
||
[TestClass] | ||
public class DiPropsFailTest: TestKit | ||
{ | ||
public DiPropsFailTest() : base(nameof(DiPropsFailTest)) | ||
{} | ||
|
||
protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider) | ||
{ } | ||
|
||
[TestMethod] | ||
public void DiTest() | ||
{ | ||
var actor = Sys.ActorOf(NonRootActorWithDi.Props()); | ||
actor.Tell("test"); | ||
ExpectMsg<string>("test"); | ||
} | ||
|
||
private class NonRootActorWithDi: ReceiveActor | ||
{ | ||
public static Props Props() => DependencyResolver.For(Context.System).Props<NonRootActorWithDi>(); | ||
|
||
public NonRootActorWithDi(ILogger<NonRootActorWithDi> log) | ||
{ | ||
ReceiveAny(msg => | ||
{ | ||
log.LogInformation("Received {Msg}", msg); | ||
Sender.Tell(msg); | ||
}); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
global using Akka.Actor; | ||
global using FluentAssertions; | ||
global using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
global using System; | ||
global using System.Collections; | ||
global using System.Threading.Tasks; | ||
global using static FluentAssertions.FluentActions; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="HostingSpecSpec.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.Event; | ||
using LogLevel = Microsoft.Extensions.Logging.LogLevel; | ||
|
||
namespace Akka.Hosting.TestKit.MsTest.Tests; | ||
|
||
[TestClass] | ||
public class HostingSpecSpec: TestKit | ||
{ | ||
private enum Echo | ||
{ } | ||
|
||
public HostingSpecSpec() | ||
: base(nameof(HostingSpecSpec), logLevel: LogLevel.Debug) | ||
{ | ||
} | ||
|
||
protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider) | ||
{ | ||
builder.WithActors((system, registry) => | ||
{ | ||
var echo = system.ActorOf(Props.Create(() => new SimpleEchoActor())); | ||
registry.Register<Echo>(echo); | ||
}); | ||
} | ||
|
||
[TestMethod] | ||
public void ActorTest() | ||
{ | ||
var echo = ActorRegistry.Get<Echo>(); | ||
var probe = CreateTestProbe(); | ||
|
||
echo.Tell("TestMessage", probe); | ||
var msg = probe.ExpectMsg("TestMessage"); | ||
Log.Info(msg); | ||
} | ||
|
||
private class SimpleEchoActor : ReceiveActor | ||
{ | ||
public SimpleEchoActor() | ||
{ | ||
var log = Context.GetLogger(); | ||
|
||
ReceiveAny(msg => | ||
{ | ||
log.Info($"Received {msg}"); | ||
Sender.Tell(msg); | ||
}); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="LoggerSpec.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.Event; | ||
using Akka.Hosting.TestKit.Internals; | ||
using LogLevel = Microsoft.Extensions.Logging.LogLevel; | ||
|
||
namespace Akka.Hosting.TestKit.MsTest.Tests; | ||
|
||
[TestClass] | ||
public class LoggerSpec: TestKit | ||
{ | ||
protected override bool ShouldUseCustomLogger => true; | ||
|
||
public LoggerSpec(): base(logLevel: LogLevel.Debug) | ||
{ | ||
} | ||
|
||
protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider) | ||
{ | ||
} | ||
|
||
protected override async Task LoggerHook(ActorSystem system, IActorRegistry registry) | ||
{ | ||
var extSystem = (ExtendedActorSystem)system; | ||
var logger = extSystem.SystemActorOf(Props.Create(() => new MockLogger()), "log-test"); | ||
registry.Register<MockLogger>(logger); | ||
await logger.Ask<LoggerInitialized>(new InitializeLogger(system.EventStream)); | ||
} | ||
|
||
[TestMethod(displayName: "TestKit ILoggerFactory logger should log messages")] | ||
public void TestKitLoggerFactoryLoggerTest() | ||
{ | ||
var loggerActor = ActorRegistry.Get<MockLogger>(); | ||
loggerActor.Tell(TestActor); | ||
|
||
var logger = Event.Logging.GetLogger(Sys, "log-test"); | ||
|
||
logger.Debug("debug"); | ||
ExpectMsg<Debug>(i => i.Message.ToString() == "debug"); | ||
|
||
logger.Info("info"); | ||
ExpectMsg<Info>(i => i.Message.ToString() == "info"); | ||
|
||
logger.Warning("warn"); | ||
ExpectMsg<Warning>(i => i.Message.ToString() == "warn"); | ||
|
||
logger.Error("err"); | ||
ExpectMsg<Error>(i => i.Message.ToString() == "err"); | ||
} | ||
|
||
private class MockLogger: TestKitLoggerFactoryLogger | ||
{ | ||
private IActorRef? _probe; | ||
|
||
protected override bool Receive(object message) | ||
{ | ||
switch (message) | ||
{ | ||
case IActorRef actor: | ||
_probe = actor; | ||
return true; | ||
default: | ||
return base.Receive(message); | ||
} | ||
} | ||
|
||
protected override void Log(LogEvent log, ActorPath path) | ||
{ | ||
if(log.LogSource.StartsWith("log-test")) | ||
_probe.Tell(log); | ||
base.Log(log, path); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/Akka.Hosting.TestKit.MsTest.Tests/Properties/AssemblyInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="AssemblyInfo.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2009-2021 Lightbend Inc. <http://www.lightbend.com> | ||
// Copyright (C) 2013-2021 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("b21496c0-a536-4953-9253-d2d0d526e42d")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is causing one of the test failures, I am not sure what this is doing, or where to start on a fix so any direction would be very much appreciated.