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
42 changes: 42 additions & 0 deletions src/NUnit.Engine.Api.Tests/ExtensionDirectoryApiTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt

using System;
using System.Collections.Generic;
using System.Reflection;
using NUnit.Framework;

namespace NUnit.Engine.Api
{
/// <summary>
/// Hosts give extension directories to the engine before it is initialized,
/// instead of adding them to the extension service and then telling it to
/// install. These tests pin that shape of the API.
/// </summary>
public class ExtensionDirectoryApiTests
{
[Test]
public void TestEngineHasExtensionDirectoriesList()
{
PropertyInfo property = typeof(ITestEngine).GetProperty("ExtensionDirectories");

Assert.That(property, Is.Not.Null, "ITestEngine.ExtensionDirectories is missing");
Assert.That(property.PropertyType, Is.EqualTo(typeof(IList<string>)));
Assert.That(property.CanRead, Is.True);
Assert.That(property.CanWrite, Is.False, "Hosts add to the list; they don't replace it");
}

[TestCase(nameof(IExtensionService.InstallExtensions), new Type[0])]
[TestCase(nameof(IExtensionService.FindExtensionAssemblies), new[] { typeof(string) })]
public void ExtensionServiceSetupMethodsAreObsolete(string name, Type[] parameters)
{
MethodInfo method = typeof(IExtensionService).GetMethod(name, parameters);
Assert.That(method, Is.Not.Null, $"IExtensionService.{name} is missing");

var obsolete = method.GetCustomAttribute<ObsoleteAttribute>();

Assert.That(obsolete, Is.Not.Null, $"IExtensionService.{name} is not marked [Obsolete]");
Assert.That(obsolete.IsError, Is.False, "Callers must keep compiling until 5.0");
Assert.That(obsolete.Message, Does.Contain("ITestEngine.ExtensionDirectories"));
}
}
}
17 changes: 11 additions & 6 deletions src/NUnit.Engine.Api/IExtensionService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt

using System;
using System.Collections.Generic;
using NUnit.Extensibility;

Expand Down Expand Up @@ -27,6 +28,12 @@ public interface IExtensionService
/// and using the contained '.addins' files to direct the search.
/// </summary>
/// <param name="initialDirectory">Path to the initial directory.</param>
/// <remarks>
/// Obsolete: add the directory to ITestEngine.ExtensionDirectories before the
/// engine is initialized. Once the engine has started, this method throws an
/// InvalidOperationException. It will be removed in 5.0.
/// </remarks>
[Obsolete("Add the directory to ITestEngine.ExtensionDirectories before the engine is initialized. This method will be removed in 5.0.")]
void FindExtensionAssemblies(string initialDirectory);

/// <summary>
Expand All @@ -47,15 +54,13 @@ public interface IExtensionService
void EnableExtension(string typeName, bool enabled);

/// <summary>
/// If extensions have not yet been installed, examine all candidate assemblies
/// and load them. Subsequent calls are ignored.
/// Does nothing. The engine installs all extensions when it is initialized,
/// including those in ITestEngine.ExtensionDirectories.
/// </summary>
/// <remarks>
/// We can only install extensions after all candidate assemblies are identified.
/// This method may be called by the user after all "Find" calls are complete.
/// If the user fails to call it and subsequently tries to examine extensions
/// using certain ExtensionManager methods, it is called automatically.
/// Obsolete: callers can simply remove the call. It will be removed in 5.0.
/// </remarks>
[Obsolete("Extensions are installed when the engine is initialized. Add extra directories to ITestEngine.ExtensionDirectories beforehand, and remove this call. This method will be removed in 5.0.")]
void InstallExtensions();

/// <summary>
Expand Down
16 changes: 16 additions & 0 deletions src/NUnit.Engine.Api/ITestEngine.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt

using System;
using System.Collections.Generic;

namespace NUnit.Engine
{
Expand Down Expand Up @@ -32,6 +33,21 @@ public interface ITestEngine : IDisposable
/// </summary>
InternalTraceLevel InternalTraceLevel { get; set; }

/// <summary>
/// Gets the list of additional directories in which the engine looks for
/// extensions, besides the folders it searches automatically. Add any
/// directories before the engine is initialized: when it initializes, it
/// adds the directories named in the NUNIT_EXTENSION_DIRECTORIES environment
/// variable, finds and installs all extensions, and makes the list read-only.
/// Adding to it afterwards throws an InvalidOperationException.
/// </summary>
/// <remarks>
/// Each directory is searched using the '.addins' files it contains.
/// Accessing <see cref="Services"/> initializes the engine if needed, so
/// add directories before using it.
/// </remarks>
IList<string> ExtensionDirectories { get; }

/// <summary>
/// Initialize the engine. This includes initializing mono addins,
/// setting the trace level and creating the standard set of services
Expand Down