diff --git a/build.cmd b/build.cmd index 0dbcfcd97ac..72661153a67 100644 --- a/build.cmd +++ b/build.cmd @@ -24,10 +24,11 @@ pushd %~dp0 src\.nuget\NuGet.exe update -self -src\.nuget\NuGet.exe install FAKE -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages -ExcludeVersion -Version 4.1.0 +src\.nuget\NuGet.exe install FAKE -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages -ExcludeVersion -Version 4.16.1 src\.nuget\NuGet.exe install xunit.runner.console -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages\FAKE -ExcludeVersion -Version 2.0.0 src\.nuget\NuGet.exe install nunit.runners -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages\FAKE -ExcludeVersion -Version 2.6.4 +src\.nuget\NuGet.exe install NUnit.Console -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages\FAKE -ExcludeVersion -Version 3.0.0 src\.nuget\NuGet.exe install NBench.Runner -OutputDirectory src\packages -ExcludeVersion if not exist src\packages\SourceLink.Fake\tools\SourceLink.fsx ( diff --git a/build.fsx b/build.fsx index 412fd8194a0..c030d60bbff 100644 --- a/build.fsx +++ b/build.fsx @@ -196,6 +196,7 @@ Target "CopyOutput" <| fun _ -> "contrib/dependencyinjection/Akka.DI.TestKit" "contrib/testkits/Akka.TestKit.Xunit" "contrib/testkits/Akka.TestKit.NUnit" + "contrib/testkits/Akka.TestKit.NUnit3" "contrib/testkits/Akka.TestKit.Xunit2" "contrib/serializers/Akka.Serialization.Wire" "contrib/cluster/Akka.Cluster.Tools" @@ -223,9 +224,11 @@ open Fake.Testing Target "RunTests" <| fun _ -> let msTestAssemblies = !! "src/**/bin/Release/Akka.TestKit.VsTest.Tests.dll" let nunitTestAssemblies = !! "src/**/bin/Release/Akka.TestKit.NUnit.Tests.dll" + let nunit3TestAssemblies = !! "src/**/bin/Release/Akka.TestKit.NUnit3.Tests.dll" let xunitTestAssemblies = !! "src/**/bin/Release/*.Tests.dll" -- "src/**/bin/Release/Akka.TestKit.VsTest.Tests.dll" -- - "src/**/bin/Release/Akka.TestKit.NUnit.Tests.dll" + "src/**/bin/Release/Akka.TestKit.NUnit.Tests.dll" -- + "src/**/bin/Release/Akka.TestKit.NUnit3.Tests.dll" mkdir testOutput @@ -236,6 +239,12 @@ Target "RunTests" <| fun _ -> DisableShadowCopy = true; OutputFile = testOutput + @"\NUnitTestResults.xml"}) + nunit3TestAssemblies + |> NUnit3 (fun p -> + {p with + ShadowCopy = false; + ResultSpecs = [(testOutput + @"\NUnit3TestResults.xml")]}) + let xunitToolPath = findToolInSubPath "xunit.console.exe" "src/packages/xunit.runner.console*/tools" printfn "Using XUnit runner: %s" xunitToolPath xUnit2 diff --git a/src/Akka.sln b/src/Akka.sln index 6fa28a6e1e5..7481020d51f 100644 --- a/src/Akka.sln +++ b/src/Akka.sln @@ -1,7 +1,5 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.40629.0 # Visual Studio 14 VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 @@ -263,6 +261,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Logger.CommonLogging", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.API.Tests", "core\Akka.API.Tests\Akka.API.Tests.csproj", "{F72BE71A-2BE3-413D-A3D9-C7FDBB4E5F08}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.TestKit.NUnit3", "contrib\testkits\Akka.TestKit.NUnit3\Akka.TestKit.NUnit3.csproj", "{62A7BBA3-2AA6-4F9B-8ACA-15C3863C026E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.TestKit.NUnit3.Tests", "contrib\testkits\Akka.TestKit.NUnit3.Tests\Akka.TestKit.NUnit3.Tests.csproj", "{FF91B397-1E60-4B94-99A1-B534C7BB91A5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug Mono|Any CPU = Debug Mono|Any CPU @@ -980,6 +982,22 @@ Global {F72BE71A-2BE3-413D-A3D9-C7FDBB4E5F08}.Release Mono|Any CPU.Build.0 = Release Mono|Any CPU {F72BE71A-2BE3-413D-A3D9-C7FDBB4E5F08}.Release|Any CPU.ActiveCfg = Release|Any CPU {F72BE71A-2BE3-413D-A3D9-C7FDBB4E5F08}.Release|Any CPU.Build.0 = Release|Any CPU + {62A7BBA3-2AA6-4F9B-8ACA-15C3863C026E}.Debug Mono|Any CPU.ActiveCfg = Debug|Any CPU + {62A7BBA3-2AA6-4F9B-8ACA-15C3863C026E}.Debug Mono|Any CPU.Build.0 = Debug|Any CPU + {62A7BBA3-2AA6-4F9B-8ACA-15C3863C026E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {62A7BBA3-2AA6-4F9B-8ACA-15C3863C026E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {62A7BBA3-2AA6-4F9B-8ACA-15C3863C026E}.Release Mono|Any CPU.ActiveCfg = Release|Any CPU + {62A7BBA3-2AA6-4F9B-8ACA-15C3863C026E}.Release Mono|Any CPU.Build.0 = Release|Any CPU + {62A7BBA3-2AA6-4F9B-8ACA-15C3863C026E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {62A7BBA3-2AA6-4F9B-8ACA-15C3863C026E}.Release|Any CPU.Build.0 = Release|Any CPU + {FF91B397-1E60-4B94-99A1-B534C7BB91A5}.Debug Mono|Any CPU.ActiveCfg = Debug|Any CPU + {FF91B397-1E60-4B94-99A1-B534C7BB91A5}.Debug Mono|Any CPU.Build.0 = Debug|Any CPU + {FF91B397-1E60-4B94-99A1-B534C7BB91A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF91B397-1E60-4B94-99A1-B534C7BB91A5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF91B397-1E60-4B94-99A1-B534C7BB91A5}.Release Mono|Any CPU.ActiveCfg = Release|Any CPU + {FF91B397-1E60-4B94-99A1-B534C7BB91A5}.Release Mono|Any CPU.Build.0 = Release|Any CPU + {FF91B397-1E60-4B94-99A1-B534C7BB91A5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF91B397-1E60-4B94-99A1-B534C7BB91A5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1097,5 +1115,7 @@ Global {453DD4B1-64B8-4B50-BFDA-3489E32D30D8} = {01167D3C-49C4-4CDE-9787-C176D139ACDD} {C84A7909-72A7-4164-B348-8D3E9D16F5A4} = {FFEC736B-EDA3-433C-8564-7C14676601A1} {F72BE71A-2BE3-413D-A3D9-C7FDBB4E5F08} = {01167D3C-49C4-4CDE-9787-C176D139ACDD} + {62A7BBA3-2AA6-4F9B-8ACA-15C3863C026E} = {7625FD95-4B2C-4A5B-BDD5-94B1493FAC8E} + {FF91B397-1E60-4B94-99A1-B534C7BB91A5} = {7625FD95-4B2C-4A5B-BDD5-94B1493FAC8E} EndGlobalSection EndGlobal diff --git a/src/contrib/testkits/Akka.TestKit.NUnit/packages.config b/src/contrib/testkits/Akka.TestKit.NUnit/packages.config index c714ef3a23e..b837b408d2b 100644 --- a/src/contrib/testkits/Akka.TestKit.NUnit/packages.config +++ b/src/contrib/testkits/Akka.TestKit.NUnit/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/Akka.TestKit.NUnit3.Tests.csproj b/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/Akka.TestKit.NUnit3.Tests.csproj new file mode 100644 index 00000000000..3055c2764e7 --- /dev/null +++ b/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/Akka.TestKit.NUnit3.Tests.csproj @@ -0,0 +1,77 @@ + + + + + Debug + AnyCPU + {FF91B397-1E60-4B94-99A1-B534C7BB91A5} + Library + Properties + Akka.TestKit.NUnit3.Tests + Akka.TestKit.NUnit3.Tests + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\packages\NUnit.3.0.0\lib\net45\nunit.framework.dll + True + + + + + + + + + + + + + + + + + + + {0d3cbad0-bbdb-43e5-afc4-ed1d3ecdc224} + Akka.TestKit + + + {5deddf90-37f0-48d3-a0b0-a5cbd8a7e377} + Akka + + + {62a7bba3-2aa6-4f9b-8aca-15c3863c026e} + Akka.TestKit.NUnit3 + + + + + + + + \ No newline at end of file diff --git a/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/AssertionsTests.cs b/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/AssertionsTests.cs new file mode 100644 index 00000000000..f4e75d17ba5 --- /dev/null +++ b/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/AssertionsTests.cs @@ -0,0 +1,78 @@ +//----------------------------------------------------------------------- +// +// Copyright (C) 2009-2016 Typesafe Inc. +// Copyright (C) 2013-2016 Akka.NET project +// +//---------------------------------------------------------------------- + +using NUnit.Framework; + +namespace Akka.TestKit.NUnit3.Tests +{ + [TestFixture] + public class AssertionsTests + { + private readonly NUnitAssertions _assertions; + + public AssertionsTests() + { + _assertions = new NUnitAssertions(); + } + + [Test] + public void Fail_should_throw() + { + Assert.Throws(() => _assertions.Fail()); + } + + [Test] + public void AssertTrue_should_throw_on_false() + { + Assert.Throws(() => _assertions.AssertTrue(false)); + } + + [Test] + public void AssertTrue_should_succeed_on_true() + { + _assertions.AssertTrue(true); + } + + [Test] + public void AssertFalse_should_throw_on_true() + { + Assert.Throws(() => _assertions.AssertFalse(true)); + } + + [Test] + public void AssertFalse_should_succeed_on_false() + { + _assertions.AssertFalse(false); + } + + + [Test] + public void AssertEqual_should_throw_on_not_equal() + { + Assert.Throws(() => _assertions.AssertEqual(42, 4711)); + } + + [Test] + public void AssertEqual_should_succeed_on_equal() + { + _assertions.AssertEqual(42, 42); + } + + + [Test] + public void AssertEqualWithComparer_should_throw_on_not_equal() + { + Assert.Throws(() => _assertions.AssertEqual(42, 42, (x, y) => false)); + } + + [Test] + public void AssertEqualWithComparer_should_succeed_on_equal() + { + _assertions.AssertEqual(42, 4711, (x, y) => true); + } + } +} diff --git a/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/Properties/AssemblyInfo.cs b/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..eeb1987342e --- /dev/null +++ b/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("Akka.TestKit.NUnit3.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Akka.TestKit.NUnit3.Tests")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar +// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("ff91b397-1e60-4b94-99a1-b534c7bb91a5")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern +// übernehmen, indem Sie "*" eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/TestKitTestFixtureTest.cs b/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/TestKitTestFixtureTest.cs new file mode 100644 index 00000000000..05117c596fc --- /dev/null +++ b/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/TestKitTestFixtureTest.cs @@ -0,0 +1,29 @@ +//----------------------------------------------------------------------- +// +// Copyright (C) 2009-2016 Typesafe Inc. +// Copyright (C) 2013-2016 Akka.NET project +// +//---------------------------------------------------------------------- + +using Akka.Actor; +using Akka.TestKit.TestActors; +using NUnit.Framework; + +namespace Akka.TestKit.NUnit3.Tests +{ + [TestFixture] + public class TestKitTestFixtureTest : TestKit + { + [Test] + public void Can_create_more_than_one_test_in_a_fixture_with_the_same_actor_name_test1() + { + Sys.ActorOf("actor-name"); + } + + [Test] + public void Can_create_more_than_one_test_in_a_fixture_with_the_same_actor_name_test2() + { + Sys.ActorOf("actor-name"); + } + } +} \ No newline at end of file diff --git a/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/TestKitTests.cs b/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/TestKitTests.cs new file mode 100644 index 00000000000..286cef41983 --- /dev/null +++ b/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/TestKitTests.cs @@ -0,0 +1,29 @@ +//----------------------------------------------------------------------- +// +// Copyright (C) 2009-2016 Typesafe Inc. +// Copyright (C) 2013-2016 Akka.NET project +// +//---------------------------------------------------------------------- + +using Akka.Actor; +using NUnit.Framework; + +namespace Akka.TestKit.NUnit3.Tests +{ + [TestFixture] + public class TestKitTests : TestKit + { + [TearDown] + public void Cleanup() + { + Shutdown(); + } + + [Test] + public void Expect_a_message() + { + TestActor.Tell("Test"); + ExpectMsg("Test"); + } + } +} \ No newline at end of file diff --git a/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/packages.config b/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/packages.config new file mode 100644 index 00000000000..471a382d94d --- /dev/null +++ b/src/contrib/testkits/Akka.TestKit.NUnit3.Tests/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/contrib/testkits/Akka.TestKit.NUnit3/Akka.TestKit.NUnit3.csproj b/src/contrib/testkits/Akka.TestKit.NUnit3/Akka.TestKit.NUnit3.csproj new file mode 100644 index 00000000000..b2905578ab5 --- /dev/null +++ b/src/contrib/testkits/Akka.TestKit.NUnit3/Akka.TestKit.NUnit3.csproj @@ -0,0 +1,72 @@ + + + + + Debug + AnyCPU + {62A7BBA3-2AA6-4F9B-8ACA-15C3863C026E} + Library + Properties + Akka.TestKit.NUnit3 + Akka.TestKit.NUnit3 + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\packages\NUnit.3.0.0\lib\net45\nunit.framework.dll + True + + + + + + + + + + + + + + + + + + {0d3cbad0-bbdb-43e5-afc4-ed1d3ecdc224} + Akka.TestKit + + + {5deddf90-37f0-48d3-a0b0-a5cbd8a7e377} + Akka + + + + + + + + \ No newline at end of file diff --git a/src/contrib/testkits/Akka.TestKit.NUnit3/Akka.TestKit.NUnit3.nuspec b/src/contrib/testkits/Akka.TestKit.NUnit3/Akka.TestKit.NUnit3.nuspec new file mode 100644 index 00000000000..0e1097ba974 --- /dev/null +++ b/src/contrib/testkits/Akka.TestKit.NUnit3/Akka.TestKit.NUnit3.nuspec @@ -0,0 +1,20 @@ + + + + @project@ + @project@@title@ + @build.number@ + @authors@ + @authors@ + TestKit for writing tests for Akka.NET using NUnit3. + https://github.com/akkadotnet/akka.net/blob/master/LICENSE + https://github.com/akkadotnet/akka.net + http://getakka.net/images/AkkaNetLogo.Normal.png + false + @releaseNotes@ + @copyright@ + @tags@ NUnit + @dependencies@ + @references@ + + diff --git a/src/contrib/testkits/Akka.TestKit.NUnit3/NUnitAssertions.cs b/src/contrib/testkits/Akka.TestKit.NUnit3/NUnitAssertions.cs new file mode 100644 index 00000000000..a553b19d72a --- /dev/null +++ b/src/contrib/testkits/Akka.TestKit.NUnit3/NUnitAssertions.cs @@ -0,0 +1,50 @@ +//----------------------------------------------------------------------- +// +// Copyright (C) 2009-2016 Typesafe Inc. +// Copyright (C) 2013-2016 Akka.NET project +// +//----------------------------------------------------------------------- + +using System; +using NUnit.Framework; + +namespace Akka.TestKit.NUnit3 +{ + /// + /// Assertions for NUnit + /// + public class NUnitAssertions : ITestKitAssertions + { + + public void Fail(string format = "", params object[] args) + { + Assert.Fail(format, args); + } + + public void AssertTrue(bool condition, string format = "", params object[] args) + { + Assert.IsTrue(condition, format, args); + } + + public void AssertFalse(bool condition, string format = "", params object[] args) + { + Assert.IsFalse(condition, format, args); + } + + public void AssertEqual(T expected, T actual, string format = "", params object[] args) + { + Assert.AreEqual(expected, actual, format, args); + } + + public void AssertEqual(T expected, T actual, Func comparer, string format = "", params object[] args) + { + if (!comparer(expected, actual)) + throw new AssertionException(string.Format("Assert.AreEqual failed. Expected [{0}]. Actual [{1}]. {2}", FormatValue(expected), FormatValue(actual), string.Format(format, args))); + } + + private static string FormatValue(T expected) + { + return ReferenceEquals(expected, null) ? "null" : expected.ToString(); + } + } +} \ No newline at end of file diff --git a/src/contrib/testkits/Akka.TestKit.NUnit3/Properties/AssemblyInfo.cs b/src/contrib/testkits/Akka.TestKit.NUnit3/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..4edc8c8a0aa --- /dev/null +++ b/src/contrib/testkits/Akka.TestKit.NUnit3/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("Akka.TestKit.NUnit3")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Akka.TestKit.NUnit3")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar +// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("62a7bba3-2aa6-4f9b-8aca-15c3863c026e")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern +// übernehmen, indem Sie "*" eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/contrib/testkits/Akka.TestKit.NUnit3/TestKit.cs b/src/contrib/testkits/Akka.TestKit.NUnit3/TestKit.cs new file mode 100644 index 00000000000..9bb52c14cac --- /dev/null +++ b/src/contrib/testkits/Akka.TestKit.NUnit3/TestKit.cs @@ -0,0 +1,134 @@ +//----------------------------------------------------------------------- +// +// Copyright (C) 2009-2016 Typesafe Inc. +// Copyright (C) 2013-2016 Akka.NET project +// +//----------------------------------------------------------------------- + +using System; +using Akka.Actor; +using Akka.Configuration; +using NUnit.Framework; + +namespace Akka.TestKit.NUnit3 +{ + /// + /// TestKit for NUnit. + /// + public class TestKit : TestKitBase, IDisposable + { + private static readonly NUnitAssertions _assertions = new NUnitAssertions(); + private readonly Config _config; + private readonly string _actorSystemName; + private bool _isFirstRun = true; + private bool _isDisposed; //Automatically initialized to false; + + /// + /// Create a new instance of the for NUnit class. + /// If no is passed in, a new system + /// with will be created. + /// + /// Optional: The actor system. + public TestKit(ActorSystem system = null) + : base(_assertions, system) + { + if(system != null) + throw new NotSupportedException("Due to the way NUnit works, providing an ActorSystem is not supported. For further details please see https://github.com/akkadotnet/akka.net/pull/1092"); + } + + /// + /// Create a new instance of the for NUnit class. + /// A new system with the specified configuration will be created. + /// + /// The configuration to use for the system. + /// Optional: the name of the system. Default: "test" + public TestKit(Config config, string actorSystemName = null) + : base(_assertions, config, actorSystemName) + { + _config = config; + _actorSystemName = actorSystemName; + } + + + /// + /// Create a new instance of the for NUnit class. + /// A new system with the specified configuration will be created. + /// + /// The configuration to use for the system. + public TestKit(string config) + : base(_assertions, ConfigurationFactory.ParseString(config)) + { + _config = ConfigurationFactory.ParseString(config); + } + + public new static Config DefaultConfig { get { return TestKitBase.DefaultConfig; } } + public new static Config FullDebugConfig { get { return TestKitBase.FullDebugConfig; } } + + protected static NUnitAssertions Assertions { get { return _assertions; } } + + /// + /// This method is called before each test run, it initializes the test including + /// creating and setting up the ActorSystem. + /// + [SetUp] + public void InitializeActorSystemOnSetUp() + { + if (!_isFirstRun) + InitializeTest(null, _config, _actorSystemName, null); + } + + /// + /// This method is called after each test finishes, which calls + /// into the AfterAll method. + /// + [TearDown] + public void ShutDownActorSystemOnTearDown() + { + _isFirstRun = false; + AfterAll(); + } + + /// + /// This method is called when a test ends. + /// If you override this, make sure you either call + /// base.AfterTest() or TestKitBase.Shutdown to shut down + /// the system. Otherwise you'll leak memory. + /// + /// + protected virtual void AfterAll() + { + Shutdown(); + } + + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + public void Dispose() + { + Dispose(true); + //Take this object off the finalization queue and prevent finalization code for this object + //from executing a second time. + GC.SuppressFinalize(this); + } + + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// if set to true the method has been called directly or indirectly by a + /// user's code. Managed and unmanaged resources will be disposed.
+ /// if set to false the method has been called by the runtime from inside the finalizer and only + /// unmanaged resources can be disposed. + protected virtual void Dispose(bool disposing) + { + // If disposing equals false, the method has been called by the + // runtime from inside the finalizer and you should not reference + // other objects. Only unmanaged resources can be disposed. + + //Make sure Dispose does not get called more than once, by checking the disposed field + if (!_isDisposed) + { + if (disposing) + { + AfterAll(); + } + } + _isDisposed = true; + } + } +} diff --git a/src/contrib/testkits/Akka.TestKit.NUnit3/packages.config b/src/contrib/testkits/Akka.TestKit.NUnit3/packages.config new file mode 100644 index 00000000000..471a382d94d --- /dev/null +++ b/src/contrib/testkits/Akka.TestKit.NUnit3/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file