Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added tests validating keyfile signing
  • Loading branch information
jnm2 committed Feb 15, 2017
commit f69998a7de87141b0a54d8cc5fa6e041f6774cf8
17 changes: 17 additions & 0 deletions ILMerge.Tests/BaselineTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Reflection;
using NUnit.Framework;

namespace ILMerging.Tests
{
[TestFixture]
public sealed class BaselineTests
{
[Test]
public void Single_input()
{
var ilMerge = new ILMerge();
ilMerge.SetUpInputAssemblyForTest(Assembly.GetExecutingAssembly());
ilMerge.MergeToTempFileForTest(".dll");
}
}
}
24 changes: 24 additions & 0 deletions ILMerge.Tests/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Linq;
using System.Reflection;
using ILMerging.Tests.Helpers;

namespace ILMerging.Tests
{
internal static class Extensions
{
public static void SetUpInputAssemblyForTest(this ILMerge ilMerge, Assembly inputAssembly)
{
ilMerge.SetSearchDirectories(ShadowCopyUtils.GetTransitiveClosureDirectories(inputAssembly).ToArray());
ilMerge.SetInputAssemblies(new[] { inputAssembly.Location });
}

public static void MergeToTempFileForTest(this ILMerge ilMerge, string outputExtension)
{
using (var outputFile = TempFile.WithExtension(outputExtension))
{
ilMerge.OutputFile = outputFile;
ilMerge.Merge();
}
}
}
}
3 changes: 3 additions & 0 deletions ILMerge.Tests/Helpers/ShadowCopyUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public static IEnumerable<Assembly> GetTransitiveClosure(params Assembly[] assem
}
}

/// <summary>
/// Necessary because of test runners like ReSharper and NCrunch which shadow copy each assembly to an isolated directory
/// </summary>
public static IEnumerable<string> GetTransitiveClosureDirectories(params Assembly[] assemblies)
{
return GetTransitiveClosure(assemblies)
Expand Down
8 changes: 8 additions & 0 deletions ILMerge.Tests/Helpers/TempFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ public TempFile(string path)
this.path = path;
}

public static TempFile WithExtension(string extension)
{
return new TempFile(
System.IO.Path.Combine(
System.IO.Path.GetTempPath(),
System.IO.Path.ChangeExtension(System.IO.Path.GetRandomFileName(), extension)));
}

private string path;
public string Path => path;

Expand Down
6 changes: 6 additions & 0 deletions ILMerge.Tests/ILMerge.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,24 @@
<Otherwise />
</Choose>
<ItemGroup>
<Compile Include="BaselineTests.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Integration\ConsoleTests.cs" />
<Compile Include="Helpers\ShadowCopyUtils.cs" />
<Compile Include="Helpers\ProcessUtils.cs" />
<Compile Include="Helpers\StackEnumerator.cs" />
<Compile Include="Helpers\TempFile.cs" />
<Compile Include="KeyTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="project.json" />
<None Include="test.pfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="test.snk">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ILMerge\ILMerge.csproj">
Expand Down
4 changes: 2 additions & 2 deletions ILMerge.Tests/Integration/ConsoleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public void No_DLL_load_crashes_when_given_PFX(bool withMscorsnInPath)
var inputAssembly = Assembly.GetExecutingAssembly();
var keyPath = "test.pfx";

using (var outputAssembly = new TempFile(Path.Combine(Path.GetTempPath(), Path.ChangeExtension(Path.GetRandomFileName(), ".dll"))))
using (var outputFile = TempFile.WithExtension(".dll"))
{
var startInfo = new ProcessStartInfo(
ilMergeExePath,
$"{ShadowCopyUtils.GenerateILMergeLibCliSwitches(inputAssembly)} /keyfile:\"{keyPath}\" /out:\"{outputAssembly}\" \"{inputAssembly.Location}\"")
$"{ShadowCopyUtils.GenerateILMergeLibCliSwitches(inputAssembly)} /keyfile:\"{keyPath}\" /out:\"{outputFile}\" \"{inputAssembly.Location}\"")
{
WorkingDirectory = Path.GetDirectoryName(inputAssembly.Location)
};
Expand Down
28 changes: 28 additions & 0 deletions ILMerge.Tests/KeyTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.IO;
using System.Reflection;
using ILMerging.Tests.Helpers;
using NUnit.Framework;

namespace ILMerging.Tests
{
[TestFixture]
public sealed class KeyTests
{
private const string KeyFile = "test.snk";

[Test]
public void Can_sign_using_keyfile()
{
using (var outputFile = TempFile.WithExtension(".dll"))
{
var ilMerge = new ILMerge { KeyFile = KeyFile, OutputFile = outputFile };
ilMerge.SetUpInputAssemblyForTest(Assembly.GetExecutingAssembly());
ilMerge.Merge();

Assert.That(
AssemblyName.GetAssemblyName(outputFile).GetPublicKey(),
Is.EqualTo(new StrongNameKeyPair(File.ReadAllBytes(KeyFile)).PublicKey));
}
}
}
}
Binary file added ILMerge.Tests/test.snk
Binary file not shown.