Skip to content

Commit

Permalink
Replace use of ReflectionOnlyLoad as well as AssemblyReader class by …
Browse files Browse the repository at this point in the history
…using mono.cecil.
  • Loading branch information
CharliePoole committed Aug 5, 2015
1 parent 12d6888 commit 6671ba5
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 440 deletions.
9 changes: 9 additions & 0 deletions nunit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nunit.framework.tests-porta
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nunitlite.runner-portable", "src\NUnitFramework\nunitlite.runner\nunitlite.runner-portable.csproj", "{D339BFC2-AF3F-46FA-899A-14BAD4BCA35B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "targets", "targets", "{2821D6DA-4F95-4002-BC35-00E8B7F9961A}"
ProjectSection(SolutionItems) = preProject
targets\Build.Targets = targets\Build.Targets
targets\Common.Properties = targets\Common.Properties
targets\Packaging.Targets = targets\Packaging.Targets
targets\Testing.Targets = targets\Testing.Targets
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -354,6 +362,7 @@ Global
{A4F0C741-6ED4-46C8-AE75-57E1C7197E22} = {A21BFC37-44FC-41A0-B6E7-6F949F45A635}
{C4D16DF1-B6FA-42F5-834E-B01DA1BAA1FF} = {A21BFC37-44FC-41A0-B6E7-6F949F45A635}
{A972031D-2F61-4183-AF75-99EE1A9F6B32} = {49D441DF-39FD-4F4D-AECA-86CF8EFE23AF}
{2821D6DA-4F95-4002-BC35-00E8B7F9961A} = {49D441DF-39FD-4F4D-AECA-86CF8EFE23AF}
{775FAD50-3623-4922-97C4-DFB29A8BE4C7} = {31B45C4C-206F-4F31-9CC6-33BF11DFEE39}
{372A3447-D657-40FF-A089-77C19FEC30C8} = {31B45C4C-206F-4F31-9CC6-33BF11DFEE39}
{D694CB69-6CFB-4762-86C2-EB27B808B282} = {31B45C4C-206F-4F31-9CC6-33BF11DFEE39}
Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions packages/repositories.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<repository path="../src/NUnitFramework/tests/packages.config" />
<repository path="..\src\NUnitEngine\Addins\nunit.v2.driver.tests\packages.config" />
<repository path="..\src\NUnitEngine\mock-v2-assembly\packages.config" />
<repository path="..\src\NUnitEngine\nunit.core.engine\packages.config" />
<repository path="..\src\NUnitEngine\nunit.engine\packages.config" />
<repository path="..\src\NUnitEngine\nunit.v2.driver.tests\packages.config" />
<repository path="..\src\NUnitFramework\testdata\packages.config" />
<repository path="..\src\NUnitFramework\tests\packages.config" />
Expand Down
17 changes: 9 additions & 8 deletions src/NUnitEngine/Addins/nunit.v2.driver/NUnit2DriverFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,26 @@ public class NUnit2DriverFactory : IDriverFactory
private const string NUNITLITE_FRAMEWORK = "nunitlite";

/// <summary>
/// Gets a flag indicating whether a given AssemblyName
/// represents a test framework supported by this factory.
/// Gets a flag indicating whether a given assembly name and version
/// represent a test framework supported by this factory.
/// </summary>
public bool IsSupportedFramework(AssemblyName reference)
public bool IsSupportedTestFramework(string assemblyName, Version version)
{
return reference.Name == NUNIT_FRAMEWORK && reference.Version.Major == 2
|| reference.Name == NUNITLITE_FRAMEWORK && reference.Version.Major == 1;
return assemblyName == NUNIT_FRAMEWORK && version.Major == 2
|| assemblyName == NUNITLITE_FRAMEWORK && version.Major == 1;
}

/// <summary>
/// Gets a driver for a given test assembly and a framework
/// which the assembly is already known to reference.
/// </summary>
/// <param name="domain">The domain in which the assembly will be loaded</param>
/// <param name="frameworkReference">The name of the test framework reference</param>
/// <param name="assemblyName">The name of the test framework reference</param>
/// <param name="version">The version of the test framework reference</param>
/// <returns></returns>
public IFrameworkDriver GetDriver(AppDomain domain, AssemblyName frameworkReference)
public IFrameworkDriver GetDriver(AppDomain domain, string assemblyName, Version version)
{
if (!IsSupportedFramework(frameworkReference))
if (!IsSupportedTestFramework(assemblyName, version))
throw new ArgumentException("Invalid framework name", "frameworkAssemblyName");

return new NUnit2FrameworkDriver(domain);
Expand Down
15 changes: 15 additions & 0 deletions src/NUnitEngine/nunit.core.engine/nunit.core.engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@
<NoWarn>1685</NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Mono.Cecil.0.9.6.1\lib\net20\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Mdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Mono.Cecil.0.9.6.1\lib\net20\Mono.Cecil.Mdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Pdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Mono.Cecil.0.9.6.1\lib\net20\Mono.Cecil.Pdb.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
Expand Down Expand Up @@ -202,6 +214,9 @@
<Folder Include="Agents\" />
<Folder Include="Services\ResultWriters\" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
4 changes: 4 additions & 0 deletions src/NUnitEngine/nunit.core.engine/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Mono.Cecil" version="0.9.6.1" targetFramework="net20" />
</packages>
11 changes: 6 additions & 5 deletions src/NUnitEngine/nunit.engine.api/Extensibility/IDriverFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ namespace NUnit.Engine.Extensibility
public interface IDriverFactory
{
/// <summary>
/// Gets a flag indicating whether a given AssemblyName
/// represents a test framework supported by this factory.
/// Gets a flag indicating whether a given assembly name and version
/// represent a test framework supported by this factory.
/// </summary>
bool IsSupportedFramework(AssemblyName refAssembly);
bool IsSupportedTestFramework(string assemblyName, Version version);

/// <summary>
/// Gets a driver for a given test assembly and a framework
/// which the assembly is already known to reference.
/// </summary>
/// <param name="domain">The domain in which the assembly will be loaded</param>
/// <param name="frameworkReference">The AssemblyName of the test framework reference</param>
/// <param name="assemblyName">The Name of the test framework reference</param>
/// <param name="version">The version of the test framework reference</param>
/// <returns></returns>
IFrameworkDriver GetDriver(AppDomain domain, AssemblyName frameworkReference);
IFrameworkDriver GetDriver(AppDomain domain, string assemblyName, Version version);
}
}
130 changes: 0 additions & 130 deletions src/NUnitEngine/nunit.engine.tests/Internal/AssemblyReaderTests.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,37 @@ public void CreateServiceContext()
services.ServiceManager.StartServices();
}

[TearDown]
public void StopService()
{
_runtimeService.StopService();
}

[Test]
public void ServiceIsStarted()
{
Assert.That(_runtimeService.Status, Is.EqualTo(ServiceStatus.Started));
}

[TestCase("mock-nunit-assembly.exe", "net-2.0", false)]
[TestCase("net-2.0/mock-nunit-assembly.exe", "net-2.0", false)]
[TestCase("net-4.0/mock-nunit-assembly.exe", "net-4.0", false)]
// TODO: Change this case when the 4.0/4.5 bug is fixed
[TestCase("net-4.5/mock-nunit-assembly.exe", "net-4.0", false)]
[TestCase("mock-cpp-clr-x64.dll", "net-4.0", false)]
[TestCase("mock-cpp-clr-x86.dll", "net-4.0", true)]
[TestCase("nunit-agent.exe", "net-2.0", false)]
[TestCase("nunit-agent-x86.exe", "net-2.0", true)]
// TODO: Make the following cases work correctly in case we want to use
// the engine to run them in the future.
[TestCase("netcf-3.5/mock-nunit-assembly.exe", "net-2.0", false)]
[TestCase("sl-5.0/mock-nunit-assembly.dll", "net-4.0", false)]
[TestCase("portable/mock-nunit-assembly.dll", "net-4.0", false)]
public void SelectRuntimeFramework(string assemblyName, string expectedRuntime, bool runAsX86)
{
var package = new TestPackage(assemblyName);
Assert.That(_runtimeService.SelectRuntimeFramework(package), Is.EqualTo(expectedRuntime));
Assert.That(package.GetSetting("RunAsX86", false), Is.EqualTo(runAsX86));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
<Compile Include="Api\TestFilterTests.cs" />
<Compile Include="Api\TestPackageTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Internal\AssemblyReaderTests.cs" />
<Compile Include="Drivers\NotRunnableFrameworkDriverTests.cs" />
<Compile Include="Drivers\NUnit3FrameworkDriverTests.cs" />
<Compile Include="Internal\PathUtilTests.cs" />
Expand Down
17 changes: 9 additions & 8 deletions src/NUnitEngine/nunit.engine/Drivers/NUnit3DriverFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,26 @@ public class NUnit3DriverFactory : IDriverFactory
private const string NUNIT_FRAMEWORK = "nunit.framework";

/// <summary>
/// Gets a flag indicating whether a given AssemblyName
/// represents a test framework supported by this factory.
/// Gets a flag indicating whether a given assembly name and version
/// represent a test framework supported by this factory.
/// </summary>
public bool IsSupportedFramework(AssemblyName reference)
public bool IsSupportedTestFramework(string assemblyName, Version version)
{
return reference.Name == NUNIT_FRAMEWORK && reference.Version.Major == 3;
return assemblyName == NUNIT_FRAMEWORK && version.Major == 3;
}

/// <summary>
/// Gets a driver for a given test assembly and a framework
/// which the assembly is already known to reference.
/// </summary>
/// <param name="domain">The domain in which the assembly will be loaded</param>
/// <param name="frameworkReference">The AssemblyName of the test framework reference</param>
/// <param name="assemblyName">The Name of the test framework reference</param>
/// <param name="version">The version of the test framework reference</param>
/// <returns></returns>
public IFrameworkDriver GetDriver(AppDomain domain, AssemblyName frameworkReference)
public IFrameworkDriver GetDriver(AppDomain domain, string assemblyName, Version version)
{
Guard.ArgumentValid(IsSupportedFramework(frameworkReference), "Invalid framework name", "frameworkAssemblyName");
Guard.ArgumentValid(IsSupportedTestFramework(assemblyName, version), "Invalid framework name", "frameworkAssemblyName");

return new NUnit3FrameworkDriver(domain);
}
}
Expand Down
Loading

0 comments on commit 6671ba5

Please sign in to comment.