From 03b16a14ed3dd00033a633fcbb19ed04327eb178 Mon Sep 17 00:00:00 2001 From: Charlie Poole Date: Tue, 16 Sep 2025 18:03:52 -0700 Subject: [PATCH] Restore and reorganize tests --- NuGet.config | 3 +- build.cake | 8 +- nuget/TestCentric.Extensibility.Api.nuspec | 2 +- nuget/TestCentric.Extensibility.nuspec | 4 +- src/Directory.Build.props | 11 +- .../FakeExtensions.cs | 117 ++++++++--------- .../ExtensionManagerTests.cs | 118 ++++++++++-------- .../ExtensionManager.cs | 10 +- 8 files changed, 151 insertions(+), 122 deletions(-) diff --git a/NuGet.config b/NuGet.config index ceb1e2b..1e5ebaa 100644 --- a/NuGet.config +++ b/NuGet.config @@ -4,6 +4,7 @@ - + + \ No newline at end of file diff --git a/build.cake b/build.cake index f27b8e4..24569d9 100644 --- a/build.cake +++ b/build.cake @@ -1,5 +1,5 @@ // Load the recipe -#load nuget:?package=TestCentric.Cake.Recipe&version=1.4.1-dev00004 +#load nuget:?package=TestCentric.Cake.Recipe&version=1.5.0-dev00006 // Comment out above line and uncomment below for local tests of recipe changes //#load ../TestCentric.Cake.Recipe/recipe/*.cake @@ -19,8 +19,8 @@ BuildSettings.Packages.Add(new NuGetPackage( source: "nuget/TestCentric.Extensibility.nuspec", checks: new PackageCheck[] { HasFiles("LICENSE.txt", "README.md", "testcentric.png"), - HasDirectory("lib/net20") - .WithFiles("TestCentric.Extensibility.dll", "TestCentric.Extensibility.api.dll", "nunit.engine.api.dll"), + //HasDirectory("lib/net20") + // .WithFiles("TestCentric.Extensibility.dll", "TestCentric.Extensibility.api.dll", "nunit.engine.api.dll"), HasDirectory("lib/net462") .WithFiles("testcentric.extensibility.dll", "TestCentric.Extensibility.api.dll", "nunit.engine.api.dll"), HasDirectory("lib/netstandard2.0") @@ -49,7 +49,7 @@ BuildSettings.Packages.Add(new NuGetPackage( checks: new PackageCheck[] { HasFiles( "LICENSE.txt", "README.md", "testcentric.png", - "lib/net20/testcentric.extensibility.api.dll", + //"lib/net20/testcentric.extensibility.api.dll", "lib/net462/testcentric.extensibility.api.dll", "lib/netstandard2.0/testcentric.extensibility.api.dll") })); diff --git a/nuget/TestCentric.Extensibility.Api.nuspec b/nuget/TestCentric.Extensibility.Api.nuspec index 9f4372c..53fef6e 100644 --- a/nuget/TestCentric.Extensibility.Api.nuspec +++ b/nuget/TestCentric.Extensibility.Api.nuspec @@ -18,7 +18,7 @@ - + diff --git a/nuget/TestCentric.Extensibility.nuspec b/nuget/TestCentric.Extensibility.nuspec index dfc229d..9121333 100644 --- a/nuget/TestCentric.Extensibility.nuspec +++ b/nuget/TestCentric.Extensibility.nuspec @@ -22,11 +22,11 @@ - + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index b0042b9..726de2f 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -23,10 +23,9 @@ true 8.0.0 - 2.0.0-dev01905 + 2.0.0-dev01907 3.0.4 1.2.1 - 3.16.2 TestCentric TestCentric Gui Runner and Engine @@ -36,6 +35,11 @@ 0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7 + + + 3.16.2 + + 4.1.0 5.3.0 + 4.0.0-beta.1.1 diff --git a/src/testcentric.extensibility.fakes/FakeExtensions.cs b/src/testcentric.extensibility.fakes/FakeExtensions.cs index 84054c0..c77b6ea 100644 --- a/src/testcentric.extensibility.fakes/FakeExtensions.cs +++ b/src/testcentric.extensibility.fakes/FakeExtensions.cs @@ -3,50 +3,40 @@ // Licensed under the MIT License. See LICENSE file in root directory. // *********************************************************************** -using TestCentric.Extensibility; -using TestCentric.Engine.Services; - using System.Diagnostics; using System; using System.Reflection; using System.Xml; using System.IO; -#if false namespace TestCentric.Engine.Extensibility { - // Extensions - - [Extension(Enabled = false, Path = "/TestCentric/Engine/TypeExtensions/ITestEventListener")] - public class FakeTestEventListener : ITestEventListener - { - public void OnTestEvent(string text) - { - throw new System.NotImplementedException(); - } - } + using TestCentric.Extensibility; - //[Extension] - public class FakeService : IService + [Extension] + public class FakeAgentLauncher : IAgentLauncher { - public IServiceLocator ServiceContext { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); } - - public ServiceStatus Status => throw new System.NotImplementedException(); + public TestAgentInfo AgentInfo => throw new NotImplementedException(); - public void StartService() + public bool CanCreateProcess(TestPackage package) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } - public void StopService() + public Process CreateProcess(Guid agentId, string agencyUrl, TestPackage package) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } } - [Extension] - public class FakeAgentLauncher : TestCentric.Engine.Extensibility.IAgentLauncher + [Extension(Enabled = false)] + public class FakeAgentLauncher_ThrowsInConstructor : IAgentLauncher { + public FakeAgentLauncher_ThrowsInConstructor() + { + throw new NotImplementedException(); + } + public TestAgentInfo AgentInfo => throw new NotImplementedException(); public bool CanCreateProcess(TestPackage package) @@ -59,26 +49,58 @@ public Process CreateProcess(Guid agentId, string agencyUrl, TestPackage package throw new NotImplementedException(); } } +} - //[Extension] - public class FakeDriverFactory : IDriverFactory - { -#if NETFRAMEWORK - public IFrameworkDriver GetDriver(AppDomain domain, AssemblyName reference) +namespace NUnit.Engine.Extensibility +{ +#if NET20 + using NUnit.Engine.Extensibility; #else - public IFrameworkDriver GetDriver(AssemblyName reference) + using NUnit.Extensibility; #endif + + [Extension(Enabled = false, Path = "/NUnit/Engine/TypeExtensions/ITestEventListener")] + public class FakeTestEventListener : ITestEventListener + { + public void OnTestEvent(string text) { - throw new NotImplementedException(); + throw new System.NotImplementedException(); } + } - public bool IsSupportedTestFramework(AssemblyName reference) + [Extension(Path = "/NUnit/Engine/TypeExtensions/IProjectLoader")] + public class FakeProjectLoader : IProjectLoader + { + public bool CanLoadFrom(string path) { - throw new NotImplementedException(); + throw new System.NotImplementedException(); + } + + public NUnit.Engine.Extensibility.IProject LoadFrom(string path) + { + throw new System.NotImplementedException(); } } - //[Extension] +// [Extension] +// public class FakeDriverFactory : IDriverFactory +// { +//#if NETFRAMEWORK +// public IFrameworkDriver GetDriver(AppDomain domain, AssemblyName reference) +//#else +// public IFrameworkDriver GetDriver(AssemblyName reference) +//#endif +// { +// throw new NotImplementedException(); +// } + +// public bool IsSupportedTestFramework(AssemblyName reference) +// { +// throw new NotImplementedException(); +// } +// } + + [Extension] public class FakeResultWriter : IResultWriter { public void CheckWritability(string outputPath) @@ -97,10 +119,10 @@ public void WriteResultFile(XmlNode resultNode, TextWriter writer) } } - [Extension(Enabled = false)] - public class FakeExtension_ThrowsInConstructor : ITestEventListener + [Extension(Enabled = false, Path = "/NUnit/Engine/TypeExtensions/ITestEventListener")] + public class FakeNUnitExtension_ThrowsInConstructor : ITestEventListener { - public FakeExtension_ThrowsInConstructor() + public FakeNUnitExtension_ThrowsInConstructor() { throw new NotImplementedException(); } @@ -111,22 +133,3 @@ public void OnTestEvent(string text) } } } -#endif - -namespace NUnit.Engine.Extensibility -{ - //[Extension(Path = "/NUnit/Engine/TypeExtensions/IProjectLoader/")] - [Extension] - public class FakeProjectLoader : IProjectLoader - { - public bool CanLoadFrom(string path) - { - throw new System.NotImplementedException(); - } - - public NUnit.Engine.Extensibility.IProject LoadFrom(string path) - { - throw new System.NotImplementedException(); - } - } -} diff --git a/src/testcentric.extensibility.tests/ExtensionManagerTests.cs b/src/testcentric.extensibility.tests/ExtensionManagerTests.cs index 71dc43c..66329ba 100644 --- a/src/testcentric.extensibility.tests/ExtensionManagerTests.cs +++ b/src/testcentric.extensibility.tests/ExtensionManagerTests.cs @@ -32,33 +32,29 @@ public ExtensionManagerTests(string defaultTypeExtensionsPath) ExpectedExtensionPointPaths = new[] { - prefix + "ITestEventListener", - prefix + "IService", prefix + "IAgentLauncher", - prefix + "IDriverFactory", - prefix + "IProjectLoader", - prefix + "IResultWriter", "/NUnit/Engine/TypeExtensions/ITestEventListener", "/NUnit/Engine/TypeExtensions/IService", "/NUnit/Engine/TypeExtensions/IDriverFactory", + "/NUnit/Engine/TypeExtensions/IResultWriter", "/NUnit/Engine/TypeExtensions/IProjectLoader", - "/NUnit/Engine/TypeExtensions/IResultWriter" +#if !NET35 + "/NUnit/Engine/TypeExtensions/IAgentLauncher" +#endif }; // This could be initialized inline, but it's here for clarity ExpectedExtensionPointTypes = new[] { - typeof(TestCentric.Engine.ITestEventListener), - typeof(TestCentric.Engine.Services.IService), typeof(TestCentric.Engine.Extensibility.IAgentLauncher), - typeof(TestCentric.Engine.Extensibility.IDriverFactory), - typeof(TestCentric.Engine.Extensibility.IProjectLoader), - typeof(TestCentric.Engine.Extensibility.IResultWriter), typeof(NUnit.Engine.ITestEventListener), typeof(NUnit.Engine.IService), typeof(NUnit.Engine.Extensibility.IDriverFactory), + typeof(NUnit.Engine.Extensibility.IResultWriter), typeof(NUnit.Engine.Extensibility.IProjectLoader), - typeof(NUnit.Engine.Extensibility.IResultWriter) +#if !NET35 + typeof(NUnit.Engine.Extensibility.IAgentLauncher) +#endif }; } @@ -145,10 +141,14 @@ internal class ThisIsNotAnExtensionPoint private static string[] KnownExtensionTypeNames = [ - //"TestCentric.Engine.Extensibility.FakeAgentLauncher", - //"TestCentric.Engine.Extensibility.FakeTestEventListener", - //"TestCentric.Engine.Extensibility.FakeExtension_ThrowsInConstructor", - "NUnit.Engine.Extensibility.FakeProjectLoader" + "TestCentric.Engine.Extensibility.FakeAgentLauncher", + "TestCentric.Engine.Extensibility.FakeAgentLauncher_ThrowsInConstructor", +#if !NET35 + "NUnit.Engine.Extensibility.FakeTestEventListener", + "NUnit.Engine.Extensibility.FakeProjectLoader", + "NUnit.Engine.Extensibility.FakeResultWriter", + "NUnit.Engine.Extensibility.FakeNUnitExtension_ThrowsInConstructor" +#endif ]; [Test] @@ -157,51 +157,67 @@ public void AllExtensionsAreKnown() Assert.That(ExtensionManager.Extensions.Select(ep => ep.TypeName), Is.EquivalentTo(KnownExtensionTypeNames)); } - //// Run this first as subsequent test will enable the extension - //[Test, Order(1)] - //public void ExtensionMayBeDisabledByDefault() - //{ - // Assert.That(ExtensionManager.Extensions, - // Has.One.Property(nameof(ExtensionNode.TypeName)).EqualTo("TestCentric.Engine.Extensibility.FakeTestEventListener") - // .And.Property(nameof(ExtensionNode.Enabled)).False); - //} - - //[Test] - //public void DisabledExtensionMayBeEnabled() - //{ - // ExtensionManager.EnableExtension("TestCentric.Engine.Extensibility.FakeTestEventListener", true); - - // Assert.That(ExtensionManager.Extensions, - // Has.One.Property(nameof(ExtensionNode.TypeName)).EqualTo("TestCentric.Engine.Extensibility.FakeTestEventListener") - // .And.Property(nameof(ExtensionNode.Enabled)).True); - //} - - //[Test] - //public void ExtensionThrowsInConstructor() - //{ - // string typeName = "TestCentric.Engine.Extensibility.FakeExtension_ThrowsInConstructor"; - // var exNode = ExtensionManager.Extensions.Where(n => n.TypeName == typeName).Single(); - - // // Although the constructor throws, we don't get an exception. - // // However, the node contains the error information. - // Assert.DoesNotThrow(() => { var o = exNode.ExtensionObject; }); - // Assert.That(exNode.Status, Is.EqualTo(ExtensionStatus.Error)); - // Assert.That(exNode.Exception, Is.InstanceOf()); - // Assert.That(exNode.Exception.InnerException, Is.InstanceOf()); - //} +#if !NET35 + // Run this first as subsequent test will enable the extension + [Test, Order(1)] + public void ExtensionMayBeDisabledByDefault() + { + Assert.That(ExtensionManager.Extensions, + Has.One.Property(nameof(ExtensionNode.TypeName)).EqualTo("NUnit.Engine.Extensibility.FakeTestEventListener") + .And.Property(nameof(ExtensionNode.Enabled)).False); + } + + [Test] + public void DisabledExtensionMayBeEnabled() + { + ExtensionManager.EnableExtension("NUnit.Engine.Extensibility.FakeTestEventListener", true); + + Assert.That(ExtensionManager.Extensions, + Has.One.Property(nameof(ExtensionNode.TypeName)).EqualTo("NUnit.Engine.Extensibility.FakeTestEventListener") + .And.Property(nameof(ExtensionNode.Enabled)).True); + } + + [Test] + public void NUnitExtensionThrowsInConstructor() + { + string typeName = "NUnit.Engine.Extensibility.FakeNUnitExtension_ThrowsInConstructor"; + var exNode = ExtensionManager.Extensions.Where(n => n.TypeName == typeName).Single(); + + // Although the constructor throws, we don't get an exception. + // However, the node contains the error information. + Assert.DoesNotThrow(() => { var o = exNode.ExtensionObject; }); + Assert.That(exNode.Status, Is.EqualTo(ExtensionStatus.Error)); + Assert.That(exNode.Exception, Is.InstanceOf()); + Assert.That(exNode.Exception.InnerException, Is.InstanceOf()); + } +#endif + + [Test] + public void TestCentricExtensionThrowsInConstructor() + { + string typeName = "TestCentric.Engine.Extensibility.FakeAgentLauncher_ThrowsInConstructor"; + var exNode = ExtensionManager.Extensions.Where(n => n.TypeName == typeName).Single(); + + // Although the constructor throws, we don't get an exception. + // However, the node contains the error information. + Assert.DoesNotThrow(() => { var o = exNode.ExtensionObject; }); + Assert.That(exNode.Status, Is.EqualTo(ExtensionStatus.Error)); + Assert.That(exNode.Exception, Is.InstanceOf()); + Assert.That(exNode.Exception.InnerException, Is.InstanceOf()); + } #if NETCOREAPP [TestCase("netstandard2.0", ExpectedResult = true)] [TestCase("net462", ExpectedResult = false)] - [TestCase("net20", ExpectedResult = false)] + //[TestCase("net20", ExpectedResult = false)] #elif NET40_OR_GREATER [TestCase("netstandard2.0", ExpectedResult = false)] [TestCase("net462", ExpectedResult = true)] - [TestCase("net20", ExpectedResult = true)] + //[TestCase("net20", ExpectedResult = true)] #else [TestCase("netstandard2.0", ExpectedResult = false)] [TestCase("net462", ExpectedResult = false)] - [TestCase("net20", ExpectedResult = true)] + //[TestCase("net20", ExpectedResult = true)] #endif public bool LoadTargetFramework(string tfm) { diff --git a/src/testcentric.extensibility/ExtensionManager.cs b/src/testcentric.extensibility/ExtensionManager.cs index 150584e..0662683 100644 --- a/src/testcentric.extensibility/ExtensionManager.cs +++ b/src/testcentric.extensibility/ExtensionManager.cs @@ -9,7 +9,11 @@ using System.Reflection; using TestCentric.Metadata; +#if NET20 using NUNIT = NUnit.Engine.Extensibility; +#else +using NUNIT = NUnit.Extensibility; +#endif namespace TestCentric.Extensibility { @@ -34,9 +38,9 @@ public class ExtensionManager private const string TESTCENTRIC_EXTENSION_ATTRIBUTE = "TestCentric.Extensibility.ExtensionAttribute"; private const string TESTCENTRIC_EXTENSION_PROPERTY_ATTRIBUTE = "TestCentric.Extensibility.ExtensionPropertyAttribute"; - // TODO: These are NUnit V3 attributes. We should support as well - private const string NUNIT_EXTENSION_ATTRIBUTE = "NUnit.Engine.Extensibility.ExtensionAttribute"; - private const string NUNIT_EXTENSION_PROPERTY_ATTRIBUTE = "NUnit.Engine.Extensibility.ExtensionPropertyAttribute"; + // TODO: These are NUnit V4 attributes. + private const string NUNIT_EXTENSION_ATTRIBUTE = "NUnit.Extensibility.ExtensionAttribute"; + private const string NUNIT_EXTENSION_PROPERTY_ATTRIBUTE = "NUnit.Extensibility.ExtensionPropertyAttribute"; // List of all ExtensionPoints discovered private readonly List _extensionPoints = new List();