forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonObject.Tests.ps1
More file actions
46 lines (40 loc) · 1.25 KB
/
Copy pathJsonObject.Tests.ps1
File metadata and controls
46 lines (40 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Describe 'Unit tests for JsonObject' -tags "CI" {
function ShouldThrow
{
param (
[Parameter(ValueFromPipeline = $true)]
$InputObject,
[Parameter(Position = 0)]
$ExpectedException
)
try
{
& $InputObject
throw "Should throw exception"
}
catch
{
$_.FullyQualifiedErrorId | should be $ExpectedException
}
}
$validStrings = @(
@{ name = "empty"; str = "" }
@{ name = "spaces"; str = " " }
@{ name = "object"; str = "{a:1}" }
)
It 'no error for valid string - <name>' -TestCase $validStrings {
param ($str)
$errRecord = $null
[Microsoft.PowerShell.Commands.JsonObject]::ConvertFromJson($str, [ref]$errRecord)
$errRecord | Should BeNullOrEmpty
}
$invalidStrings = @(
@{ name = "plain text"; str = "plaintext" }
@{ name = "part"; str = '{"a" :' }
)
It 'throw ArgumentException for invalid string - <name>' -TestCase $invalidStrings {
param ($str)
$errRecord = $null
{ [Microsoft.PowerShell.Commands.JsonObject]::ConvertFromJson($str, [ref]$errRecord) } | ShouldThrow 'ArgumentException'
}
}