From 6e2190fc7de699dd9d84faaf3f56c6b98af43ca5 Mon Sep 17 00:00:00 2001 From: JumpingYang001 Date: Fri, 8 Apr 2016 01:47:50 -0700 Subject: [PATCH 1/3] Add Import-Alias Pester Unit test --- test/powershell/Import-Alias.Tests.ps1 | 111 +++++++++++++++++++------ 1 file changed, 86 insertions(+), 25 deletions(-) diff --git a/test/powershell/Import-Alias.Tests.ps1 b/test/powershell/Import-Alias.Tests.ps1 index 3b8cea09da..dcbc7dbe84 100644 --- a/test/powershell/Import-Alias.Tests.ps1 +++ b/test/powershell/Import-Alias.Tests.ps1 @@ -1,25 +1,86 @@ -Describe "Import-Alias" { - $pesteraliasfile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath pesteralias.txt - - Context "Validate ability to import alias file" { - - It "Should be able to import an alias file successfully" { - { Import-Alias $pesteraliasfile } | Should Not throw - } - - It "Should be able to import file via the Import-Alias alias of ipal" { - { ipal $pesteraliasfile } | Should Not throw - } - - It "Should be able to import an alias file and perform imported aliased echo cmd" { - (Import-Alias $pesteraliasfile) - (pesterecho pestertesting) | Should Be "pestertesting" - } - - It "Should be able to use ipal alias to import an alias file and perform cmd" { - (ipal $pesteraliasfile) - (pesterecho pestertesting) | Should be "pestertesting" - } - - } -} +Describe "Import-Alias DRT Unit Tests" -Tags DRT{ + $testAliasDirectory = Join-Path -Path $TestDrive -ChildPath ExportAliasTestDirectory + $testAliases = "TestAliases" + $fulltestpath = Join-Path -Path $testAliasDirectory -ChildPath $testAliases + + BeforeEach { + New-Item -Path $testAliasDirectory -ItemType Directory -Force + remove-item alias:abcd* -force + remove-item alias:ijkl* -force + set-alias abcd01 efgh01 + set-alias abcd02 efgh02 + set-alias abcd03 efgh03 + set-alias abcd04 efgh04 + set-alias ijkl01 mnop01 + set-alias ijkl02 mnop02 + set-alias ijkl03 mnop03 + set-alias ijkl04 mnop04 + } + + AfterEach { + Remove-Item -Path $testAliasDirectory -Recurse -Force + } + + It "Import-Alias Resolve To Multiple will throw PSInvalidOperationException" { + try { + Import-Alias * + Throw "Execution OK" + } + catch { + $_.FullyQualifiedErrorId | Should be "NotSupported,Microsoft.PowerShell.Commands.ImportAliasCommand" + } + } + + It "Import-Alias From Exported Alias File Aliases Already Exist should throw SessionStateException skip now as bug#777" -Skip:$true{ + {Export-Alias $fulltestpath abcd*}| Should Not Throw + try { + Import-Alias $fulltestpath + Throw "Execution OK" + } + catch { + $_.FullyQualifiedErrorId | Should be "AliasAlreadyExists,Microsoft.PowerShell.Commands.ImportAliasCommand" + } + } + + It "Import-Alias Into Invalid Scope should throw PSArgumentException"{ + {Export-Alias $fulltestpath abcd*}| Should Not Throw + try { + Import-Alias $fulltestpath -scope bogus + Throw "Execution OK" + } + catch { + $_.FullyQualifiedErrorId | Should be "Argument,Microsoft.PowerShell.Commands.ImportAliasCommand" + } + } + + It "Import-Alias From Exported Alias File Aliases Already Exist using force should not throw"{ + {Export-Alias $fulltestpath abcd*}| Should Not Throw + {Import-Alias $fulltestpath -Force}| Should Not Throw + } +} + +Describe "Import-Alias" { + $pesteraliasfile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath pesteralias.txt + + Context "Validate ability to import alias file" { + + It "Should be able to import an alias file successfully" { + { Import-Alias $pesteraliasfile } | Should Not throw + } + + It "Should be able to import file via the Import-Alias alias of ipal" { + { ipal $pesteraliasfile } | Should Not throw + } + + It "Should be able to import an alias file and perform imported aliased echo cmd" { + (Import-Alias $pesteraliasfile) + (pesterecho pestertesting) | Should Be "pestertesting" + } + + It "Should be able to use ipal alias to import an alias file and perform cmd" { + (ipal $pesteraliasfile) + (pesterecho pestertesting) | Should be "pestertesting" + } + + } +} From 5c341e7d7f1975aa566e94d18b94c896bc7167ab Mon Sep 17 00:00:00 2001 From: JumpingYang001 Date: Sun, 10 Apr 2016 19:38:35 -0700 Subject: [PATCH 2/3] Remove Context for Import-Alias pester unit test --- test/powershell/Import-Alias.Tests.ps1 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/powershell/Import-Alias.Tests.ps1 b/test/powershell/Import-Alias.Tests.ps1 index dcbc7dbe84..42f699b638 100644 --- a/test/powershell/Import-Alias.Tests.ps1 +++ b/test/powershell/Import-Alias.Tests.ps1 @@ -62,8 +62,6 @@ Describe "Import-Alias DRT Unit Tests" -Tags DRT{ Describe "Import-Alias" { $pesteraliasfile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath pesteralias.txt - Context "Validate ability to import alias file" { - It "Should be able to import an alias file successfully" { { Import-Alias $pesteraliasfile } | Should Not throw } @@ -81,6 +79,4 @@ Describe "Import-Alias" { (ipal $pesteraliasfile) (pesterecho pestertesting) | Should be "pestertesting" } - - } } From 6184dec3ad0bf0c945c89680948c2893fb6b9477 Mon Sep 17 00:00:00 2001 From: JumpingYang001 Date: Wed, 13 Apr 2016 02:42:34 -0700 Subject: [PATCH 3/3] Update stand-alone tests for Import-Alias Pester unit test --- test/powershell/Import-Alias.Tests.ps1 | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/powershell/Import-Alias.Tests.ps1 b/test/powershell/Import-Alias.Tests.ps1 index 42f699b638..f47b493a4e 100644 --- a/test/powershell/Import-Alias.Tests.ps1 +++ b/test/powershell/Import-Alias.Tests.ps1 @@ -1,5 +1,5 @@ Describe "Import-Alias DRT Unit Tests" -Tags DRT{ - $testAliasDirectory = Join-Path -Path $TestDrive -ChildPath ExportAliasTestDirectory + $testAliasDirectory = Join-Path -Path $TestDrive -ChildPath ImportAliasTestDirectory $testAliases = "TestAliases" $fulltestpath = Join-Path -Path $testAliasDirectory -ChildPath $testAliases @@ -60,7 +60,24 @@ Describe "Import-Alias DRT Unit Tests" -Tags DRT{ } Describe "Import-Alias" { - $pesteraliasfile = Join-Path -Path (Join-Path $PSScriptRoot -ChildPath assets) -ChildPath pesteralias.txt + $newLine=[Environment]::NewLine + $testAliasDirectory = Join-Path -Path $TestDrive -ChildPath ImportAliasTestDirectory + $testAliases = "pesteralias.txt" + $pesteraliasfile = Join-Path -Path $testAliasDirectory -ChildPath $testAliases + + BeforeEach { + New-Item -Path $testAliasDirectory -ItemType Directory -Force + + $pesteraliascontent ='# Alias File'+$newLine + $pesteraliascontent+='# Exported by : alex'+$newLine + $pesteraliascontent+='# Date/Time : Thursday, 12 November 2015 21:55:08'+$newLine + $pesteraliascontent+='# Computer : archvm'+$newLine+'"pesterecho","echo","","None"' + $pesteraliascontent > $pesteraliasfile + } + + AfterEach { + Remove-Item -Path $testAliasDirectory -Recurse -Force + } It "Should be able to import an alias file successfully" { { Import-Alias $pesteraliasfile } | Should Not throw