src/types.ps1

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

class Requirement {
    [string] $Namespace
    [ValidateNotNullOrEmpty()]
    [string] $Describe
    [scriptblock] $Test
    [scriptblock] $Set
    [string[]] $DependsOn = @()
    [string] ToString() {
        if ($this.Namespace) {
            return $this.Namespace + ">" + $this.Describe
        }
        else {
            return $this.Describe
        }
    }
}

enum Method {
    Test
    Set
    Validate
}

enum LifecycleState {
    Start
    Stop
}

class RequirementEvent {
    [datetime] $Date
    [Method] $Method
    [LifecycleState] $State
    [object] $Result
    [Requirement] $Requirement
    hidden Init([Requirement]$Requirement, [Method]$Method, [LifecycleState]$State, $Result) {
        $this.Date = Get-Date
        $this.Method = $Method
        $this.State = $State
        $this.Result = $Result
        $this.Requirement = $Requirement
    }
    RequirementEvent([Requirement]$Requirement, [Method]$Method, [LifecycleState]$State, $Result) {
        $this.Init($Requirement, $Method, $State, $Result)
    }
    RequirementEvent([Requirement]$Requirement, [Method]$Method, [LifecycleState]$State) {
        $this.Init($Requirement, $Method, $State, $null)
    }
}