1
+ // Copyright (c) .NET Foundation. All rights reserved.
2
+ // Licensed under the MIT License. See License.txt in the project root for license information.
3
+
4
+ using System ;
5
+ using System . Collections . Generic ;
6
+ using System . Text ;
7
+ using Microsoft . Azure . WebJobs . Script . Description ;
8
+ using Xunit ;
9
+
10
+ namespace Microsoft . Azure . WebJobs . Script . Tests . Description . DotNet
11
+ {
12
+ public class RawAssemblyCompilationTests
13
+ {
14
+ [ Theory ]
15
+ [ MemberData ( nameof ( GetTargetNames ) ) ]
16
+ public void GetEntryPointSignature_BindsToExpectedMethod ( string entryPointName , string methodName )
17
+ {
18
+ var testAssembly = typeof ( TestFunction1 ) . Assembly ;
19
+ string assemblyPath = new Uri ( testAssembly . CodeBase , UriKind . Absolute ) . LocalPath ;
20
+ var compilation = new RawAssemblyCompilation ( assemblyPath , entryPointName ) ;
21
+
22
+ FunctionSignature signature = compilation . GetEntryPointSignature ( new FunctionEntryPointResolver ( ) , testAssembly ) ;
23
+
24
+ Assert . NotNull ( signature ) ;
25
+ Assert . Equal ( methodName , signature . MethodName ) ;
26
+ }
27
+
28
+ [ Fact ]
29
+ public void GetEntryPointSignature_PrefersStaticMethod ( )
30
+ {
31
+ var testAssembly = typeof ( TestFunction1 ) . Assembly ;
32
+ string assemblyPath = new Uri ( testAssembly . CodeBase , UriKind . Absolute ) . LocalPath ;
33
+ var compilation = new RawAssemblyCompilation ( assemblyPath , $ "{ typeof ( TestFunction3 ) . FullName } .{ nameof ( TestFunction3 . Run ) } ") ;
34
+
35
+ FunctionSignature signature = compilation . GetEntryPointSignature ( new FunctionEntryPointResolver ( ) , testAssembly ) ;
36
+
37
+ Assert . NotNull ( signature ) ;
38
+ Assert . Equal ( nameof ( TestFunction3 . Run ) , signature . MethodName ) ;
39
+ }
40
+
41
+ public static IEnumerable < object [ ] > GetTargetNames ( )
42
+ {
43
+ return new [ ]
44
+ {
45
+ new [ ] { $ "{ typeof ( TestFunction1 ) . FullName } .{ nameof ( TestFunction1 . Run ) } ", nameof ( TestFunction1 . Run ) } ,
46
+ new [ ] { $ "{ typeof ( TestFunction2 ) . FullName } .{ nameof ( TestFunction2 . Run ) } ", nameof ( TestFunction2 . Run ) }
47
+ } ;
48
+ }
49
+ }
50
+
51
+ public class TestFunction1
52
+ {
53
+ public void Run ( ) { }
54
+ }
55
+
56
+ public class TestFunction2
57
+ {
58
+ public static void Run ( ) { }
59
+ }
60
+
61
+ public class TestFunction3
62
+ {
63
+ public void Run ( ) { }
64
+
65
+ public static void Run ( string test ) { }
66
+ }
67
+ }
0 commit comments