From 7ab662c860647c81859950265c62315b4e3f3bdd Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 21 Mar 2018 11:40:13 +0100 Subject: [PATCH] fix scoping issue in test file --- .../Item/02_New-CredentialStoreItem.Tests.ps1 | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 index 7e4e9aa..4ed64f7 100644 --- a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 +++ b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 @@ -79,23 +79,24 @@ Describe "New-CredentialStoreItem" { return [PSCredential]::new($UserName, $Password) } + It "Test missing Credential" { + $tmpCS = 'C:\CredentialStore.json' + New-CredentialStoreItem -Path $tmpCs -Shared -RemoteHost 'foobar3' + $writtenItem = Get-CredentialStoreItem -Path $tmpCS -Shared -RemoteHost 'foobar3' + $writtenItem.UserName | Should -Be "myUser" + } } - It "Test missing Credential" { - $tmpCS = 'C:\CredentialStore.json' - New-CredentialStoreItem -Path $tmpCs -Shared -RemoteHost 'foobar3' - $writtenItem = Get-CredentialStoreItem -Path $tmpCS -Shared -RemoteHost 'foobar3' - $writtenItem.UserName | Should -Be "myUser" - } -} -Context "General Exception handling" { - Mock Test-CredentialStore {return $false} - $UserName = 'myUser' - $Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force - Mock Get-Credential { - return [PSCredential]::new($UserName, $Password) + Context "General Exception handling" { + Mock Test-CredentialStore {return $false} + $UserName = 'myUser' + $Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force + Mock Get-Credential { + return [PSCredential]::new($UserName, $Password) + } + It "Missing CredentialStore should throw" { + New-CredentialStoreItem -Path 'C:\missingStore.json' -RemoteHost 'notrelevant' | Should -Throw "Could not add anything" + } } - It "Missing CredentialStore should throw" { - New-CredentialStoreItem -Path 'C:\missingStore.json' -RemoteHost 'notrelevant' | Should -Throw "Could not add anything" - } + }