99
1010namespace Confuser . UnitTest {
1111 public abstract class TestBase {
12+ private const string _externalPrefix = "external:" ;
13+
1214 readonly ITestOutputHelper outputHelper ;
1315
1416 protected TestBase ( ITestOutputHelper outputHelper ) =>
@@ -30,16 +32,21 @@ protected async Task Run(string[] inputFileNames, string[] expectedOutput, Setti
3032 if ( Directory . Exists ( outputDir ) ) {
3133 Directory . Delete ( outputDir , true ) ;
3234 }
33- string entryInputFileName = Path . Combine ( baseDir , inputFileNames [ 0 ] ) ;
34- var entryOutputFileName = Path . Combine ( outputDir , inputFileNames [ 0 ] ) ;
35+
36+ string firstFileName = GetFileName ( inputFileNames [ 0 ] ) ;
37+ string entryInputFileName = Path . Combine ( baseDir , firstFileName ) ;
38+ var entryOutputFileName = Path . Combine ( outputDir , firstFileName ) ;
3539 var proj = new ConfuserProject {
3640 BaseDirectory = baseDir ,
3741 OutputDirectory = outputDir ,
3842 Packer = packer
3943 } ;
4044
4145 foreach ( string name in inputFileNames ) {
42- var projectModule = new ProjectModule { Path = Path . Combine ( baseDir , name ) } ;
46+ var projectModule = new ProjectModule {
47+ Path = Path . Combine ( baseDir , GetFileName ( name ) ) ,
48+ IsExternal = IsExternal ( name )
49+ } ;
4350 projectModuleAction ? . Invoke ( projectModule ) ;
4451 proj . Add ( projectModule ) ;
4552 }
@@ -56,7 +63,7 @@ protected async Task Run(string[] inputFileNames, string[] expectedOutput, Setti
5663 await ConfuserEngine . Run ( parameters ) ;
5764
5865 for ( var index = 0 ; index < inputFileNames . Length ; index ++ ) {
59- string name = inputFileNames [ index ] ;
66+ string name = GetFileName ( inputFileNames [ index ] ) ;
6067 string outputName = Path . Combine ( outputDir , name ) ;
6168
6269 bool exists ;
@@ -72,9 +79,14 @@ protected async Task Run(string[] inputFileNames, string[] expectedOutput, Setti
7279 // Check if output assemblies is obfuscated
7380 Assert . NotEqual ( FileUtilities . ComputeFileChecksum ( Path . Combine ( baseDir , name ) ) ,
7481 FileUtilities . ComputeFileChecksum ( outputName ) ) ;
82+ } else if ( IsExternal ( inputFileNames [ index ] ) ) {
83+ File . Copy (
84+ Path . Combine ( baseDir , GetFileName ( inputFileNames [ index ] ) ) ,
85+ Path . Combine ( outputDir , GetFileName ( inputFileNames [ index ] ) ) ) ;
7586 }
7687 }
7788
89+
7890 if ( Path . GetExtension ( entryInputFileName ) == ".exe" ) {
7991 var info = new ProcessStartInfo ( entryOutputFileName ) { RedirectStandardOutput = true , UseShellExecute = false } ;
8092 using ( var process = Process . Start ( info ) ) {
@@ -92,5 +104,13 @@ protected async Task Run(string[] inputFileNames, string[] expectedOutput, Setti
92104 }
93105 }
94106 }
107+
108+ private static string GetFileName ( string name ) {
109+ if ( IsExternal ( name ) )
110+ return name . Substring ( _externalPrefix . Length ) ;
111+ return name ;
112+ }
113+
114+ private static bool IsExternal ( string name ) => name . StartsWith ( _externalPrefix , StringComparison . OrdinalIgnoreCase ) ;
95115 }
96116}
0 commit comments