File size: 1,741 Bytes
8c763fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Describe "Assembly loaded in IndividualAssemblyLoadContext should be visible to PowerShell" -Tags "CI" {
BeforeAll {
$code1 = @'
namespace LoadBytes {
public class MyLoadBytesTest {
public static string GetName() { return "MyLoadBytesTest"; }
}
}
'@
$code2 = @'
namespace LoadFile {
public class MyLoadFileTest {
public static string GetName() { return "MyLoadFileTest"; }
}
}
'@
$tempFolderPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), "IndividualALCTest")
New-Item $tempFolderPath -ItemType Directory -Force > $null
$loadBytesFile = [System.IO.Path]::Combine($tempFolderPath, "MyLoadBytesTest.dll")
$loadFileFile = [System.IO.Path]::Combine($tempFolderPath, "MyLoadFileTest.dll")
if (-not (Test-Path $loadBytesFile)) {
Add-Type -TypeDefinition $code1 -OutputAssembly $loadBytesFile
}
if (-not (Test-Path $loadFileFile)) {
Add-Type -TypeDefinition $code2 -OutputAssembly $loadFileFile
}
}
It "Assembly loaded via 'Assembly.Load(byte[])' should be discoverable" {
$bytes = [System.IO.File]::ReadAllBytes($loadBytesFile)
[System.Reflection.Assembly]::Load($bytes) > $null
[LoadBytes.MyLoadBytesTest]::GetName() | Should -BeExactly "MyLoadBytesTest"
}
It "Assembly loaded via 'Assembly.LoadFile' should be discoverable" {
[System.Reflection.Assembly]::LoadFile($loadFileFile) > $null
[LoadFile.MyLoadFileTest]::GetName() | Should -BeExactly "MyLoadFileTest"
}
}
|