Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ILMerge.Tests/BaselineTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System.Reflection;
using NUnit.Framework;
using TestTools;
using System.Diagnostics.CodeAnalysis;

namespace ILMerging.Tests
{
[ExcludeFromCodeCoverage]
[TestFixture]
public sealed class BaselineTests
{
Expand Down
1 change: 1 addition & 0 deletions ILMerge.Tests/ILMerge.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ItemGroup>
<ProjectReference Include="..\ILMerge\ILMerge.csproj" />
<ProjectReference Include="..\System.Compiler\System.Compiler.csproj" />
<ProjectReference Include="..\TestTools\TestTools.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion ILMerge.Tests/Integration/ConsoleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using ILMerging.Tests.Helpers;
using TestTools.Helpers;
using NUnit.Framework;
using System.Diagnostics.CodeAnalysis;

namespace ILMerging.Tests.Integration
{
[ExcludeFromCodeCoverage]
[TestFixture, Category("Integration")]
public sealed class ConsoleTests
{
Expand Down
5 changes: 4 additions & 1 deletion ILMerge.Tests/KeyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
using System.IO;
using System.Reflection;
using System.Security.Cryptography;
using ILMerging.Tests.Helpers;
using TestTools.Helpers;
using TestTools;
using NUnit.Framework;
using System.Diagnostics.CodeAnalysis;

namespace ILMerging.Tests
{
[ExcludeFromCodeCoverage]
[TestFixture]
public sealed class KeyTests
{
Expand Down
2 changes: 2 additions & 0 deletions ILMerge.Tests/TestFiles.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.IO;
using NUnit.Framework;
using System.Diagnostics.CodeAnalysis;

namespace ILMerging.Tests
{
[ExcludeFromCodeCoverage]
internal static class TestFiles
{
private static string FromCurrentDir(string fileName)
Expand Down
18 changes: 15 additions & 3 deletions ILMerge.sln
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.7
VisualStudioVersion = 15.0.26430.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILMerge", "ILMerge\ILMerge.csproj", "{84B41834-EFDE-4E52-A8CE-B51DFCB1D1B2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILMerge", "ILMerge\ILMerge.csproj", "{84B41834-EFDE-4E52-A8CE-B51DFCB1D1B2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Compiler", "System.Compiler\System.Compiler.csproj", "{D7E16B38-3893-4EEF-847F-A3BE807E9546}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILMerge.Tests", "ILMerge.Tests\ILMerge.Tests.csproj", "{734805E8-B2FB-41E3-A669-80429AA50C98}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILMerge.Tests", "ILMerge.Tests\ILMerge.Tests.csproj", "{734805E8-B2FB-41E3-A669-80429AA50C98}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B2EC5A7D-1059-4EC6-95FB-B2075609DF4B}"
ProjectSection(SolutionItems) = preProject
ilmerge-manual.md = ilmerge-manual.md
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILMergeMsTest.UnitTests", "ILMergeMsTest.UnitTests\ILMergeMsTest.UnitTests.csproj", "{E75D1760-E327-4709-892E-8CF522CACADB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestTools", "TestTools\TestTools.csproj", "{E0F0B234-A11A-43DC-9461-3B0184FA5E90}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -32,6 +36,14 @@ Global
{734805E8-B2FB-41E3-A669-80429AA50C98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{734805E8-B2FB-41E3-A669-80429AA50C98}.Release|Any CPU.ActiveCfg = Release|Any CPU
{734805E8-B2FB-41E3-A669-80429AA50C98}.Release|Any CPU.Build.0 = Release|Any CPU
{E75D1760-E327-4709-892E-8CF522CACADB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E75D1760-E327-4709-892E-8CF522CACADB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E75D1760-E327-4709-892E-8CF522CACADB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E75D1760-E327-4709-892E-8CF522CACADB}.Release|Any CPU.Build.0 = Release|Any CPU
{E0F0B234-A11A-43DC-9461-3B0184FA5E90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E0F0B234-A11A-43DC-9461-3B0184FA5E90}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0F0B234-A11A-43DC-9461-3B0184FA5E90}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E0F0B234-A11A-43DC-9461-3B0184FA5E90}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
37 changes: 37 additions & 0 deletions ILMergeMsTest.UnitTests/BaselineMSTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using ILMerging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using TestTools;

namespace ILMergeMsTest.UnitTests
{
[ExcludeFromCodeCoverage]
[TestClass]
public sealed class BaselineMSTests
{
#region Private Members
private const string Extension = ".dll";
private const string TestSnk = "test.snk";
private const string TestPfx = "test.pfx";
#endregion

#region Public Properties
public TestContext TestContext { get; set; }
#endregion

/// <summary>
/// Replicating the "Single_Input" NUnit test, using MSTest2.
/// Test output and working directory is within the generated "TestResults" folder - it is cleansed for all "Release" test runs,
/// and partially persists for "Debug" test runs (the NUnit tests are using the system's "Temp" directory, which is not preferable).
/// </summary>
/// <param name="withMscorsnInPath"></param>
[TestMethod]
public void Single_input()
{
var ilMerge = new ILMerge();
ilMerge.SetUpInputAssemblyForTest(Assembly.GetExecutingAssembly());
ilMerge.MergeToTempFileForTest(".dll");
}
}
}
80 changes: 80 additions & 0 deletions ILMergeMsTest.UnitTests/ConsoleMSTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using TestTools.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ILMerging;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace ILMergeMsTest.UnitTests
{
[ExcludeFromCodeCoverage]
[TestClass]
public sealed class ConsoleMSTests
{
#region Private Members
private const string Extension = ".dll";
private const string TestSnk = "test.snk";
private const string TestPfx = "test.pfx";
#endregion

#region Public Properties
public TestContext TestContext { get; set; }
#endregion

/// <summary>
/// Demonstrating MSTest2 DataRowAttribute usage,
/// that partially replicates nUnit TestFixture and TestCase functionality.
/// Test output and working directory is within the generated "TestResults" folder - it is cleansed for all "Release" test runs,
/// and partially persists for "Debug" test runs (the NUnit tests are using the system's "Temp" directory, which is not preferable).
/// </summary>
/// <param name="withMscorsnInPath"></param>
[TestMethod]
[TestCategory("Integration")]
[DeploymentItem("TestData")]
[DataRow(true, DisplayName = "(with mscorsn in path)")]
[DataRow(false, DisplayName = "(without mscorsn in path)")]
public void No_DLL_load_crashes_when_given_PFX(bool withMscorsnInPath)
{
// Inconclusive for non-64 Bit OS'
if (withMscorsnInPath && !Environment.Is64BitOperatingSystem) Assert.Inconclusive("This test can only be run on a 64-bit OS.");

// ARRANGE
var ilMergeExePath = typeof(ILMerge).Assembly.Location;
var inputAssembly = Assembly.GetExecutingAssembly();
var fileName = ShadowCopyUtils.GenerateILMergeLibCliSwitches(inputAssembly);
var outputFile = Path.Combine(TestContext.DeploymentDirectory,
Path.ChangeExtension(Path.GetRandomFileName(), Extension));

var startInfo = new ProcessStartInfo(
ilMergeExePath, $"{fileName} /keyfile:\"{TestPfx}\" /out:\"{outputFile}\" \"{inputAssembly.Location}\"")
{
WorkingDirectory = Path.GetDirectoryName(inputAssembly.Location)
};

if (withMscorsnInPath)
{
startInfo.EnvironmentVariables["PATH"] = $"{Environment.GetEnvironmentVariable("PATH")};{RuntimeEnvironment.GetRuntimeDirectory()}";
}

// ACT
// The system runs .NET executables as 64-bit no matter what the architecture of the calling process is.
var result = ProcessUtils.Run(startInfo);

// ASSERT
Assert.AreEqual(0, result.ExitCode);
Assert.IsFalse(result.ToString().Contains("Unable to load DLL 'mscorsn.dll'"));
Assert.IsFalse(result.ToString().Contains("An attempt was made to load a program with an incorrect format."));

// Test failures:
Assert.IsFalse(result.ToString().Contains("Unhandled Exception: System.IO.FileNotFoundException"),
"The test is not being run properly. If you are using ReSharper, disable shadow copy. " +
"If you are using NCrunch, go to NCrunch's configuration for the ILMerge project and " +
"make sure \"Copy referenced assemblies to workspace\" is set to True. " +
"(Both ReSharper and NCrunch settings are saved in the repo, so this should not happen.)");
}
}
}
89 changes: 89 additions & 0 deletions ILMergeMsTest.UnitTests/ILMergeMsTest.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E75D1760-E327-4709-892E-8CF522CACADB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ILMergeMsTest.UnitTests</RootNamespace>
<AssemblyName>ILMergeMsTest.UnitTests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.XML" />
</ItemGroup>
<ItemGroup>
<Compile Include="BaselineMSTests.cs" />
<Compile Include="ConsoleMSTests.cs" />
<Compile Include="KeyMSTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="TestData\test.pfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\test.snk">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ILMerge\ILMerge.csproj">
<Project>{84b41834-efde-4e52-a8ce-b51dfcb1d1b2}</Project>
<Name>ILMerge</Name>
</ProjectReference>
<ProjectReference Include="..\TestTools\TestTools.csproj">
<Project>{e0f0b234-a11a-43dc-9461-3b0184fa5e90}</Project>
<Name>TestTools</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Readme.txt" />
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets')" />
</Project>
Loading