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
5 changes: 4 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
<NSubstitutePublicKey>0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7</NSubstitutePublicKey>
</PropertyGroup>

<!-- Common package metadata -->
<!-- Common package metadata, may be overridden in individual projects -->
<!-- Each project should supply properties for PackageId, Title and Description -->
<PropertyGroup>
<PackageOutputPath>$(MSBuildThisFileDirectory)..\package</PackageOutputPath>
<IncludeSymbols>true</IncludeSymbols>
Expand All @@ -46,6 +47,8 @@
<PackageIcon>nunit_256.png</PackageIcon>
<PackageIconUrl>https://cdn.rawgit.com/nunit/resources/master/images/icon/nunit_256.png</PackageIconUrl>
<PackageReleaseNotes>https://docs.nunit.org/articles/nunit/release-notes/console-and-engine.html</PackageReleaseNotes>
<RepositoryUrl>https://github.com/NUnit/nunit-console</RepositoryUrl>
<ReleaseNotes>https://docs.nunit.org/articles/nunit/release-notes/console-and-engine.html</ReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
21 changes: 16 additions & 5 deletions src/NUnitCommon/nunit.agent.core/Drivers/DriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ namespace NUnit.Engine.Drivers
/// </summary>
public class DriverService : IDriverService
{
#if NETFRAMEWORK
private const string TYPE_EXTENSION_PATH = "/NUnit/Engine/TypeExtensions/";

private static readonly Assembly THIS_ASSEMBLY = typeof(DriverService).Assembly;
private static readonly bool RUNNING_UNDER_CHOCOLATEY =
System.IO.File.Exists(Path.Combine(Path.GetDirectoryName(THIS_ASSEMBLY.Location)!, "VERIFICATION.txt"));
private static readonly string PACKAGE_PREFIX = RUNNING_UNDER_CHOCOLATEY ? "nunit-extension-" : "NUnit.Extension.";
#endif

private static readonly Logger log = InternalTrace.GetLogger("DriverService");

private static readonly char[] CommaSeparator = [','];
Expand All @@ -28,11 +37,14 @@ public DriverService()
_factories.Add(new NUnit3DriverFactory());

#if NETFRAMEWORK // TODO: Restore extensibility to .NET 8.0 build
var thisAssembly = Assembly.GetExecutingAssembly();
var extensionManager = new ExtensionManager();
var extensionManager = new ExtensionManager()
{
TypeExtensionPath = TYPE_EXTENSION_PATH,
PackagePrefixes = [PACKAGE_PREFIX]
};

extensionManager.FindExtensionPoints(thisAssembly);
extensionManager.FindExtensionAssemblies(thisAssembly);
extensionManager.FindExtensionPoints(THIS_ASSEMBLY);
extensionManager.FindExtensionAssemblies(THIS_ASSEMBLY);

foreach (IDriverFactory factory in extensionManager.GetExtensions<IDriverFactory>())
_factories.Add(factory);
Expand All @@ -41,7 +53,6 @@ public DriverService()
if (node is not null)
_factories.Add(new NUnit2DriverFactory(node));
#endif

}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/NUnitCommon/nunit.agent.core/nunit.agent.core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<PropertyGroup>
<PackageId>NUnit.Agent.Core</PackageId>
<Title>Agent Core</Title>
<Description>Contains Types used by agents.</Description>
</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions src/NUnitCommon/nunit.common/nunit.common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<PropertyGroup>
<PackageId>NUnit.Common</PackageId>
<Title>NUnit Shared Types</Title>
<Description>Contains Types used by both the engine and agents.</Description>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<PropertyGroup>
<PackageId>NUnit.Extensibility.Api</PackageId>
<Title>NUnit Extensibility Api</Title>
<Description>Contains the Types required for creating an NUnit extension of any kind.</Description>
</PropertyGroup>

Expand Down
124 changes: 74 additions & 50 deletions src/NUnitCommon/nunit.extensibility.tests/ExtensionManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace NUnit.Extensibility
{
[TestFixture("/NUnit/Engine/TypeExtensions/")]
public class ExtensionManagerTests
{
private static readonly Assembly THIS_ASSEMBLY = typeof(ExtensionManagerTests).Assembly;
Expand All @@ -21,30 +22,6 @@ public class ExtensionManagerTests
private static readonly string FAKE_EXTENSIONS_SOURCE_DIRECTORY =
Path.Combine(new DirectoryInfo(THIS_ASSEMBLY_DIRECTORY).Parent!.Parent!.Parent!.FullName, "src/TestData/FakeExtensions");

private static readonly string[] KnownExtensionPointPaths =
{
"/NUnit/Engine/TypeExtensions/IAgentLauncher",
"/NUnit/Engine/TypeExtensions/IDriverFactory",
"/NUnit/Engine/TypeExtensions/IProjectLoader",
"/NUnit/Engine/TypeExtensions/IResultWriter",
"/NUnit/Engine/TypeExtensions/ITestEventListener",
"/NUnit/Engine/TypeExtensions/IService",
"/NUnit/Engine/NUnitV2Driver"
};

private static readonly Type[] KnownExtensionPointTypes =
{
typeof(IAgentLauncher),
typeof(IDriverFactory),
typeof(IProjectLoader),
typeof(IResultWriter),
typeof(ITestEventListener),
typeof(IService),
typeof(IFrameworkDriver)
};

private static readonly int[] KnownExtensionPointCounts = { 1, 1, 1, 1, 2, 1, 0 };

private const string FAKE_AGENT_LAUNCHER_EXTENSION = "NUnit.Engine.Fakes.FakeAgentLauncherExtension";
private const string FAKE_FRAMEWORK_DRIVER_EXTENSION = "NUnit.Engine.Fakes.FakeFrameworkDriverExtension";
private const string FAKE_PROJECT_LOADER_EXTENSION = "NUnit.Engine.Fakes.FakeProjectLoaderExtension";
Expand All @@ -67,11 +44,50 @@ public class ExtensionManagerTests
};

private ExtensionManager _extensionManager;
private string _defaultTestExtensionPath;

private string[] _expectedExtensionPointPaths;
private Type[] _expectedExtensionPointTypes;
private int[] _expectedExtensionCounts;

public ExtensionManagerTests(string defaultTestExtensionPath)
{
Guard.ArgumentValid(
defaultTestExtensionPath.StartsWith('/') && defaultTestExtensionPath.EndsWith('/'),
"Path must start and end with '/'", nameof(defaultTestExtensionPath));

_defaultTestExtensionPath = defaultTestExtensionPath;
var prefix = defaultTestExtensionPath ?? "/NUnit/Extensibility/TypeExtensions/";

_expectedExtensionPointPaths =
[
prefix + "IAgentLauncher",
prefix + "IDriverFactory",
prefix + "IProjectLoader",
prefix + "IResultWriter",
prefix + "ITestEventListener",
prefix + "IService",
"/NUnit/Engine/NUnitV2Driver"
];

_expectedExtensionPointTypes =
[
typeof(IAgentLauncher),
typeof(IDriverFactory),
typeof(IProjectLoader),
typeof(IResultWriter),
typeof(ITestEventListener),
typeof(IService),
typeof(IFrameworkDriver)
];

_expectedExtensionCounts = [1, 1, 1, 1, 2, 1, 0];
}

[SetUp]
public void CreateExtensionManager()
{
_extensionManager = new ExtensionManager();
_extensionManager = new ExtensionManager() { TypeExtensionPath = _defaultTestExtensionPath };

// Find actual extension points.
_extensionManager.FindExtensionPoints(typeof(ExtensionManager).Assembly);
Expand All @@ -86,7 +102,7 @@ public void CreateExtensionManager()
public void AllKnownExtensionPointsAreFound()
{
Assert.That(_extensionManager.ExtensionPoints.Select(ep => ep.Path),
Is.EquivalentTo(KnownExtensionPointPaths));
Is.EquivalentTo(_expectedExtensionPointPaths));
}

[Test]
Expand Down Expand Up @@ -115,37 +131,45 @@ public void AllKnownExtensionsAreEnabledAsRequired()
}
}

[Test, Sequential]
public void CanGetExtensionPointByPath(
[ValueSource(nameof(KnownExtensionPointPaths))] string path,
[ValueSource(nameof(KnownExtensionPointTypes))] Type type)
[Test]
public void CanGetExtensionPointsByPath()
{
var ep = _extensionManager.GetExtensionPoint(path);
Assert.That(ep, Is.Not.Null);
Assert.That(ep.Path, Is.EqualTo(path));
Assert.That(ep.TypeName, Is.EqualTo(type.FullName));
for (int i = 0; i < _expectedExtensionPointPaths.Length; i++)
{
var path = _expectedExtensionPointPaths[i];
var type = _expectedExtensionPointTypes[i];
var ep = _extensionManager.GetExtensionPoint(path);
Assert.That(ep, Is.Not.Null);
Assert.That(ep.Path, Is.EqualTo(path));
Assert.That(ep.TypeName, Is.EqualTo(type.FullName));
}
}

[Test, Sequential]
public void CanGetExtensionPointByType(
[ValueSource(nameof(KnownExtensionPointPaths))] string path,
[ValueSource(nameof(KnownExtensionPointTypes))] Type type)
[Test]
public void CanGetExtensionPointByType()
{
var ep = _extensionManager.GetExtensionPoint(type);
Assert.That(ep, Is.Not.Null);
Assert.That(ep.Path, Is.EqualTo(path));
Assert.That(ep.TypeName, Is.EqualTo(type.FullName));
for (int i = 0; i < _expectedExtensionPointPaths.Length; i++)
{
var path = _expectedExtensionPointPaths[i];
var type = _expectedExtensionPointTypes[i];
var ep = _extensionManager.GetExtensionPoint(type);
Assert.That(ep, Is.Not.Null);
Assert.That(ep.Path, Is.EqualTo(path));
Assert.That(ep.TypeName, Is.EqualTo(type.FullName));
}
}

[Test, Sequential]
public void ExtensionsAreAddedToExtensionPoint(
[ValueSource(nameof(KnownExtensionPointPaths))] string path,
[ValueSource(nameof(KnownExtensionPointCounts))] int extensionCount)
[Test]
public void ExtensionsAreAddedToExtensionPoint()
{
var ep = _extensionManager.GetExtensionPoint(path);
Assume.That(ep, Is.Not.Null);

Assert.That(ep.Extensions.Count, Is.EqualTo(extensionCount));
for (int i = 0; i < _expectedExtensionPointPaths.Length; i++)
{
var path = _expectedExtensionPointPaths[i];
var extensionCount = _expectedExtensionCounts[i];
var ep = _extensionManager.GetExtensionPoint(path);
Assume.That(ep, Is.Not.Null);
Assert.That(ep.Extensions.Count, Is.EqualTo(extensionCount));
}
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@
namespace NUnit.Extensibility
{
/// <summary>
/// NUnitEngineException is thrown when the engine has been
/// called with improper values or when a particular facility
/// ExtensibilityException is thrown when the extensibility features
/// are used with improper values or when a particular feature
/// is not available.
/// </summary>
[Serializable]
public class NUnitExtensibilityException : Exception
public class ExtensibilityException : Exception
{
/// <summary>
/// Construct with a message
/// </summary>
public NUnitExtensibilityException(string message) : base(message)
public ExtensibilityException(string message) : base(message)
{
}

/// <summary>
/// Construct with a message and inner exception
/// </summary>
public NUnitExtensibilityException(string message, Exception? innerException) : base(message, innerException)
public ExtensibilityException(string message, Exception? innerException) : base(message, innerException)
{
}

/// <summary>
/// Serialization constructor
/// </summary>
public NUnitExtensibilityException(SerializationInfo info, StreamingContext context) : base(info, context)
public ExtensibilityException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
Expand Down
Loading
Loading