modify updateformatdata tests to use runspace to isolate format changes.
This should be the pattern for any test which mainupulates current state to protect from unintended side effects. This was done by default in ttest because each test would have its own runspace
This commit is contained in:
parent
cf7f46e1b8
commit
b8c9578e5b
1 changed files with 26 additions and 17 deletions
|
@ -1,5 +1,17 @@
|
||||||
Describe "Update-FormatData" {
|
Describe "Update-FormatData" {
|
||||||
|
|
||||||
|
BeforeAll {
|
||||||
|
$path = Join-Path -Path $TestDrive -ChildPath "outputfile.ps1xml"
|
||||||
|
$ps = [powershell]::Create()
|
||||||
|
$iss = [system.management.automation.runspaces.initialsessionstate]::CreateDefault2()
|
||||||
|
$rs = [system.management.automation.runspaces.runspacefactory]::CreateRunspace($iss)
|
||||||
|
$rs.Open()
|
||||||
|
$ps.Runspace = $rs
|
||||||
|
}
|
||||||
|
AfterAll {
|
||||||
|
$rs.Close()
|
||||||
|
$ps.Dispose()
|
||||||
|
}
|
||||||
Context "Validate Update-FormatData update correctly" {
|
Context "Validate Update-FormatData update correctly" {
|
||||||
|
|
||||||
It "Should not throw upon reloading previous formatting file" {
|
It "Should not throw upon reloading previous formatting file" {
|
||||||
|
@ -7,19 +19,19 @@ Describe "Update-FormatData" {
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should validly load formatting data" {
|
It "Should validly load formatting data" {
|
||||||
$path = Join-Path -Path $TestDrive -ChildPath "outputfile.ps1xml"
|
|
||||||
Get-FormatData -typename System.Diagnostics.Process | Export-FormatData -Path $path
|
Get-FormatData -typename System.Diagnostics.Process | Export-FormatData -Path $path
|
||||||
{ Update-FormatData -prependPath $path } | Should Not throw
|
$null = $ps.AddScript("Update-FormatData -prependPath $path")
|
||||||
Remove-Item $path -ErrorAction SilentlyContinue
|
$ps.Invoke()
|
||||||
|
$ps.HadErrors | Should be $false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Describe "Update-FormatData basic functionality" -Tags DRT{
|
Describe "Update-FormatData basic functionality" -Tags DRT{
|
||||||
$testfilename = "testfile.ps1xml"
|
BeforeAll {
|
||||||
$testfile = Join-Path -Path $TestDrive -ChildPath $testfilename
|
$testfilename = "testfile.ps1xml"
|
||||||
|
$testfile = Join-Path -Path $TestDrive -ChildPath $testfilename
|
||||||
|
|
||||||
It "Update-FormatData with WhatIf should work"{
|
|
||||||
$xmlContent=@"
|
$xmlContent=@"
|
||||||
<Types>
|
<Types>
|
||||||
<Type>
|
<Type>
|
||||||
|
@ -37,14 +49,11 @@ Describe "Update-FormatData basic functionality" -Tags DRT{
|
||||||
</Types>
|
</Types>
|
||||||
"@
|
"@
|
||||||
$xmlContent > $testfile
|
$xmlContent > $testfile
|
||||||
try
|
}
|
||||||
{
|
|
||||||
{ Update-FormatData -Append $testfile -WhatIf } | Should Not Throw
|
It "Update-FormatData with WhatIf should work"{
|
||||||
{ Update-FormatData -Prepend $testfile -WhatIf } | Should Not Throw
|
|
||||||
}
|
{ Update-FormatData -Append $testfile -WhatIf } | Should Not Throw
|
||||||
finally
|
{ Update-FormatData -Prepend $testfile -WhatIf } | Should Not Throw
|
||||||
{
|
|
||||||
Remove-Item $testfile -ErrorAction SilentlyContinue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue