Skip to content

Commit 02a2c62

Browse files
authored
Merge pull request #1746 from nunit/issue-1744
Improvements to the ExtensionManager
2 parents af23621 + 7485617 commit 02a2c62

File tree

13 files changed

+256
-184
lines changed

13 files changed

+256
-184
lines changed

src/Directory.Build.props

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
<NSubstitutePublicKey>0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7</NSubstitutePublicKey>
3333
</PropertyGroup>
3434

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

5154
<ItemGroup>

src/NUnitCommon/nunit.agent.core/Drivers/DriverService.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ namespace NUnit.Engine.Drivers
1717
/// </summary>
1818
public class DriverService : IDriverService
1919
{
20+
#if NETFRAMEWORK
21+
private const string TYPE_EXTENSION_PATH = "/NUnit/Engine/TypeExtensions/";
22+
23+
private static readonly Assembly THIS_ASSEMBLY = typeof(DriverService).Assembly;
24+
private static readonly bool RUNNING_UNDER_CHOCOLATEY =
25+
System.IO.File.Exists(Path.Combine(Path.GetDirectoryName(THIS_ASSEMBLY.Location)!, "VERIFICATION.txt"));
26+
private static readonly string PACKAGE_PREFIX = RUNNING_UNDER_CHOCOLATEY ? "nunit-extension-" : "NUnit.Extension.";
27+
#endif
28+
2029
private static readonly Logger log = InternalTrace.GetLogger("DriverService");
2130

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

3039
#if NETFRAMEWORK // TODO: Restore extensibility to .NET 8.0 build
31-
var thisAssembly = Assembly.GetExecutingAssembly();
32-
var extensionManager = new ExtensionManager();
40+
var extensionManager = new ExtensionManager()
41+
{
42+
TypeExtensionPath = TYPE_EXTENSION_PATH,
43+
PackagePrefixes = [PACKAGE_PREFIX]
44+
};
3345

34-
extensionManager.FindExtensionPoints(thisAssembly);
35-
extensionManager.FindExtensionAssemblies(thisAssembly);
46+
extensionManager.FindExtensionPoints(THIS_ASSEMBLY);
47+
extensionManager.FindExtensionAssemblies(THIS_ASSEMBLY);
3648

3749
foreach (IDriverFactory factory in extensionManager.GetExtensions<IDriverFactory>())
3850
_factories.Add(factory);
@@ -41,7 +53,6 @@ public DriverService()
4153
if (node is not null)
4254
_factories.Add(new NUnit2DriverFactory(node));
4355
#endif
44-
4556
}
4657

4758
/// <summary>

src/NUnitCommon/nunit.agent.core/nunit.agent.core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<PropertyGroup>
99
<PackageId>NUnit.Agent.Core</PackageId>
10+
<Title>Agent Core</Title>
1011
<Description>Contains Types used by agents.</Description>
1112
</PropertyGroup>
1213

src/NUnitCommon/nunit.common/nunit.common.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<PropertyGroup>
99
<PackageId>NUnit.Common</PackageId>
10+
<Title>NUnit Shared Types</Title>
1011
<Description>Contains Types used by both the engine and agents.</Description>
1112
</PropertyGroup>
1213

src/NUnitCommon/nunit.extensibility.api/nunit.extensibility.api.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
<PropertyGroup>
1010
<PackageId>NUnit.Extensibility.Api</PackageId>
11+
<Title>NUnit Extensibility Api</Title>
1112
<Description>Contains the Types required for creating an NUnit extension of any kind.</Description>
1213
</PropertyGroup>
1314

src/NUnitCommon/nunit.extensibility.tests/ExtensionManagerTests.cs

Lines changed: 74 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

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

24-
private static readonly string[] KnownExtensionPointPaths =
25-
{
26-
"/NUnit/Engine/TypeExtensions/IAgentLauncher",
27-
"/NUnit/Engine/TypeExtensions/IDriverFactory",
28-
"/NUnit/Engine/TypeExtensions/IProjectLoader",
29-
"/NUnit/Engine/TypeExtensions/IResultWriter",
30-
"/NUnit/Engine/TypeExtensions/ITestEventListener",
31-
"/NUnit/Engine/TypeExtensions/IService",
32-
"/NUnit/Engine/NUnitV2Driver"
33-
};
34-
35-
private static readonly Type[] KnownExtensionPointTypes =
36-
{
37-
typeof(IAgentLauncher),
38-
typeof(IDriverFactory),
39-
typeof(IProjectLoader),
40-
typeof(IResultWriter),
41-
typeof(ITestEventListener),
42-
typeof(IService),
43-
typeof(IFrameworkDriver)
44-
};
45-
46-
private static readonly int[] KnownExtensionPointCounts = { 1, 1, 1, 1, 2, 1, 0 };
47-
4825
private const string FAKE_AGENT_LAUNCHER_EXTENSION = "NUnit.Engine.Fakes.FakeAgentLauncherExtension";
4926
private const string FAKE_FRAMEWORK_DRIVER_EXTENSION = "NUnit.Engine.Fakes.FakeFrameworkDriverExtension";
5027
private const string FAKE_PROJECT_LOADER_EXTENSION = "NUnit.Engine.Fakes.FakeProjectLoaderExtension";
@@ -67,11 +44,50 @@ public class ExtensionManagerTests
6744
};
6845

6946
private ExtensionManager _extensionManager;
47+
private string _defaultTestExtensionPath;
48+
49+
private string[] _expectedExtensionPointPaths;
50+
private Type[] _expectedExtensionPointTypes;
51+
private int[] _expectedExtensionCounts;
52+
53+
public ExtensionManagerTests(string defaultTestExtensionPath)
54+
{
55+
Guard.ArgumentValid(
56+
defaultTestExtensionPath.StartsWith('/') && defaultTestExtensionPath.EndsWith('/'),
57+
"Path must start and end with '/'", nameof(defaultTestExtensionPath));
58+
59+
_defaultTestExtensionPath = defaultTestExtensionPath;
60+
var prefix = defaultTestExtensionPath ?? "/NUnit/Extensibility/TypeExtensions/";
61+
62+
_expectedExtensionPointPaths =
63+
[
64+
prefix + "IAgentLauncher",
65+
prefix + "IDriverFactory",
66+
prefix + "IProjectLoader",
67+
prefix + "IResultWriter",
68+
prefix + "ITestEventListener",
69+
prefix + "IService",
70+
"/NUnit/Engine/NUnitV2Driver"
71+
];
72+
73+
_expectedExtensionPointTypes =
74+
[
75+
typeof(IAgentLauncher),
76+
typeof(IDriverFactory),
77+
typeof(IProjectLoader),
78+
typeof(IResultWriter),
79+
typeof(ITestEventListener),
80+
typeof(IService),
81+
typeof(IFrameworkDriver)
82+
];
83+
84+
_expectedExtensionCounts = [1, 1, 1, 1, 2, 1, 0];
85+
}
7086

7187
[SetUp]
7288
public void CreateExtensionManager()
7389
{
74-
_extensionManager = new ExtensionManager();
90+
_extensionManager = new ExtensionManager() { TypeExtensionPath = _defaultTestExtensionPath };
7591

7692
// Find actual extension points.
7793
_extensionManager.FindExtensionPoints(typeof(ExtensionManager).Assembly);
@@ -86,7 +102,7 @@ public void CreateExtensionManager()
86102
public void AllKnownExtensionPointsAreFound()
87103
{
88104
Assert.That(_extensionManager.ExtensionPoints.Select(ep => ep.Path),
89-
Is.EquivalentTo(KnownExtensionPointPaths));
105+
Is.EquivalentTo(_expectedExtensionPointPaths));
90106
}
91107

92108
[Test]
@@ -115,37 +131,45 @@ public void AllKnownExtensionsAreEnabledAsRequired()
115131
}
116132
}
117133

118-
[Test, Sequential]
119-
public void CanGetExtensionPointByPath(
120-
[ValueSource(nameof(KnownExtensionPointPaths))] string path,
121-
[ValueSource(nameof(KnownExtensionPointTypes))] Type type)
134+
[Test]
135+
public void CanGetExtensionPointsByPath()
122136
{
123-
var ep = _extensionManager.GetExtensionPoint(path);
124-
Assert.That(ep, Is.Not.Null);
125-
Assert.That(ep.Path, Is.EqualTo(path));
126-
Assert.That(ep.TypeName, Is.EqualTo(type.FullName));
137+
for (int i = 0; i < _expectedExtensionPointPaths.Length; i++)
138+
{
139+
var path = _expectedExtensionPointPaths[i];
140+
var type = _expectedExtensionPointTypes[i];
141+
var ep = _extensionManager.GetExtensionPoint(path);
142+
Assert.That(ep, Is.Not.Null);
143+
Assert.That(ep.Path, Is.EqualTo(path));
144+
Assert.That(ep.TypeName, Is.EqualTo(type.FullName));
145+
}
127146
}
128147

129-
[Test, Sequential]
130-
public void CanGetExtensionPointByType(
131-
[ValueSource(nameof(KnownExtensionPointPaths))] string path,
132-
[ValueSource(nameof(KnownExtensionPointTypes))] Type type)
148+
[Test]
149+
public void CanGetExtensionPointByType()
133150
{
134-
var ep = _extensionManager.GetExtensionPoint(type);
135-
Assert.That(ep, Is.Not.Null);
136-
Assert.That(ep.Path, Is.EqualTo(path));
137-
Assert.That(ep.TypeName, Is.EqualTo(type.FullName));
151+
for (int i = 0; i < _expectedExtensionPointPaths.Length; i++)
152+
{
153+
var path = _expectedExtensionPointPaths[i];
154+
var type = _expectedExtensionPointTypes[i];
155+
var ep = _extensionManager.GetExtensionPoint(type);
156+
Assert.That(ep, Is.Not.Null);
157+
Assert.That(ep.Path, Is.EqualTo(path));
158+
Assert.That(ep.TypeName, Is.EqualTo(type.FullName));
159+
}
138160
}
139161

140-
[Test, Sequential]
141-
public void ExtensionsAreAddedToExtensionPoint(
142-
[ValueSource(nameof(KnownExtensionPointPaths))] string path,
143-
[ValueSource(nameof(KnownExtensionPointCounts))] int extensionCount)
162+
[Test]
163+
public void ExtensionsAreAddedToExtensionPoint()
144164
{
145-
var ep = _extensionManager.GetExtensionPoint(path);
146-
Assume.That(ep, Is.Not.Null);
147-
148-
Assert.That(ep.Extensions.Count, Is.EqualTo(extensionCount));
165+
for (int i = 0; i < _expectedExtensionPointPaths.Length; i++)
166+
{
167+
var path = _expectedExtensionPointPaths[i];
168+
var extensionCount = _expectedExtensionCounts[i];
169+
var ep = _extensionManager.GetExtensionPoint(path);
170+
Assume.That(ep, Is.Not.Null);
171+
Assert.That(ep.Extensions.Count, Is.EqualTo(extensionCount));
172+
}
149173
}
150174

151175
[Test]

src/NUnitCommon/nunit.extensibility/NUnitExtensibilityException.cs renamed to src/NUnitCommon/nunit.extensibility/ExtensibilityException.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@
66
namespace NUnit.Extensibility
77
{
88
/// <summary>
9-
/// NUnitEngineException is thrown when the engine has been
10-
/// called with improper values or when a particular facility
9+
/// ExtensibilityException is thrown when the extensibility features
10+
/// are used with improper values or when a particular feature
1111
/// is not available.
1212
/// </summary>
1313
[Serializable]
14-
public class NUnitExtensibilityException : Exception
14+
public class ExtensibilityException : Exception
1515
{
1616
/// <summary>
1717
/// Construct with a message
1818
/// </summary>
19-
public NUnitExtensibilityException(string message) : base(message)
19+
public ExtensibilityException(string message) : base(message)
2020
{
2121
}
2222

2323
/// <summary>
2424
/// Construct with a message and inner exception
2525
/// </summary>
26-
public NUnitExtensibilityException(string message, Exception? innerException) : base(message, innerException)
26+
public ExtensibilityException(string message, Exception? innerException) : base(message, innerException)
2727
{
2828
}
2929

3030
/// <summary>
3131
/// Serialization constructor
3232
/// </summary>
33-
public NUnitExtensibilityException(SerializationInfo info, StreamingContext context) : base(info, context)
33+
public ExtensibilityException(SerializationInfo info, StreamingContext context) : base(info, context)
3434
{
3535
}
3636
}

0 commit comments

Comments
 (0)