File size: 2,008 Bytes
8c763fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

Describe 'Tests for lossless rehydration of serialized types.' -Tags 'CI' {
    BeforeAll {
        $cmdBp = Set-PSBreakpoint -Command Get-Process
        $varBp = Set-PSBreakpoint -Variable ?
        $lineBp = Set-PSBreakpoint -Script $PSScriptRoot/PSSerializer.Tests.ps1 -Line 1

        function ShouldRehydrateLosslessly {
            [CmdletBinding()]
            param(
                [Parameter(Mandatory, ValueFromPipeline)]
                [ValidateNotNull()]
                [System.Management.Automation.Breakpoint]
                $Breakpoint
            )
            $dehydratedBp = [System.Management.Automation.PSSerializer]::Serialize($Breakpoint)
            $rehydratedBp = [System.Management.Automation.PSSerializer]::Deserialize($dehydratedBp)
            foreach ($property in $Breakpoint.PSObject.Properties) {
                $bpValue = $Breakpoint.$($property.Name)
                $rehydratedBpValue = $rehydratedBp.$($property.Name)
                $propertyType = $property.TypeNameOfValue -as [System.Type]
                if ($null -eq $bpValue) {
                    $rehydratedBpValue | Should -Be $null
                } elseif ($propertyType.IsValueType) {
                    $bpValue | Should -Be $rehydratedBpValue
                } elseif ($propertyType -eq [string]) {
                    $bpValue | Should -BeExactly $rehydratedBpValue
                } else {
                    $bpValue.ToString() | Should -BeExactly $rehydratedBpValue.ToString()
                }
            }
        }
    }

    AfterAll {
        Remove-PSBreakpoint -Breakpoint $cmdBp,$varBp,$lineBp
    }

    It 'Losslessly rehydrates command breakpoints' {
        $cmdBp | ShouldRehydrateLosslessly
    }

    It 'Losslessly rehydrates variable breakpoints' {
        $varBp | ShouldRehydrateLosslessly
    }

    It 'Losslessly rehydrates line breakpoints' {
        $lineBp | ShouldRehydrateLosslessly
    }
}