Skip to content

Commit

Permalink
Initial implementation of nunit.agent.core (packaging NYI)
Browse files Browse the repository at this point in the history
  • Loading branch information
CharliePoole committed Feb 3, 2025
1 parent 03ccd89 commit abc42b0
Show file tree
Hide file tree
Showing 80 changed files with 220 additions and 125 deletions.
14 changes: 14 additions & 0 deletions NUnitConsole.sln
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunit.common", "src\NUnitCo
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nunit.common.tests", "src\NUnitCommon\nunit.common.tests\nunit.common.tests.csproj", "{6605DA54-EBF4-4ED1-B5BC-B607AD0CE308}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nunit.agent.core", "src\NUnitCommon\nunit.agent.core\nunit.agent.core.csproj", "{4FCFAF1C-1579-4A1C-BAF9-9627E39D7CDA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nunit.agent.core.tests", "src\NUnitCommon\nunit.agent.core.tests\nunit.agent.core.tests.csproj", "{89258A3E-5B62-487A-9AE7-D7672CBF61F1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -287,6 +291,14 @@ Global
{6605DA54-EBF4-4ED1-B5BC-B607AD0CE308}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6605DA54-EBF4-4ED1-B5BC-B607AD0CE308}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6605DA54-EBF4-4ED1-B5BC-B607AD0CE308}.Release|Any CPU.Build.0 = Release|Any CPU
{4FCFAF1C-1579-4A1C-BAF9-9627E39D7CDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4FCFAF1C-1579-4A1C-BAF9-9627E39D7CDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FCFAF1C-1579-4A1C-BAF9-9627E39D7CDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FCFAF1C-1579-4A1C-BAF9-9627E39D7CDA}.Release|Any CPU.Build.0 = Release|Any CPU
{89258A3E-5B62-487A-9AE7-D7672CBF61F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{89258A3E-5B62-487A-9AE7-D7672CBF61F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89258A3E-5B62-487A-9AE7-D7672CBF61F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89258A3E-5B62-487A-9AE7-D7672CBF61F1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -333,6 +345,8 @@ Global
{E2A4C099-E35D-4E27-B89D-957140ED970F} = {3B30D2E5-1587-4D68-B848-1BDDB3C24BFC}
{9D9CAD66-8EDF-4ED0-A222-503BE9B21EC7} = {3B30D2E5-1587-4D68-B848-1BDDB3C24BFC}
{6605DA54-EBF4-4ED1-B5BC-B607AD0CE308} = {3B30D2E5-1587-4D68-B848-1BDDB3C24BFC}
{4FCFAF1C-1579-4A1C-BAF9-9627E39D7CDA} = {3B30D2E5-1587-4D68-B848-1BDDB3C24BFC}
{89258A3E-5B62-487A-9AE7-D7672CBF61F1} = {3B30D2E5-1587-4D68-B848-1BDDB3C24BFC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D8E4FC26-5422-4C51-8BBC-D1AC0A578711}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt

using System;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using NUnit.Engine.Drivers;
using NUnit.Engine.Extensibility;

namespace NUnit.Engine.Services
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void SetUp()
[TestCase(4, ExpectedResult = true)]
public bool SupportsNetFramework(int majorVersion)
{
AssemblyName name = new AssemblyName(NUnit3DriverFactory.NUNIT_FRAMEWORK)
AssemblyName name = new AssemblyName("nunit.framework")
{
Version = new Version(majorVersion, 0)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using NUnit.TestData.Assemblies;
using NUnit.Framework;
using NUnit.Framework.Internal;
using NUnit.Engine.Internal;

namespace NUnit.Engine.Drivers
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt

using NUnit.Engine.Drivers;
using System;

namespace NUnit.Engine.Runners
{
internal class FakeTestAgentRunner : Engine.Runners.TestAgentRunner
internal class FakeTestAgentRunner : TestAgentRunner
{
public FakeTestAgentRunner(TestPackage package) : base(package)
public FakeTestAgentRunner(TestPackage package, IDriverService? driverService = null) : base(package)
{
TestDomain = AppDomain.CurrentDomain;
DriverService = driverService;
}

public new void Load()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ public void Initialize()
string.Empty,
false).ReturnsForAnyArgs(_driver);

_runner = new FakeTestAgentRunner(new TestPackage("mock-assembly.dll").SubPackages[0])
{
DriverService = driverService
};
_runner = new FakeTestAgentRunner(new TestPackage("mock-assembly.dll").SubPackages[0], driverService);
}

[TearDown]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net462;net8.0</TargetFrameworks>
<ExposedInternals>true</ExposedInternals>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net462' OR '$(TargetFramework)'=='net6.0' OR '$(TargetFramework)'=='net8.0'">
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnitLite" Version="4.2.2" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='netcoreapp3.1'">
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnitLite" Version="3.14.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="NUnit.Analyzers" Version="4.5.0" />
<PackageReference Include="NSubstitute" Version="4.3.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net462'">
<Reference Include="System.Configuration" />
<Reference Include="System.Runtime.Remoting" />
<Reference Include="System.Web" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\TestData\mock-assembly\mock-assembly.csproj" />
<ProjectReference Include="..\nunit.agent.core\nunit.agent.core.csproj" />
<ProjectReference Include="..\nunit.common\nunit.common.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Runtime.Remoting.Channels.Tcp;
using System.Threading;
using NUnit.Engine.Agents;
using NUnit.Engine.Internal;

namespace NUnit.Engine.Communication.Transports.Remoting
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Net.Sockets;
using System.Threading;
using NUnit.Engine.Agents;
using NUnit.Engine.Internal;
using NUnit.Engine.Communication.Messages;
using NUnit.Engine.Communication.Protocols;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.IO;
using System.Reflection;
using NUnit.Engine.Extensibility;
using NUnit.Engine.Internal;
using TestCentric.Metadata;

namespace NUnit.Engine.Drivers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Reflection;
using NUnit.Engine.Extensibility;
using NUnit.Engine.Internal;
using NUnit.Extensibility;

namespace NUnit.Engine.Drivers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Reflection;
using NUnit.Engine.Extensibility;
using NUnit.Engine.Internal;

namespace NUnit.Engine.Drivers
{
Expand Down Expand Up @@ -46,7 +45,7 @@ public IFrameworkDriver GetDriver(AppDomain domain, string id, AssemblyName refe
public IFrameworkDriver GetDriver(string id, AssemblyName reference)
{
Guard.ArgumentNotNullOrEmpty(id, nameof(id));
Guard.ArgumentValid(IsSupportedTestFramework(reference), "Invalid framework", "reference");
Guard.ArgumentValid(IsSupportedTestFramework(reference), "Invalid framework", nameof(reference));
log.Info("Using NUnitFrameworkDriver");
return new NUnitFrameworkDriver(id, reference);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
using System.IO;
using System.Reflection;
using System.Runtime.Serialization;
using NUnit.Engine.Internal;

namespace NUnit.Engine.Drivers
{
/// <summary>
/// This is the original NUnit 3 API, which only works for .NET Framework.
/// As far as I can discover, it first appeared in pre-release 2.9.1,
/// on launchpad in 2009, hence the name.
/// </summary>
class NUnitFrameworkApi2009 : NUnitFrameworkApi
/// <summary>
/// This is the original NUnit 3 API, which only works for .NET Framework.
/// As far as I can discover, it first appeared in pre-release 2.9.1,
/// on launchpad in 2009, hence the name.
/// </summary>
class NUnitFrameworkApi2009 : NUnitFrameworkApi
{
static readonly Logger log = InternalTrace.GetLogger(nameof(NUnitFrameworkApi2009));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
using System.Collections.Generic;
using System.IO;
using System.Reflection;

#if NETCOREAPP
using NUnit.Engine.Internal;
#endif

namespace NUnit.Engine.Drivers
{
Expand Down Expand Up @@ -56,7 +59,7 @@ public string Load(string testAssemblyPath, IDictionary<string, object> settings
{
Guard.ArgumentNotNull(testAssemblyPath, nameof(testAssemblyPath));
Guard.ArgumentNotNull(settings, nameof(settings));
Guard.ArgumentValid(File.Exists(testAssemblyPath), "Framework driver called with a file name that doesn't exist.", "testAssemblyPath");
Guard.ArgumentValid(File.Exists(testAssemblyPath), "Framework driver called with a file name that doesn't exist.", nameof(testAssemblyPath));
log.Info($"Loading {testAssemblyPath} - see separate log file");

_testAssemblyPath = Path.GetFullPath(testAssemblyPath);
Expand All @@ -67,15 +70,15 @@ public string Load(string testAssemblyPath, IDictionary<string, object> settings
{
_frameworkController = AppDomain.CurrentDomain.CreateInstanceAndUnwrap(
_nunitRef.FullName,
CONTROLLER_TYPE,
false,
0,
null,
new object[] { _testAssemblyPath, idPrefix, settings },
null,
CONTROLLER_TYPE,
false,
0,
null,
new object[] { _testAssemblyPath, idPrefix, settings },
null,
null).ShouldNotBeNull();
}
catch (Exception ex)
catch (Exception ex)
{
string msg = $"Failed to load {_nunitRef.FullName}\r\n Codebase: {_nunitRef.CodeBase}";
throw new Exception(msg, ex);
Expand Down Expand Up @@ -119,14 +122,14 @@ public string Run(ITestEventListener? listener, string filter)
CheckLoadWasCalled();
log.Info("Running {0} - see separate log file", Path.GetFileName(_testAssemblyPath.ShouldNotBeNull()));
Action<string>? callback = null;
return (string)ExecuteMethod(RUN_METHOD, new[] { typeof(Action<string>), typeof(string) }, callback, filter);
return (string)ExecuteMethod(RUN_METHOD, [typeof(Action<string>), typeof(string)], callback, filter);
}

public void RunAsync(Action<string> callback, string filter)
{
CheckLoadWasCalled();
log.Info("Running {0} - see separate log file", Path.GetFileName(_testAssemblyPath.ShouldNotBeNull()));
ExecuteMethod(RUN_ASYNC_METHOD, new[] { typeof(Action<string>), typeof(string) }, callback, filter);
ExecuteMethod(RUN_ASYNC_METHOD, [typeof(Action<string>), typeof(string)], callback, filter);
}

public void StopRun(bool force)
Expand Down Expand Up @@ -187,7 +190,6 @@ private Assembly LoadAssembly(AssemblyName assemblyName)
}
catch (Exception e)
{
var msg = string.Format(FAILED_TO_LOAD_ASSEMBLY + assemblyName.FullName);
log.Error($"{FAILED_TO_LOAD_ASSEMBLY}\r\n{e}");
throw new NUnitEngineException(FAILED_TO_LOAD_NUNIT, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using NUnit.Engine.Internal;
using NUnit.Engine;
using NUnit.Engine.Extensibility;

namespace NUnit.Engine.Drivers
Expand All @@ -14,7 +14,7 @@ namespace NUnit.Engine.Drivers
/// </summary>
public class NUnitFrameworkDriver : IFrameworkDriver
{
static readonly Version MINIMUM_NUNIT_VERSION = new Version(3, 2, 0);
static readonly Version MINIMUM_NUNIT_VERSION = new(3, 2, 0);
static readonly Logger log = InternalTrace.GetLogger(nameof(NUnitFrameworkDriver));

readonly NUnitFrameworkApi _api;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.IO;
using System.Diagnostics;

namespace NUnit.Engine.Internal
namespace NUnit.Engine.Drivers
{
public class ProvidedPathsAssemblyResolver
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Reflection;
using System.Text;

namespace NUnit.Engine.Internal
namespace NUnit.Engine
{
/// <summary>
/// DomainDetailsBuilder provides human readable information on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System.Security;
using System.Security.Policy;
using System.Security.Principal;
using NUnit.Engine.Internal;
using System.Linq;

namespace NUnit.Engine.Runners
Expand Down Expand Up @@ -83,7 +82,7 @@ AppDomainSetup CreateAppDomainSetup(TestPackage package)
// If property is null, .NET 4.5+ is not installed, so there is no need
if (TargetFrameworkNameProperty != null)
{
var frameworkName = package.GetSetting(InternalEnginePackageSettings.ImageTargetFrameworkName, "");
var frameworkName = package.GetSetting(EnginePackageSettings.ImageTargetFrameworkName, "");
if (frameworkName != "")
TargetFrameworkNameProperty.SetValue(setup, frameworkName, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Linq;
using NUnit.Engine.Drivers;
using NUnit.Engine.Extensibility;
using NUnit.Engine.Internal;

namespace NUnit.Engine.Runners
{
Expand All @@ -24,7 +23,7 @@ public abstract class TestAgentRunner : ITestEngineRunner
protected AppDomain? TestDomain { get; set; }

// Used to inject DriverService for testing
internal IDriverService? DriverService { get; set; }
protected IDriverService? DriverService { get; set; }

/// <summary>
/// The TestPackage for which this is the runner
Expand Down Expand Up @@ -101,11 +100,11 @@ public virtual TestEngineResult Load()

var testFile = assemblyPackage.FullName!; // We know it's an assembly

string? targetFramework = assemblyPackage.GetSetting(InternalEnginePackageSettings.ImageTargetFrameworkName, (string?)null);
string? targetFramework = assemblyPackage.GetSetting(EnginePackageSettings.ImageTargetFrameworkName, (string?)null);
bool skipNonTestAssemblies = assemblyPackage.GetSetting(EnginePackageSettings.SkipNonTestAssemblies, false);

if (_assemblyResolver != null && !TestDomain.IsDefaultAppDomain()
&& assemblyPackage.GetSetting(InternalEnginePackageSettings.ImageRequiresDefaultAppDomainAssemblyResolver, false))
&& assemblyPackage.GetSetting(EnginePackageSettings.ImageRequiresDefaultAppDomainAssemblyResolver, false))
{
// It's OK to do this in the loop because the Add method
// checks to see if the path is already present.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;

namespace NUnit.Engine.Internal
namespace NUnit.Engine
{
public delegate bool TestPackageSelectorDelegate(TestPackage p);

Expand Down
Loading

0 comments on commit abc42b0

Please sign in to comment.