Skip to content

Commit

Permalink
Further changes that were not pushed to 1596
Browse files Browse the repository at this point in the history
  • Loading branch information
CharliePoole committed Jan 20, 2025
1 parent ff04e8e commit db7bb19
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace NUnit.Engine.Drivers
// Functional tests of the NUnitFrameworkDriver calling into the framework.
#if NETFRAMEWORK
[TestFixture("2009")]
[TestFixture("2018")]
#endif
[TestFixture("2018")]
public class NUnitFrameworkDriverTests
{
private const string MOCK_ASSEMBLY = "mock-assembly.dll";
Expand All @@ -26,13 +26,11 @@ public class NUnitFrameworkDriverTests
private NUnitFrameworkDriver _driver;
private string _mockAssemblyPath;

#if NETFRAMEWORK
private string _whichApi;
public NUnitFrameworkDriverTests(string whichApi)
{
_whichApi = whichApi;
}
#endif

[SetUp]
public void CreateDriver()
Expand Down Expand Up @@ -125,6 +123,23 @@ public void RunTestsAction_WithoutLoad_ThrowsInvalidOperationException()
Assert.That(ex.Message, Is.EqualTo(LOAD_MESSAGE));
}

[Test]
public void RunTestsAction_WithInvalidFilterElement_ThrowsException()
{
_driver.Load(_mockAssemblyPath, _settings);

var invalidFilter = "<filter><invalidElement>foo</invalidElement></filter>";
var ex = Assert.Catch(() => _driver.Run(new NullListener(), invalidFilter));

if (_whichApi == "2018")
{
Assert.That(ex, Is.TypeOf<TargetInvocationException>());
Assert.That(ex.InnerException, Is.TypeOf<ArgumentException>());
}
else
Assert.That(ex, Is.TypeOf<NUnitEngineException>());
}

#if NETFRAMEWORK
// Nested Class tests Api Selection in the driver
public class ApiSelectionTests()
Expand All @@ -146,23 +161,6 @@ public void CorrectApiIsSelected(string nunitVersion, string apiVersion)
}
}

[Test]
public void RunTestsAction_WithInvalidFilterElement_ThrowsException()
{
_driver.Load(_mockAssemblyPath, _settings);

var invalidFilter = "<filter><invalidElement>foo</invalidElement></filter>";
var ex = Assert.Catch(() => _driver.Run(new NullListener(), invalidFilter));

if (_whichApi == "2018")
{
Assert.That(ex, Is.TypeOf<TargetInvocationException>());
Assert.That(ex.InnerException, Is.TypeOf<ArgumentException>());
}
else
Assert.That(ex, Is.TypeOf<NUnitEngineException>());
}

private class CallbackEventHandler : System.Web.UI.ICallbackEventHandler
{
private string? _result;
Expand Down
2 changes: 1 addition & 1 deletion src/NUnitEngine/nunit.engine.core/Drivers/DriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public IFrameworkDriver GetDriver(AppDomain domain, TestPackage package, string

if (platform == "Silverlight" || platform == ".NETPortable" || platform == ".NETStandard" || platform == ".NETCompactFramework")
if (skipNonTestAssemblies)
return new SkippedAssemblyFrameworkDriver(assemblyPath, "X");
return new SkippedAssemblyFrameworkDriver(assemblyPath, package.ID);
else
return new InvalidAssemblyFrameworkDriver(assemblyPath, package.ID, platform +
" test assemblies are not supported by this version of the engine");
Expand Down
24 changes: 11 additions & 13 deletions src/NUnitEngine/nunit.engine.core/Drivers/NUnitFrameworkApi2009.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ public string Load(string testAssemblyPath, IDictionary<string, object> settings

try
{
_frameworkController = _testDomain.CreateInstanceAndUnwrap(
_nunitRef.FullName,
CONTROLLER_TYPE,
false,
0,
null,
new object[] { _testAssemblyPath, idPrefix, settings },
null,
null).ShouldNotBeNull();
_frameworkController = _testDomain.CreateInstanceAndUnwrap(
_nunitRef.FullName,
CONTROLLER_TYPE,
false,
0,
null,
new object[] { _testAssemblyPath, idPrefix, settings },
null,
null).ShouldNotBeNull();
}
catch (BadImageFormatException ex) when (requestedRuntime != null)
{
Expand Down Expand Up @@ -152,10 +152,8 @@ private object CreateObject(string typeName, params object?[]? args)
{
try
{
return _testDomain.CreateInstanceAndUnwrap(
_nunitRef.FullName, typeName, false, 0, null, args, null, null)!;
//return _testDomain.CreateInstanceAndUnwrap(
// _nunitRef.FullName, typeName, false, 0, null, args, null, null)!;
return _testDomain.CreateInstanceAndUnwrap(
_nunitRef.FullName, typeName, false, 0, null, args, null, null)!;
}
catch (TargetInvocationException ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class NUnitFrameworkApi2018 : NUnitFrameworkApi

#if NETCOREAPP
private TestAssemblyLoadContext? _assemblyLoadContext;
//private Assembly? _testAssembly;
private Assembly? _frameworkAssembly;
#endif

Expand All @@ -63,7 +62,7 @@ public string Load(string testAssemblyPath, IDictionary<string, object> settings
log.Info($"Loading {testAssemblyPath} - see separate log file");

_testAssemblyPath = Path.GetFullPath(testAssemblyPath);
var idPrefix = string.IsNullOrEmpty(_driverId) ? "" : _driverId + "-";
var idPrefix = _driverId + "-";

#if NETFRAMEWORK
try
Expand Down Expand Up @@ -236,10 +235,10 @@ private object ExecuteMethod(MethodInfo? method, params object?[] args)
#if NETFRAMEWORK
return method.Invoke(_frameworkController, args).ShouldNotBeNull();
#else
using (_assemblyLoadContext.ShouldNotBeNull().EnterContextualReflection())
{
return method.Invoke(_frameworkController, args).ShouldNotBeNull();
}
//using (_assemblyLoadContext.ShouldNotBeNull().EnterContextualReflection())
//{
return method.Invoke(_frameworkController, args).ShouldNotBeNull();
//}
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public NUnitFrameworkDriver(string id, AssemblyName nunitRef)
/// An id prefix that will be passed to the test framework and used as part of the
/// test ids created.
/// </summary>
public string ID { get; } = string.Empty;
public string ID { get; }

/// <summary>
/// Loads the tests in an assembly.
Expand Down
2 changes: 0 additions & 2 deletions src/NUnitEngine/nunit.engine.core/Runners/TestAgentRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ public virtual void Unload() { }
/// <returns>The count of test cases</returns>
public int CountTestCases(TestFilter filter)
{
GetLoadedDriver();

try
{
return GetLoadedDriver().CountTestCases(filter.Text);
Expand Down

0 comments on commit db7bb19

Please sign in to comment.