From 0b97247cbf6a033a297fded42a56f2fe04635c30 Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Tue, 10 May 2016 02:57:01 -0700 Subject: [PATCH] Add Unit Test for Remove-TypeData --- test/powershell/Remove-TypeData.Tests.ps1 | 70 +++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 test/powershell/Remove-TypeData.Tests.ps1 diff --git a/test/powershell/Remove-TypeData.Tests.ps1 b/test/powershell/Remove-TypeData.Tests.ps1 new file mode 100644 index 0000000000..d1d2c5f6e7 --- /dev/null +++ b/test/powershell/Remove-TypeData.Tests.ps1 @@ -0,0 +1,70 @@ +Describe "Remove-TypeData DRT Unit Tests" -Tags DRT{ + It "Remove With Pipe line Input Pass Type Shortcut String" { + { 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" + $XMLFile2 = Join-Path $TestDrive -ChildPath "testFile2.ps1xml" + $content1 = @" + + + System.Array + + + Yada + Length + + + + +"@ + + $content2 = @" + + + System.Array + + + Yoda + Length + + + + +"@ + + $content1 > $XMLFile1 + $content2 > $XMLFile2 + Update-TypeData -AppendPath $XMLFile1 + Update-TypeData -AppendPath $XMLFile2 + $a = 1..3 + $a.Yada | Should be 3 + $a.Yoda | Should Be 3 + Remove-TypeData -Path $XMLFile1 + $a = 1..3 + $a.Yada | Should BeNullOrEmpty + $a.Yoda | Should Be 3 + + #clean up + Remove-TypeData -Path $XMLFile2 + Remove-Item $XMLFile1 -ErrorAction SilentlyContinue + Remove-Item $XMLFile2 -ErrorAction SilentlyContinue + } + + It "Remove Type File In Initial Session State File Not In Cache" { + try + { + Remove-TypeData -Path "fakefile" -ErrorAction Stop + Throw "TypePathException" + } + catch + { + $_.FullyQualifiedErrorId | Should Be "TypePathException,Microsoft.PowerShell.Commands.RemoveTypeDataCommand" + } + } +} \ No newline at end of file