From d0c62017a9f9a78780a15be549ffdfdcba8f337e Mon Sep 17 00:00:00 2001 From: TingLiu6 Date: Mon, 8 Aug 2016 01:46:55 -0700 Subject: [PATCH] Add NullableBooleanDCR Pester Test --- .../enginecore/NullableBooleanDCR.Tests.ps1 | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/powershell/enginecore/NullableBooleanDCR.Tests.ps1 diff --git a/test/powershell/enginecore/NullableBooleanDCR.Tests.ps1 b/test/powershell/enginecore/NullableBooleanDCR.Tests.ps1 new file mode 100644 index 000000000..5b1cb4515 --- /dev/null +++ b/test/powershell/enginecore/NullableBooleanDCR.Tests.ps1 @@ -0,0 +1,50 @@ +Describe "Nullable Boolean DCR Tests" -Tags "CI" { + BeforeAll { + function ParserTestFunction + { + param([bool]$First) $PSBoundParameters + } + + function parsertest-bool2 + { + [CmdletBinding()] + param ( + [Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)] [bool]$First = $false + ) + + Process { + return $PSBoundParameters + } + } + + $testCases = @( + @{ Arg = $true; Expected = $true } + @{ Arg = 1; Expected = $true } + @{ Arg = 1.28; Expected = $true } + @{ Arg = (-2.32); Expected = $true } + + @{ Arg = $false; Expected = $false } + @{ Arg = 0; Expected = $false } + @{ Arg = 0.00; Expected = $false } + @{ Arg = (1 - 1); Expected = $false } + ) + } + + It 'Test a boolean parameter accepts positional values, input:, expect:' -TestCases $testCases { + param($Arg, $Expected) + (parsertestfunction $Arg).Values[0] | Should Be $Expected + (parsertest-bool2 $Arg).Values[0] | Should Be $Expected + } + + It 'Test a boolean parameter accepts values specified with a colon, input:, expect:' -TestCases $testCases { + param($Arg, $Expected) + (parsertestfunction -First:$Arg).Values[0] | Should Be $Expected + (parsertest-bool2 -First:$Arg).Values[0] | Should Be $Expected + } + + It 'Test a boolean parameter accepts values specified with general format, input:, expect:' -TestCases $testCases { + param($Arg, $Expected) + (parsertestfunction -First $Arg).Values[0] | Should Be $Expected + (parsertest-bool2 -First $Arg).Values[0] | Should Be $Expected + } +}