11
11
12
12
namespace Microsoft . DotNet . CoreSetup . Test . HostActivation . NativeHosting
13
13
{
14
- public partial class LoadAssembly : IClassFixture < LoadAssembly . SharedTestState >
14
+ public class LoadAssembly : IClassFixture < LoadAssembly . SharedTestState >
15
15
{
16
16
private const string AppLoadAssemblyArg = "app_load_assembly" ;
17
17
private const string ComponentLoadAssemblyArg = "component_load_assembly" ;
18
18
19
+ private const string AppLoadAssemblyBytesArg = "app_load_assembly_bytes" ;
20
+ private const string ComponentLoadAssemblyBytesArg = "component_load_assembly_bytes" ;
21
+
19
22
private readonly SharedTestState sharedState ;
20
23
21
24
public LoadAssembly ( SharedTestState sharedTestState )
22
25
{
23
26
sharedState = sharedTestState ;
24
27
}
25
28
26
- [ Fact ]
27
- public void ApplicationContext ( )
29
+ private void ApplicationContext ( bool loadAssemblyBytes , bool loadSymbolBytes )
28
30
{
29
- var appProject = sharedState . Application ;
30
- var componentProject = sharedState . ComponentWithNoDependenciesFixture . TestProject ;
31
- string [ ] args =
31
+ var app = sharedState . Application ;
32
+ var component = sharedState . Component ;
33
+ IEnumerable < string > args = new [ ]
32
34
{
33
- AppLoadAssemblyArg ,
35
+ loadAssemblyBytes ? AppLoadAssemblyBytesArg : AppLoadAssemblyArg ,
34
36
sharedState . HostFxrPath ,
35
- appProject . AppDll ,
36
- componentProject . AppDll ,
37
- sharedState . ComponentTypeName ,
38
- sharedState . ComponentEntryPoint1 ,
39
- } ;
37
+ app . AppDll
38
+ } . Concat ( sharedState . GetComponentLoadArgs ( loadAssemblyBytes , loadSymbolBytes ) ) ;
39
+
40
40
CommandResult result = sharedState . CreateNativeHostCommand ( args , sharedState . DotNetRoot )
41
41
. Execute ( ) ;
42
42
43
43
result . Should ( ) . Pass ( )
44
- . And . InitializeContextForApp ( appProject . AppDll )
44
+ . And . InitializeContextForApp ( app . AppDll )
45
45
. And . ExecuteSelfContained ( selfContained : false )
46
- . And . ExecuteInDefaultContext ( componentProject . AssemblyName )
46
+ . And . ExecuteInDefaultContext ( component . AssemblyName )
47
+ . And . ExecuteWithLocation ( component . AssemblyName , loadAssemblyBytes ? string . Empty : component . AppDll )
47
48
. And . ExecuteFunctionPointer ( sharedState . ComponentEntryPoint1 , 1 , 1 ) ;
48
49
}
49
50
50
51
[ Fact ]
51
- public void ComponentContext ( )
52
+ public void ApplicationContext_FilePath ( )
53
+ {
54
+ ApplicationContext ( loadAssemblyBytes : false , loadSymbolBytes : false ) ;
55
+ }
56
+
57
+ [ Theory ]
58
+ [ InlineData ( true ) ]
59
+ [ InlineData ( false ) ]
60
+ public void ApplicationContext_Bytes ( bool loadSymbolBytes )
61
+ {
62
+ ApplicationContext ( loadAssemblyBytes : true , loadSymbolBytes ) ;
63
+ }
64
+
65
+ private void ComponentContext ( bool loadAssemblyBytes , bool loadSymbolBytes )
52
66
{
53
- var appProject = sharedState . Application ;
54
- var componentProject = sharedState . ComponentWithNoDependenciesFixture . TestProject ;
55
- string [ ] args =
67
+ var app = sharedState . Application ;
68
+ var component = sharedState . Component ;
69
+ IEnumerable < string > args = new [ ]
56
70
{
57
- ComponentLoadAssemblyArg ,
71
+ loadAssemblyBytes ? ComponentLoadAssemblyBytesArg : ComponentLoadAssemblyArg ,
58
72
sharedState . HostFxrPath ,
59
- componentProject . RuntimeConfigJson ,
60
- componentProject . AppDll ,
61
- sharedState . ComponentTypeName ,
62
- sharedState . ComponentEntryPoint1 ,
63
- } ;
73
+ component . RuntimeConfigJson
74
+ } . Concat ( sharedState . GetComponentLoadArgs ( loadAssemblyBytes , loadSymbolBytes ) ) ;
75
+
64
76
CommandResult result = sharedState . CreateNativeHostCommand ( args , sharedState . DotNetRoot )
65
77
. Execute ( ) ;
66
78
67
79
result . Should ( ) . Pass ( )
68
- . And . InitializeContextForConfig ( componentProject . RuntimeConfigJson )
69
- . And . ExecuteInDefaultContext ( componentProject . AssemblyName )
80
+ . And . InitializeContextForConfig ( component . RuntimeConfigJson )
81
+ . And . ExecuteInDefaultContext ( component . AssemblyName )
82
+ . And . ExecuteWithLocation ( component . AssemblyName , loadAssemblyBytes ? string . Empty : component . AppDll )
70
83
. And . ExecuteFunctionPointer ( sharedState . ComponentEntryPoint1 , 1 , 1 ) ;
71
84
}
72
85
73
86
[ Fact ]
74
- public void SelfContainedApplicationContext ( )
87
+ public void ComponentContext_FilePath ( )
88
+ {
89
+ ComponentContext ( loadAssemblyBytes : false , loadSymbolBytes : false ) ;
90
+ }
91
+
92
+ [ Theory ]
93
+ [ InlineData ( true ) ]
94
+ [ InlineData ( false ) ]
95
+ public void ComponentContext_Bytes ( bool loadSymbolBytes )
96
+ {
97
+ ComponentContext ( loadAssemblyBytes : true , loadSymbolBytes ) ;
98
+ }
99
+
100
+ private void SelfContainedApplicationContext ( bool loadAssemblyBytes , bool loadSymbolBytes )
75
101
{
76
- var appProject = sharedState . SelfContainedApplication ;
77
- var componentProject = sharedState . ComponentWithNoDependenciesFixture . TestProject ;
78
- string [ ] args =
102
+ var app = sharedState . SelfContainedApplication ;
103
+ var component = sharedState . Component ;
104
+ IEnumerable < string > args = new [ ]
79
105
{
80
- AppLoadAssemblyArg ,
81
- appProject . HostFxrDll ,
82
- appProject . AppDll ,
83
- componentProject . AppDll ,
84
- sharedState . ComponentTypeName ,
85
- sharedState . ComponentEntryPoint1
86
- } ;
106
+ loadAssemblyBytes ? AppLoadAssemblyBytesArg : AppLoadAssemblyArg ,
107
+ app . HostFxrDll ,
108
+ app . AppDll
109
+ } . Concat ( sharedState . GetComponentLoadArgs ( loadAssemblyBytes , loadSymbolBytes ) ) ;
110
+
87
111
CommandResult result = sharedState . CreateNativeHostCommand ( args , sharedState . DotNetRoot )
88
112
. Execute ( ) ;
89
113
90
114
result . Should ( ) . Pass ( )
91
- . And . InitializeContextForApp ( appProject . AppDll )
115
+ . And . InitializeContextForApp ( app . AppDll )
92
116
. And . ExecuteSelfContained ( selfContained : true )
93
- . And . ExecuteInDefaultContext ( componentProject . AssemblyName )
117
+ . And . ExecuteInDefaultContext ( component . AssemblyName )
118
+ . And . ExecuteWithLocation ( component . AssemblyName , loadAssemblyBytes ? string . Empty : component . AppDll )
94
119
. And . ExecuteFunctionPointer ( sharedState . ComponentEntryPoint1 , 1 , 1 ) ;
95
120
}
96
121
122
+ [ Fact ]
123
+ public void SelfContainedApplicationContext_FilePath ( )
124
+ {
125
+ SelfContainedApplicationContext ( loadAssemblyBytes : false , loadSymbolBytes : false ) ;
126
+ }
127
+
128
+ [ Theory ]
129
+ [ InlineData ( true ) ]
130
+ [ InlineData ( false ) ]
131
+ public void SelfContainedApplicationContext_Bytes ( bool loadSymbolBytes )
132
+ {
133
+ SelfContainedApplicationContext ( loadAssemblyBytes : true , loadSymbolBytes ) ;
134
+ }
135
+
97
136
public class SharedTestState : SharedTestStateBase
98
137
{
99
138
public string HostFxrPath { get ; }
@@ -103,10 +142,10 @@ public class SharedTestState : SharedTestStateBase
103
142
public TestApp SelfContainedApplication { get ; }
104
143
105
144
public TestProjectFixture ComponentWithNoDependenciesFixture { get ; }
145
+ public TestApp Component => ComponentWithNoDependenciesFixture . TestProject . BuiltApp ;
106
146
107
147
public string ComponentTypeName { get ; }
108
148
public string ComponentEntryPoint1 => "ComponentEntryPoint1" ;
109
- public string UnmanagedFunctionPointerEntryPoint1 => "UnmanagedFunctionPointerEntryPoint1" ;
110
149
111
150
public SharedTestState ( )
112
151
{
@@ -127,6 +166,17 @@ public SharedTestState()
127
166
ComponentTypeName = $ "Component.Component, { ComponentWithNoDependenciesFixture . TestProject . AssemblyName } ";
128
167
}
129
168
169
+ internal IEnumerable < string > GetComponentLoadArgs ( bool loadAssemblyBytes , bool loadSymbolBytes )
170
+ {
171
+ List < string > args = new List < string > ( ) { Component . AppDll } ;
172
+ if ( loadAssemblyBytes )
173
+ args . Add ( loadSymbolBytes ? $ "{ Path . GetFileNameWithoutExtension ( Component . AppDll ) } .pdb" : "nullptr" ) ;
174
+
175
+ args . Add ( ComponentTypeName ) ;
176
+ args . Add ( ComponentEntryPoint1 ) ;
177
+ return args ;
178
+ }
179
+
130
180
protected override void Dispose ( bool disposing )
131
181
{
132
182
if ( Application != null )
0 commit comments