Increase code coverage #22

Merged
OCram85 merged 34 commits from dev into master 2018-03-21 12:16:09 +01:00
1 changed files with 21 additions and 21 deletions
Showing only changes of commit 82da4dc20a - Show all commits

View File

@ -73,29 +73,29 @@ Describe "New-CredentialStoreItem" {
} }
} }
Context "Test optional parameter lookup" { Context "Test optional parameter lookup" {
$UserName = 'myUser'
$Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force
Mock Get-Credential { Mock Get-Credential {
return [PSCustomObject]@{ return [PSCredential]::new($UserName, $Password)
UserName = 'myUser'
Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force
}
}
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" { It "Test missing Credential" {
Mock Test-CredentialStore {return $false} $tmpCS = 'C:\CredentialStore.json'
Mock Get-Credential { New-CredentialStoreItem -Path $tmpCs -Shared -RemoteHost 'foobar3'
return [PSCustomObject]@{ $writtenItem = Get-CredentialStoreItem -Path $tmpCS -Shared -RemoteHost 'foobar3'
UserName = 'myUser' $writtenItem.UserName | Should -Be "myUser"
Password = ConvertTo-SecureString -String "mypasswd" -AsPlainText -Force }
} }
} Context "General Exception handling" {
It "Missing CredentialStore should throw" { Mock Test-CredentialStore {return $false}
New-CredentialStoreItem -Path 'C:\missingStore.json' -RemoteHost 'notrelevant' | Should -Throw "Could not add anything" $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"
} }
} }