Skip to content

Commit

Permalink
Merge pull request #662 from TestCentric/issue-661
Browse files Browse the repository at this point in the history
Disable running in process unless all assemblies are .NET Framework
  • Loading branch information
CharliePoole authored Jan 14, 2021
2 parents daee8ae + e1cca4e commit e68d428
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/Common/testcentric.common.tests/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public void ValidOptionsAreRecognized(string propertyName, string option, object
Assert.That(property.GetValue(options, null), Is.EqualTo(expected));
}

//[TestCase("--config")]
[TestCase("--process")]
[TestCase("--agents")]
[TestCase("--domain")]
Expand All @@ -100,7 +99,6 @@ public void InvalidOptionsAreDetectedByMonoOptions(string option)
[TestCase("--garbage")]
[TestCase("--process:Unknown")]
[TestCase("--agents:XYZ")]
[TestCase("--domain:Junk")]
[TestCase("--trace:Something")]
public void InvalidOptionsAreDetected(string option)
{
Expand Down
14 changes: 13 additions & 1 deletion src/Common/testcentric.common/TestPackageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Licensed under the MIT License. See LICENSE.txt in root directory.
// ***********************************************************************

using System;
using System.Runtime.Versioning;
using System.Collections.Generic;
using NUnit.Engine;

Expand Down Expand Up @@ -80,6 +80,18 @@ public static bool HasImageTargetFrameworkName(this TestPackage package)
return HasSetting(package, EnginePackageSettings.ImageTargetFrameworkName);
}

public static bool IsNetFrameworkPackage(this TestPackage package)
{
return !HasImageTargetFrameworkName(package) // Implies .NET 2.0 or lower
|| new FrameworkName(GetImageTargetFrameworkName(package)).Identifier == ".NETFramework";
}

public static bool IsNetCorePackage(this TestPackage package)
{
return HasImageTargetFrameworkName(package)
&& new FrameworkName(GetImageTargetFrameworkName(package)).Identifier == ".NETCoreApp";
}

public static bool HasSetting(this TestPackage package, string name)
{
return package.Settings.ContainsKey(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ private void UpdateViewCommands(bool testLoading = false)
_view.RecentFilesMenu.Enabled = !testRunning && !testLoading;
_view.ExitCommand.Enabled = !testLoading;
_view.SaveResultsCommand.Enabled = _view.SaveResultsAsMenu.Enabled = !testRunning && !testLoading && _model.HasResults;
_view.RunInProcess.Enabled = testLoaded && _model.TestPackage.IsNetFrameworkPackage();
}

private string CreateOpenFileFilter()
Expand Down
1 change: 1 addition & 0 deletions src/TestCentric/testcentric.gui/Views/IMainView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public interface IMainView
ICommand ReloadTestsCommand { get; }
IToolStripMenu RuntimeMenu { get; }
ISelection ProcessModel { get; }
IChecked RunInProcess { get; }
IChecked RunAsX86 { get; }
ISelection DomainUsage { get; }
IToolStripMenu RecentFilesMenu { get; }
Expand Down
2 changes: 2 additions & 0 deletions src/TestCentric/testcentric.gui/Views/TestCentricMainView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public TestCentricMainView() : base("TestCentric")
//SelectedRuntime = new CheckedMenuGroup(runtimeMenuItem);
ProcessModel = new CheckedToolStripMenuGroup("Process Model",
defaultProcessMenuItem, inProcessMenuItem, singleProcessMenuItem, multipleProcessMenuItem);
RunInProcess = new ToolStripMenuElement(inProcessMenuItem);
DomainUsage = new CheckedToolStripMenuGroup("Domain Usage",
defaultDomainMenuItem, singleDomainMenuItem, multipleDomainMenuItem);
RunAsX86 = new ToolStripMenuElement(runAsX86MenuItem);
Expand Down Expand Up @@ -1103,6 +1104,7 @@ public int SplitterPosition
public ICommand ReloadTestsCommand { get; }
public IToolStripMenu RuntimeMenu { get; }
public ISelection ProcessModel { get; private set; }
public IChecked RunInProcess { get; private set; }
public IChecked RunAsX86 { get; private set; }
public ISelection DomainUsage { get; private set; }
public IToolStripMenu RecentFilesMenu { get; }
Expand Down
1 change: 1 addition & 0 deletions src/TestCentric/tests/Presenters/Main/WhenTestRunBegins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ protected void SimulateTestRunStarting()

_model.HasTests.Returns(true);
_model.IsTestRunning.Returns(true);
_model.TestPackage.Returns(new NUnit.Engine.TestPackage("dummy.dll"));
FireRunStartingEvent(1234);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public void SimulateTestRunFinish()
_model.HasTests.Returns(true);
_model.HasResults.Returns(true);
_model.IsTestRunning.Returns(false);
_model.TestPackage.Returns(new NUnit.Engine.TestPackage("dummy.dll"));

var resultNode = new ResultNode("<test-run/>");
FireRunFinishedEvent(resultNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void SimulateTestLoad()

_model.HasTests.Returns(true);
_model.IsTestRunning.Returns(false);
_model.TestPackage.Returns(new NUnit.Engine.TestPackage("dummy.dll"));

TestNode testNode = new TestNode("<test-suite id='1'/>");
_model.Tests.Returns(testNode);
Expand Down
2 changes: 2 additions & 0 deletions src/TestCentric/tests/Presenters/Main/WhenTestsAreReloaded.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public void SimulateTestLoad()

TestNode testNode = new TestNode("<test-suite id='1'/>");
_model.Tests.Returns(testNode);
_model.TestPackage.Returns(new NUnit.Engine.TestPackage("dummy.dll"));

FireTestReloadedEvent(testNode);
}

Expand Down

0 comments on commit e68d428

Please sign in to comment.