Extracted some additional methods for UnitTests
Added a check to verify that the Confuser actually alters the assembly.
This commit is contained in:
Родитель
e2e9fdf494
Коммит
15569148ac
|
@ -9,7 +9,7 @@ using Xunit;
|
|||
using Xunit.Abstractions;
|
||||
|
||||
namespace CompressorWithResx.Test {
|
||||
public class CompressTest {
|
||||
public sealed class CompressTest {
|
||||
private readonly ITestOutputHelper outputHelper;
|
||||
|
||||
public CompressTest(ITestOutputHelper outputHelper) =>
|
||||
|
@ -22,17 +22,19 @@ namespace CompressorWithResx.Test {
|
|||
[InlineData("true", "dynamic")]
|
||||
public async Task CompressAndExecuteTest(string compatKey, string deriverKey) {
|
||||
var baseDir = Environment.CurrentDirectory;
|
||||
var outputFile = Path.Combine(baseDir, "testtmp", "CompressorWithResx.exe");
|
||||
ClearOutput(outputFile);
|
||||
var outputDir = Path.Combine(baseDir, "testtmp");
|
||||
var inputFile = Path.Combine(baseDir, "CompressorWithResx.exe");
|
||||
var outputFile = Path.Combine(outputDir, "CompressorWithResx.exe");
|
||||
FileUtilities.ClearOutput(outputFile);
|
||||
var proj = new ConfuserProject {
|
||||
BaseDirectory = baseDir,
|
||||
OutputDirectory = Path.Combine(baseDir, "testtmp"),
|
||||
OutputDirectory = outputDir,
|
||||
Packer = new SettingItem<Packer>("compressor") {
|
||||
{ "compat", compatKey},
|
||||
{ "key", deriverKey }
|
||||
}
|
||||
};
|
||||
proj.Add(new ProjectModule() { Path = Path.Combine(baseDir, "CompressorWithResx.exe") });
|
||||
proj.Add(new ProjectModule() { Path = inputFile });
|
||||
|
||||
|
||||
var parameters = new ConfuserParameters {
|
||||
|
@ -43,6 +45,7 @@ namespace CompressorWithResx.Test {
|
|||
await ConfuserEngine.Run(parameters);
|
||||
|
||||
Assert.True(File.Exists(outputFile));
|
||||
Assert.NotEqual(FileUtilities.ComputeFileChecksum(inputFile), FileUtilities.ComputeFileChecksum(outputFile));
|
||||
|
||||
var info = new ProcessStartInfo(outputFile) {
|
||||
RedirectStandardOutput = true,
|
||||
|
@ -58,23 +61,7 @@ namespace CompressorWithResx.Test {
|
|||
Assert.Equal(42, process.ExitCode);
|
||||
}
|
||||
|
||||
ClearOutput(outputFile);
|
||||
}
|
||||
|
||||
private static void ClearOutput(string outputFile) {
|
||||
try {
|
||||
if (File.Exists(outputFile)) {
|
||||
File.Delete(outputFile);
|
||||
}
|
||||
}
|
||||
catch (UnauthorizedAccessException) { }
|
||||
var debugSymbols = Path.ChangeExtension(outputFile, "pdb");
|
||||
try {
|
||||
if (File.Exists(debugSymbols)) {
|
||||
File.Delete(debugSymbols);
|
||||
}
|
||||
}
|
||||
catch (UnauthorizedAccessException) { }
|
||||
FileUtilities.ClearOutput(outputFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Confuser.UnitTest {
|
||||
public static class FileUtilities {
|
||||
public static void ClearOutput(string outputFile) {
|
||||
try {
|
||||
if (File.Exists(outputFile)) {
|
||||
File.Delete(outputFile);
|
||||
}
|
||||
}
|
||||
catch (UnauthorizedAccessException) { }
|
||||
var debugSymbols = Path.ChangeExtension(outputFile, "pdb");
|
||||
try {
|
||||
if (File.Exists(debugSymbols)) {
|
||||
File.Delete(debugSymbols);
|
||||
}
|
||||
}
|
||||
catch (UnauthorizedAccessException) { }
|
||||
}
|
||||
|
||||
public static byte[] ComputeFileChecksum(string file) {
|
||||
if (file == null) throw new ArgumentNullException(nameof(file));
|
||||
if (!File.Exists(file)) throw new FileNotFoundException($"File: {file}");
|
||||
|
||||
using (var checksum = SHA1.Create()) {
|
||||
using (var fs = File.OpenRead(file)) {
|
||||
return checksum.ComputeHash(fs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче