Skip to content

Commit

Permalink
Misc Test improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisMaddock committed Aug 18, 2018
1 parent ea6ed51 commit d37abbe
Showing 1 changed file with 14 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
// ***********************************************************************

using System;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
using NUnit.Engine.Extensibility;
Expand All @@ -33,12 +34,6 @@ public class ExtensionServiceTests
private ExtensionService _serviceClass;
private IExtensionService _serviceInterface;


// NOTE: Some of these tests depend on certain extensions being built
// at the same time as NUnit and therefore being present in the addins
// directory. As extensions are moved out to separate builds, we will
// need to modify those tests.

#pragma warning disable 414
private static readonly string[] KNOWN_EXTENSION_POINT_PATHS = new string[] {
"/NUnit/Engine/TypeExtensions/IDriverFactory",
Expand Down Expand Up @@ -72,40 +67,25 @@ public void CreateService()
_serviceClass.FindExtensionPoints(typeof(TestEngine).Assembly);
_serviceClass.FindExtensionPoints(typeof(ITestEngine).Assembly);

_serviceClass.FindExtensionsInAssembly(new ExtensionAssembly(GetType().Assembly.Location, true));
_serviceClass.FindExtensionsInAssembly(new ExtensionAssembly(GetType().Assembly.Location, false));
}

[TestCaseSource("KNOWN_EXTENSION_POINT_PATHS")]
[TestCaseSource(nameof(KNOWN_EXTENSION_POINT_PATHS))]
public void CanListExtensionPoints(string path)
{
foreach (var ep in _serviceInterface.ExtensionPoints)
if (ep.Path == path)
return;

Assert.Fail("Couldn't find known ExtensionPoint {0}", path);
Assert.That(_serviceInterface.ExtensionPoints.Select(ep => ep.Path), Does.Contain(path));
}

[Test]
public void AllExtensionPointsAreKnown()
{
foreach (var ep in _serviceInterface.ExtensionPoints)
{
var known = false;
foreach (var path in KNOWN_EXTENSION_POINT_PATHS)
if (path == ep.Path)
{
known = true;
break;
}
if (!known)
Assert.Fail("Unknown ExtensionPoint {0}", ep.Path);
}
Assert.That(_serviceInterface.ExtensionPoints.Select(ep => ep.Path), Is.EquivalentTo(KNOWN_EXTENSION_POINT_PATHS));
}

[Test, Sequential]
public void CanGetExtensionPointByPath(
[ValueSource("KNOWN_EXTENSION_POINT_PATHS")] string path,
[ValueSource("KNOWN_EXTENSION_POINT_TYPES")] Type type)
[ValueSource(nameof(KNOWN_EXTENSION_POINT_PATHS))] string path,
[ValueSource(nameof(KNOWN_EXTENSION_POINT_TYPES))] Type type)
{
var ep = _serviceInterface.GetExtensionPoint(path);
Assert.NotNull(ep);
Expand All @@ -115,8 +95,8 @@ public void CanGetExtensionPointByPath(

[Test, Sequential]
public void CanGetExtensionPointByType(
[ValueSource("KNOWN_EXTENSION_POINT_PATHS")] string path,
[ValueSource("KNOWN_EXTENSION_POINT_TYPES")] Type type)
[ValueSource(nameof(KNOWN_EXTENSION_POINT_PATHS))] string path,
[ValueSource(nameof(KNOWN_EXTENSION_POINT_TYPES))] Type type)
{
var ep = _serviceClass.GetExtensionPoint(type);
Assert.NotNull(ep);
Expand All @@ -135,23 +115,25 @@ public void CanGetExtensionPointByType(
};
#pragma warning restore 414

[TestCaseSource("KNOWN_EXTENSIONS")]
[TestCaseSource(nameof(KNOWN_EXTENSIONS))]
public void CanListExtensions(string typeName)
{
foreach (IExtensionNode node in _serviceClass.Extensions)
{
if (node.TypeName == typeName)
{
Assert.True(node.Enabled);
return;
}
}

Assert.Fail("Couldn't find known Extension {0}", typeName);
}

[Test, Sequential]
public void ExtensionsAreAddedToExtensionPoint(
[ValueSource("KNOWN_EXTENSION_POINT_PATHS")] string path,
[ValueSource("KNOWN_EXTENSION_POINT_COUNTS")] int extensionCount)
[ValueSource(nameof(KNOWN_EXTENSION_POINT_PATHS))] string path,
[ValueSource(nameof(KNOWN_EXTENSION_POINT_COUNTS))] int extensionCount)
{
var ep = _serviceClass.GetExtensionPoint(path);
Assume.That(ep, Is.Not.Null);
Expand Down

0 comments on commit d37abbe

Please sign in to comment.