1+ namespace Stamp . Fody . Tests
2+ {
3+ using System ;
4+ using System . Diagnostics ;
5+ using System . IO ;
6+ using System . Text . RegularExpressions ;
7+ using NUnit . Framework ;
8+
9+ public static class Verifier
10+ {
11+ public static void Verify ( string beforeAssemblyPath , string afterAssemblyPath )
12+ {
13+ var before = Validate ( beforeAssemblyPath ) ;
14+ var after = Validate ( afterAssemblyPath ) ;
15+ var message = $ "Failed processing { Path . GetFileName ( afterAssemblyPath ) } \r \n { after } ";
16+ Assert . AreEqual ( TrimLineNumbers ( before ) , TrimLineNumbers ( after ) , message ) ;
17+ }
18+
19+ private static string Validate ( string assemblyPath2 )
20+ {
21+ var exePath = GetPathToPeVerify ( ) ;
22+ if ( ! File . Exists ( exePath ) )
23+ {
24+ return string . Empty ;
25+ }
26+ var process = Process . Start ( new ProcessStartInfo ( exePath , "\" " + assemblyPath2 + "\" " )
27+ {
28+ RedirectStandardOutput = true ,
29+ UseShellExecute = false ,
30+ CreateNoWindow = true
31+ } ) ;
32+
33+ process . WaitForExit ( 10000 ) ;
34+ return process . StandardOutput . ReadToEnd ( ) . Trim ( ) . Replace ( assemblyPath2 , "" ) ;
35+ }
36+
37+ private static string GetPathToPeVerify ( )
38+ {
39+ var exePath = Environment . ExpandEnvironmentVariables ( @"%programfiles(x86)%\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\PEVerify.exe" ) ;
40+
41+ if ( ! File . Exists ( exePath ) )
42+ {
43+ exePath = Environment . ExpandEnvironmentVariables ( @"%programfiles(x86)%\Microsoft SDKs\Windows\v8.0A\Bin\NETFX 4.0 Tools\PEVerify.exe" ) ;
44+ }
45+ return exePath ;
46+ }
47+
48+ private static string TrimLineNumbers ( string foo )
49+ {
50+ return Regex . Replace ( foo , @"0x.*]" , "" ) ;
51+ }
52+ }
53+ }
0 commit comments