This repository has been archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
293 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#region HEADER | ||
$RepoRoot = (Get-GitDirectory).replace('\.git', '') | ||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' | ||
$sut = $sut -replace "\d{2}`_", '' | ||
$suthome = (Get-ChildItem -Path $RepoRoot -Exclude ".\tests\" -Filter $sut -Recurse).FullName | ||
# Skip try loading the source file if it doesn't exists. | ||
If ($suthome.Length -gt 0) { | ||
. $suthome | ||
} | ||
Else { | ||
Write-Warning ("Could not find source file {0}" -f $sut) | ||
} | ||
|
||
# load additional functions defined in the repository. Replace the expression <FunctionName>. | ||
. (Get-ChildItem -Path $RepoRoot -Filter "Get-RandomKey.ps1" -Recurse).FullName | ||
|
||
#endregion HEADER | ||
|
||
Describe "Set-ChallengeFile" { | ||
Context "Tests with custom path" { | ||
It "Working dir and path not exist" { | ||
{Set-ChallengeFile -Path 'C:\PSCredentialStore\Challenge.bin'} | Should -Not -Throw | ||
} | ||
It "No parameter and non file should return true" { | ||
if (Test-Path -Path ("{0}\PSCredentialStore\Challenge.bin" -f $env:ProgramData)) { | ||
Remove-Item -Path ("{0}\PSCredentialStore\Challenge.bin" -f $env:ProgramData) | ||
} | ||
Set-ChallengeFile | ||
Test-Path -Path ("{0}\PSCredentialStore\Challenge.bin" -f $env:ProgramData) | Should -Be $true | ||
} | ||
It "Existing Credential file should return error" { | ||
{ Set-ChallengeFile } | Should -Throw | ||
Remove-Item -Path ("{0}\PSCredentialStore\Challenge.bin" -f $env:ProgramData) | ||
} | ||
It "Use -Force switch should create a new challenge file" { | ||
# prepare for test and clean up old data | ||
if (Test-Path -Path ("{0}\PSCredentialStore\Challenge.bin" -f $env:ProgramData)) { | ||
Remove-Item -Path ("{0}\PSCredentialStore\Challenge.bin" -f $env:ProgramData) | ||
} | ||
Set-ChallengeFile | ||
{ Set-ChallengeFile -Force } | Should -Not -Throw | ||
} | ||
It "Test directory creation for shared store" { | ||
if (Test-Path -Path ("{0}\PSCredentialStore" -f $env:ProgramData)) { | ||
Remove-Item -Path ("{0}\PSCredentialStore" -f $env:ProgramData) -Force -Recurse | ||
} | ||
Set-ChallengeFile | ||
Test-Path -Path ("{0}\PSCredentialStore" -f $env:ProgramData) | Should -Be $true | ||
} | ||
} | ||
Context "General Exception handling" { | ||
Mock New-Item {throw "foobar exception"} | ||
It "Test exception handling if the root directory could not be created" { | ||
if (Test-Path -Path ("{0}\PSCredentialStore" -f $env:ProgramData)) { | ||
Remove-Item -Path ("{0}\PSCredentialStore" -f $env:ProgramData) -Force -Recurse | ||
} | ||
{ Set-ChallengeFile } | Should -Throw "Could not create the parent data dir" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#region HEADER | ||
$RepoRoot = (Get-GitDirectory).replace('\.git', '') | ||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' | ||
$sut = $sut -replace "\d{2}`_", '' | ||
$suthome = (Get-ChildItem -Path $RepoRoot -Exclude ".\tests\" -Filter $sut -Recurse).FullName | ||
# Skip try loading the source file if it doesn't exists. | ||
If ($suthome.Length -gt 0) { | ||
. $suthome | ||
} | ||
Else { | ||
Write-Warning ("Could not find source file {0}" -f $sut) | ||
} | ||
|
||
# load additional functions defined in the repository. Replace the expression <FunctionName>. | ||
#. (Get-ChildItem -Path $RepoRoot -Filter "Test-ChallengeFile.ps1" -Recurse).FullName | ||
|
||
#endregion HEADER | ||
|
||
Describe "Test-ChallengeFile" { | ||
Context "Basic input tests" { | ||
Mock Test-Path {return $true} | ||
It "No parameter with existing challenge file" { | ||
{Test-ChallengeFile} | Should -Not -Throw | ||
} | ||
It "No parameter and existing file should return true" { | ||
Test-ChallengeFile | Should -Be $true | ||
} | ||
} | ||
Context "Execute with parameter" { | ||
$TestChFile = "{0}\resources\cs\Challenge.bin" -f $RepoRoot | ||
It "Provide valid path" { | ||
Test-ChallengeFile -Path $TestChFile | Should -Be $true | ||
} | ||
It "Provide fake path" { | ||
Test-ChallengeFile -Path "C:\notexisting.bin" | Should -Be $false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#region HEADER | ||
$RepoRoot = (Get-GitDirectory).replace('\.git', '') | ||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' | ||
$sut = $sut -replace "\d{2}`_", '' | ||
$suthome = (Get-ChildItem -Path $RepoRoot -Exclude ".\tests\" -Filter $sut -Recurse).FullName | ||
# Skip try loading the source file if it doesn't exists. | ||
If ($suthome.Length -gt 0) { | ||
. $suthome | ||
} | ||
Else { | ||
Write-Warning ("Could not find source file {0}" -f $sut) | ||
} | ||
|
||
# load additional functions defined in the repository. Replace the expression <FunctionName>. | ||
# . (Get-ChildItem -Path $RepoRoot -Filter "<FunctionName>.ps1" -Recurse).FullName | ||
|
||
#endregion HEADER | ||
|
||
Describe "Get-ModuleBase" { | ||
Context "Basic syntax check" { | ||
It "Test1: Should not throw" { | ||
{ Get-ModuleBase } | Should -Not -Throw | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#region HEADER | ||
$RepoRoot = (Get-GitDirectory).replace('\.git', '') | ||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' | ||
$sut = $sut -replace "\d{2}`_", '' | ||
$suthome = (Get-ChildItem -Path $RepoRoot -Exclude ".\tests\" -Filter $sut -Recurse).FullName | ||
# Skip try loading the source file if it doesn't exists. | ||
If ($suthome.Length -gt 0) { | ||
. $suthome | ||
} | ||
Else { | ||
Write-Warning ("Could not find source file {0}" -f $sut) | ||
} | ||
|
||
# load additional functions defined in the repository. Replace the expression <FunctionName>. | ||
# . (Get-ChildItem -Path $RepoRoot -Filter "<FunctionName>.ps1" -Recurse).FullName | ||
|
||
#endregion HEADER | ||
|
||
Describe "Get-RandomKey" { | ||
Context "Basic input tests" { | ||
It "Test1: Should throw if wrong size is given" { | ||
{Get-RandomKey -size 43} | Should -Throw | ||
} | ||
} | ||
Context "Basic syntax check" { | ||
It "Test1: Should return a key with a length of 16" { | ||
$Key = Get-RandomKey -size 16 | ||
$Key.length | Should -Be 16 | ||
} | ||
It "Test2: Should return a key with a length of 24" { | ||
$Key = Get-RandomKey -size 24 | ||
$Key.length | Should -Be 24 | ||
} | ||
It "Test3: Should return a key with a length of 32" { | ||
$Key = Get-RandomKey -size 32 | ||
$Key.length | Should -Be 32 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#region HEADER | ||
$RepoRoot = (Get-GitDirectory).replace('\.git', '') | ||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' | ||
$sut = $sut -replace "\d{2}`_", '' | ||
$suthome = (Get-ChildItem -Path $RepoRoot -Exclude ".\tests\" -Filter $sut -Recurse).FullName | ||
# Skip try loading the source file if it doesn't exists. | ||
If ($suthome.Length -gt 0) { | ||
. $suthome | ||
} | ||
Else { | ||
Write-Warning ("Could not find source file {0}" -f $sut) | ||
} | ||
|
||
# load additional functions defined in the repository. Replace the expression <FunctionName>. | ||
#. (Get-ChildItem -Path $RepoRoot -Filter "<FunctionName>.ps1" -Recurse).FullName | ||
|
||
#endregion HEADER | ||
|
||
Describe "Test-ModuleName" { | ||
Context "Basic input tests" { | ||
It "Testing standard module should not throw" { | ||
{ Test-Module -Name 'PowerShellGet' -Type Module } | Should -Not -Throw | ||
} | ||
It "Existing module should return true" { | ||
Test-Module -Name 'PowerShellGet' -Type Module | Should -Be $true | ||
} | ||
} | ||
Context "Custom Type tests" { | ||
It "Using custom type should throw" { | ||
{ Test-Module -Name "foobarr" -Type Custom} | Should -Throw | ||
} | ||
} | ||
Context "Working with PSSnapins" { | ||
It "Loading first PSSnaping should not throw " { | ||
$Snap = Get-PSSnapin -Registered | Select-Object -First 1 | ||
{ Test-Module -Name $Snap.Name -Type PSSnapin } | Should -Not -Throw | ||
} | ||
It "Loading first PSSnaping should return true" { | ||
$Snap = Get-PSSnapin -Registered | Select-Object -First 1 | ||
Test-Module -Name $Snap.Name -Type PSSnapin | Should -Be $true | ||
} | ||
It "Not existing PSSnaping should return false" { | ||
Test-Module -Name 'foobar2000' -Type PSSnapin | Should -Be $false | ||
} | ||
It "StopifFails switch should thrown an error" { | ||
{Test-Module -Name 'foobar2000' -Type PSSnapin -StopIfFails }| Should -Throw | ||
} | ||
} | ||
Context "Working with modules" { | ||
It "Loading first module should not throw " { | ||
$Mod = Get-Module -ListAvailable | Select-Object -First 1 | ||
{ Test-Module -Name $Mod.Name -Type Module } | Should -Not -Throw | ||
} | ||
It "Loading first module should return true" { | ||
$Snap = Get-Module -ListAvailable | Select-Object -First 1 | ||
Test-Module -Name $Snap.Name -Type Module | Should -Be $true | ||
} | ||
It "Not existing module should return false" { | ||
Test-Module -Name 'foobar2000' -Type Module | Should -Be $false | ||
} | ||
It "StopifFails switch should thrown an error" { | ||
{Test-Module -Name 'foobar2000' -Type Module -StopIfFails }| Should -Throw | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters