Isolate Remove-TypeData tests with runspace
This commit is contained in:
parent
a02e89ee7b
commit
f13f5afd23
2 changed files with 53 additions and 39 deletions
|
@ -1,13 +1,5 @@
|
||||||
Describe "Remove-TypeData DRT Unit Tests" -Tags DRT{
|
Describe "Remove-TypeData DRT Unit Tests" -Tags DRT {
|
||||||
It "Remove With Pipe line Input Pass Type Shortcut String" {
|
BeforeAll {
|
||||||
{ Update-TypeData -MemberType NoteProperty -MemberName TestNote -Value TestNote -TypeName int } | Should Not Throw
|
|
||||||
$a = Get-TypeData System.Int32
|
|
||||||
$a.TypeName | Should Be System.Int32
|
|
||||||
|
|
||||||
{ 'int' | Remove-TypeData } | Should Not Throw
|
|
||||||
}
|
|
||||||
|
|
||||||
It "Remove Type File In Initial Session State" {
|
|
||||||
$XMLFile1 = Join-Path $TestDrive -ChildPath "testFile1.ps1xml"
|
$XMLFile1 = Join-Path $TestDrive -ChildPath "testFile1.ps1xml"
|
||||||
$XMLFile2 = Join-Path $TestDrive -ChildPath "testFile2.ps1xml"
|
$XMLFile2 = Join-Path $TestDrive -ChildPath "testFile2.ps1xml"
|
||||||
$content1 = @"
|
$content1 = @"
|
||||||
|
@ -23,7 +15,6 @@
|
||||||
</Type>
|
</Type>
|
||||||
</Types>
|
</Types>
|
||||||
"@
|
"@
|
||||||
|
|
||||||
$content2 = @"
|
$content2 = @"
|
||||||
<Types>
|
<Types>
|
||||||
<Type>
|
<Type>
|
||||||
|
@ -37,31 +28,56 @@
|
||||||
</Type>
|
</Type>
|
||||||
</Types>
|
</Types>
|
||||||
"@
|
"@
|
||||||
|
|
||||||
$content1 > $XMLFile1
|
$content1 > $XMLFile1
|
||||||
$content2 > $XMLFile2
|
$content2 > $XMLFile2
|
||||||
Update-TypeData -AppendPath $XMLFile1
|
}
|
||||||
Update-TypeData -AppendPath $XMLFile2
|
|
||||||
$a = 1..3
|
BeforeEach {
|
||||||
$a.Yada | Should be 3
|
$ps = [powershell]::Create()
|
||||||
$a.Yoda | Should Be 3
|
$iss = [system.management.automation.runspaces.initialsessionstate]::CreateDefault2()
|
||||||
Remove-TypeData -Path $XMLFile1
|
$rs = [system.management.automation.runspaces.runspacefactory]::CreateRunspace($iss)
|
||||||
$a.Yada | Should BeNullOrEmpty
|
$rs.Open()
|
||||||
$a.Yoda | Should Be 3
|
$ps.Runspace = $rs
|
||||||
|
}
|
||||||
#clean up
|
|
||||||
Remove-TypeData -Path $XMLFile2
|
AfterEach {
|
||||||
|
$rs.Close()
|
||||||
|
$ps.Dispose()
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Remove With Pipe line Input Pass Type Shortcut String" {
|
||||||
|
$null = $ps.AddScript("Update-TypeData -MemberType NoteProperty -MemberName TestNote -Value TestNote -TypeName int").Invoke()
|
||||||
|
$ps.Commands.Clear()
|
||||||
|
$null = $ps.AddScript("(Get-TypeData System.Int32).TypeName").Invoke() | Should Be System.Int32
|
||||||
|
$ps.Commands.Clear()
|
||||||
|
$null = $ps.AddScript("'int' | Remove-TypeData").Invoke()
|
||||||
|
$ps.HadErrors | Should be $false
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Remove Type File In Initial Session State" {
|
||||||
|
# setup
|
||||||
|
$null = $ps.AddScript("Update-TypeData -AppendPath $XMLFile1").Invoke()
|
||||||
|
$ps.Commands.Clear()
|
||||||
|
$null = $ps.AddScript("Update-TypeData -AppendPath $XMLFile2").Invoke()
|
||||||
|
$ps.Commands.Clear()
|
||||||
|
$null = $ps.AddScript('$a = 1..3').Invoke()
|
||||||
|
$ps.Commands.Clear()
|
||||||
|
# test
|
||||||
|
$ps.AddScript('$a.Yada').Invoke() | Should be 3
|
||||||
|
$ps.Commands.Clear()
|
||||||
|
$ps.AddScript('$a.Yoda').Invoke() | Should Be 3
|
||||||
|
$ps.Commands.Clear()
|
||||||
|
$null = $ps.AddScript("Remove-TypeData -Path $XMLFile1").Invoke()
|
||||||
|
$ps.Commands.Clear()
|
||||||
|
$ps.AddScript('$a.Yada').Invoke() | Should BeNullOrEmpty
|
||||||
|
$ps.Commands.Clear()
|
||||||
|
$ps.AddScript('$a.Yoda').Invoke() | Should Be 3
|
||||||
|
$ps.Commands.Clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Remove Type File In Initial Session State File Not In Cache" {
|
It "Remove Type File In Initial Session State File Not In Cache" {
|
||||||
try
|
$null = $ps.AddScript("Remove-TypeData -Path fakefile").Invoke()
|
||||||
{
|
$ps.HadErrors | Should be $true
|
||||||
Remove-TypeData -Path "fakefile" -ErrorAction Stop
|
$ps.Streams.Error[0].FullyQualifiedErrorID | Should Be "TypePathException,Microsoft.PowerShell.Commands.RemoveTypeDataCommand"
|
||||||
Throw "OK"
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
$_.FullyQualifiedErrorId | Should Be "TypePathException,Microsoft.PowerShell.Commands.RemoveTypeDataCommand"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ Describe "Update-TypeData basic functionality" -Tags DRT{
|
||||||
$testfile = Join-Path -Path $TestDrive -ChildPath $testfilename
|
$testfile = Join-Path -Path $TestDrive -ChildPath $testfilename
|
||||||
$invalidFileExtensionFile = Join-Path -Path $TestDrive -ChildPath "notmshxml"
|
$invalidFileExtensionFile = Join-Path -Path $TestDrive -ChildPath "notmshxml"
|
||||||
|
|
||||||
$xmlContent=@"
|
$xmlContent=@"
|
||||||
<Types>
|
<Types>
|
||||||
<Type>
|
<Type>
|
||||||
<Name>AnyName</Name>
|
<Name>AnyName</Name>
|
||||||
|
@ -39,7 +39,7 @@ Describe "Update-TypeData basic functionality" -Tags DRT{
|
||||||
</Type>
|
</Type>
|
||||||
</Types>
|
</Types>
|
||||||
"@
|
"@
|
||||||
$xmlContent>$testfile
|
$xmlContent>$testfile
|
||||||
}
|
}
|
||||||
|
|
||||||
BeforeEach {
|
BeforeEach {
|
||||||
|
@ -49,15 +49,13 @@ Describe "Update-TypeData basic functionality" -Tags DRT{
|
||||||
$rs.Open()
|
$rs.Open()
|
||||||
$ps.Runspace = $rs
|
$ps.Runspace = $rs
|
||||||
}
|
}
|
||||||
|
|
||||||
AfterEach {
|
AfterEach {
|
||||||
$rs.Close()
|
$rs.Close()
|
||||||
$ps.Dispose()
|
$ps.Dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
#Pester bug:https://github.com/PowerShell/psl-pester/issues/6
|
|
||||||
It "Update-TypeData with Invalid TypesXml should throw Exception" {
|
|
||||||
|
|
||||||
|
It "Update-TypeData with Invalid TypesXml should throw Exception" {
|
||||||
$null = $ps.AddScript("Update-TypeData -PrependPath $testfile")
|
$null = $ps.AddScript("Update-TypeData -PrependPath $testfile")
|
||||||
$ps.Invoke()
|
$ps.Invoke()
|
||||||
$ps.HadErrors | Should be $true
|
$ps.HadErrors | Should be $true
|
||||||
|
|
Loading…
Reference in a new issue