129 lines
4.7 KiB
PowerShell
129 lines
4.7 KiB
PowerShell
|
. $PSScriptRoot\..\..\Load-PesterModules.ps1
|
||
|
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||
|
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.json\.tests\.', '.'
|
||
|
$functionPath = Join-Path -Path $here -ChildPath $sut
|
||
|
Write-Host "Overriding SUT: $functionPath"
|
||
|
Get-Module $sut | Remove-Module -Force
|
||
|
$moduleForMock = "Alkami.PowerShell.Configuration"
|
||
|
|
||
|
Describe "Get-AppSetting.json" {
|
||
|
$configPathUUT = "TestDrive:\appsettings.json"
|
||
|
$configContentUUT = @"
|
||
|
{
|
||
|
"SettingName" : "SettingValue",
|
||
|
"DeepSettingParent" : {
|
||
|
"DeepSettingChild": "DeepSettingValue"
|
||
|
},
|
||
|
"ReallyDeepSettingParent" : {
|
||
|
"DeepSettingParent" : {
|
||
|
"DeepSettingChild": "DeepSettingValue"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
"@
|
||
|
|
||
|
Context "Simple_Setting" {
|
||
|
Mock -ModuleName $moduleForMock -CommandName Write-Error -MockWith {}
|
||
|
Mock -ModuleName $moduleForMock -CommandName Write-Host -MockWith {}
|
||
|
Mock -ModuleName $moduleForMock -CommandName Write-Warning -MockWith {}
|
||
|
|
||
|
Set-Content -Path $configPathUUT -Value $configContentUUT
|
||
|
|
||
|
$value = Get-AppSetting -Path $configPathUUT -Key "SettingName"
|
||
|
|
||
|
It "got the right value" {
|
||
|
$value | Should -Be "SettingValue"
|
||
|
}
|
||
|
|
||
|
It "did not write an error" {
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Error -Times 0 -Scope Context
|
||
|
}
|
||
|
|
||
|
It "wrote no warnings to the console" {
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Warning -Times 0 -Scope Context
|
||
|
}
|
||
|
|
||
|
It "wrote no hosts messages" {
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Host -Times 0 -Scope Context
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Context "DeepSettingParent.RightName" {
|
||
|
Mock -ModuleName $moduleForMock -CommandName Write-Error -MockWith {}
|
||
|
Mock -ModuleName $moduleForMock -CommandName Write-Host -MockWith {}
|
||
|
Mock -ModuleName $moduleForMock -CommandName Write-Warning -MockWith {}
|
||
|
|
||
|
Set-Content -Path $configPathUUT -Value $configContentUUT
|
||
|
|
||
|
$value = Get-AppSetting -Path $configPathUUT -Key "DeepSettingParent:DeepSettingChild"
|
||
|
|
||
|
It "got the right value" {
|
||
|
$value | Should -Be "DeepSettingValue"
|
||
|
}
|
||
|
|
||
|
It "did not write an error" {
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Error -Times 0 -Scope Context
|
||
|
}
|
||
|
|
||
|
It "wrote no warnings to the console" {
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Warning -Times 0 -Scope Context
|
||
|
}
|
||
|
|
||
|
It "wrote no hosts messages" {
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Host -Times 0 -Scope Context
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Context "DeepSettingParent.WrongName" {
|
||
|
Mock -ModuleName $moduleForMock -CommandName Write-Error -MockWith {}
|
||
|
Mock -ModuleName $moduleForMock -CommandName Write-Host -MockWith {}
|
||
|
Mock -ModuleName $moduleForMock -CommandName Write-Warning -MockWith {}
|
||
|
|
||
|
Set-Content -Path $configPathUUT -Value $configContentUUT
|
||
|
|
||
|
$value = Get-AppSetting -Path $configPathUUT -Key "DeepSettingParent:SettingName"
|
||
|
|
||
|
It "got the right value" {
|
||
|
$value | Should -BeNull
|
||
|
}
|
||
|
|
||
|
It "did not write an error" {
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Error -Times 0 -Scope Context
|
||
|
}
|
||
|
|
||
|
It "wrote a simple warning to the console" {
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Warning -Times 1 -Scope Context
|
||
|
}
|
||
|
|
||
|
It "wrote no hosts messages" {
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Host -Times 0 -Scope Context
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Context "ReallyDeepSettingParent" {
|
||
|
Mock -ModuleName $moduleForMock -CommandName Write-Error -MockWith {}
|
||
|
Mock -ModuleName $moduleForMock -CommandName Write-Host -MockWith {}
|
||
|
Mock -ModuleName $moduleForMock -CommandName Write-Warning -MockWith {}
|
||
|
|
||
|
Set-Content -Path $configPathUUT -Value $configContentUUT
|
||
|
|
||
|
$value = Get-AppSetting -Path $configPathUUT -Key "ReallyDeepSettingParent:DeepSettingParent:SettingName"
|
||
|
|
||
|
It "got the right value" {
|
||
|
$value | Should -BeNull
|
||
|
}
|
||
|
|
||
|
It "did not write an error" {
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Error -Times 0 -Scope Context
|
||
|
}
|
||
|
|
||
|
It "wrote a simple warning to the console" {
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Warning -Times 1 -Scope Context
|
||
|
}
|
||
|
|
||
|
It "wrote no hosts messages" {
|
||
|
Assert-MockCalled -ModuleName $moduleForMock -CommandName Write-Host -Times 0 -Scope Context
|
||
|
}
|
||
|
}
|
||
|
}
|