@@ -27,7 +27,7 @@ public void LoadLibrary()
27
27
{
28
28
string [ ] args = {
29
29
"ijwhost" ,
30
- sharedState . IjwLibraryPath ,
30
+ sharedState . IjwApp . AppDll ,
31
31
"NativeEntryPoint"
32
32
} ;
33
33
CommandResult result = sharedState . CreateNativeHostCommand ( args , sharedState . RepoDirectories . BuiltDotnet )
@@ -38,14 +38,49 @@ public void LoadLibrary()
38
38
. And . HaveStdOutContaining ( "[C++/CLI] ManagedClass: AssemblyLoadContext = \" Default\" System.Runtime.Loader.DefaultAssemblyLoadContext" ) ;
39
39
}
40
40
41
+ [ Theory ]
42
+ [ InlineData ( true ) ]
43
+ [ InlineData ( false ) ]
44
+ public void LoadLibrary_ContextConfig ( bool load_isolated )
45
+ {
46
+ // make a copy of a portion of the shared state because we will modify it
47
+ using ( var app = sharedState . IjwApp . Copy ( ) )
48
+ {
49
+ string [ ] args = {
50
+ "ijwhost" ,
51
+ app . AppDll ,
52
+ "NativeEntryPoint"
53
+ } ;
54
+
55
+ RuntimeConfig . FromFile ( app . RuntimeConfigJson )
56
+ . WithProperty ( "System.Runtime.InteropServices.CppCLI.LoadComponentInIsolatedContext" , load_isolated . ToString ( ) )
57
+ . Save ( ) ;
58
+
59
+ CommandResult result = sharedState . CreateNativeHostCommand ( args , sharedState . RepoDirectories . BuiltDotnet )
60
+ . Execute ( ) ;
61
+
62
+ result . Should ( ) . Pass ( )
63
+ . And . HaveStdOutContaining ( "[C++/CLI] NativeEntryPoint: calling managed class" ) ;
64
+
65
+ if ( load_isolated ) // Assembly should be loaded in an isolated context
66
+ {
67
+ result . Should ( ) . HaveStdOutContaining ( "[C++/CLI] ManagedClass: AssemblyLoadContext = \" IsolatedComponentLoadContext" ) ;
68
+ }
69
+ else // Assembly should be loaded in the default context
70
+ {
71
+ result . Should ( ) . HaveStdOutContaining ( "[C++/CLI] ManagedClass: AssemblyLoadContext = \" Default\" System.Runtime.Loader.DefaultAssemblyLoadContext" ) ;
72
+ }
73
+ }
74
+ }
75
+
41
76
[ Theory ]
42
77
[ InlineData ( true ) ]
43
78
[ InlineData ( false ) ]
44
79
public void ManagedHost ( bool selfContained )
45
80
{
46
81
string [ ] args = {
47
82
"ijwhost" ,
48
- sharedState . IjwLibraryPath ,
83
+ sharedState . IjwApp . AppDll ,
49
84
"NativeEntryPoint"
50
85
} ;
51
86
TestProjectFixture fixture = selfContained ? sharedState . ManagedHostFixture_SelfContained : sharedState . ManagedHostFixture_FrameworkDependent ;
@@ -63,24 +98,23 @@ public void ManagedHost(bool selfContained)
63
98
64
99
public class SharedTestState : SharedTestStateBase
65
100
{
66
- public string IjwLibraryPath { get ; }
101
+ public TestApp IjwApp { get ; }
67
102
68
103
public TestProjectFixture ManagedHostFixture_FrameworkDependent { get ; }
69
104
public TestProjectFixture ManagedHostFixture_SelfContained { get ; }
70
105
71
106
public SharedTestState ( )
72
107
{
73
108
string folder = Path . Combine ( BaseDirectory , "ijw" ) ;
74
- Directory . CreateDirectory ( folder ) ;
109
+ IjwApp = new TestApp ( folder , "ijw" ) ;
75
110
76
111
// Copy over ijwhost
77
112
string ijwhostName = "ijwhost.dll" ;
78
113
File . Copy ( Path . Combine ( RepoDirectories . HostArtifacts , ijwhostName ) , Path . Combine ( folder , ijwhostName ) ) ;
79
114
80
115
// Copy over the C++/CLI test library
81
116
string ijwLibraryName = "ijw.dll" ;
82
- IjwLibraryPath = Path . Combine ( folder , ijwLibraryName ) ;
83
- File . Copy ( Path . Combine ( RepoDirectories . HostTestArtifacts , ijwLibraryName ) , IjwLibraryPath ) ;
117
+ File . Copy ( Path . Combine ( RepoDirectories . HostTestArtifacts , ijwLibraryName ) , Path . Combine ( folder , ijwLibraryName ) ) ;
84
118
85
119
// Create a runtimeconfig.json for the C++/CLI test library
86
120
new RuntimeConfig ( Path . Combine ( folder , "ijw.runtimeconfig.json" ) )
0 commit comments