-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathTestClassResource.psm1
More file actions
148 lines (118 loc) · 3.15 KB
/
TestClassResource.psm1
File metadata and controls
148 lines (118 loc) · 3.15 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
using namespace System.Collections.Generic
enum EnumPropEnumeration {
Unexpected
Expected
}
enum Ensure {
Present
Absent
}
class BaseTestClass {
[DscProperty()]
[string] $BaseProperty
}
[DscResource()]
class TestClassResource : BaseTestClass {
[DscProperty(Key)]
[string] $Name
[DscProperty()]
[string] $Prop1
[DscProperty()]
[hashtable] $HashTableProp
[DscProperty()]
[string] $EnumProp
[DscProperty()]
[PSCredential] $Credential
[DscProperty()]
[Ensure] $Ensure
[string] $NonDscProperty # This property shouldn't be in results data
hidden
[string] $HiddenNonDscProperty # This property shouldn't be in results data
hidden
[DscProperty()]
[string] $HiddenDscProperty # This property should be in results data, but is an anti-pattern.
[void] Set() {
}
[bool] Test() {
if (($this.Name -eq "TestClassResource1") -and ($this.Prop1 -eq "ValueForProp1")) {
return $true
}
else {
return $false
}
}
[TestClassResource] Get() {
if ($this.Name -eq "TestClassResource1") {
$this.Prop1 = "ValueForProp1"
}
else {
$this.Prop1 = $env:DSC_CONFIG_ROOT
}
$this.EnumProp = ([EnumPropEnumeration]::Expected).ToString()
return $this
}
static [TestClassResource[]] Export() {
$resultList = [List[TestClassResource]]::new()
$resultCount = 5
if ($env:TestClassResourceResultCount) {
$resultCount = $env:TestClassResourceResultCount
}
1..$resultCount | % {
$obj = New-Object TestClassResource
$obj.Name = "Object$_"
$obj.Prop1 = "Property of object$_"
$resultList.Add($obj)
}
return $resultList.ToArray()
}
static [TestClassResource[]] Export([bool]$UseExport) {
if ($UseExport) {
return [TestClassResource]::Export()
}
else {
$resultList = [List[TestClassResource]]::new()
$resultCount = 5
if ($env:TestClassResourceResultCount) {
$resultCount = $env:TestClassResourceResultCount
}
1..$resultCount | % {
$obj = New-Object TestClassResource
$obj.Name = "Object$_"
$obj.Prop1 = "Property of object$_"
$resultList.Add($obj)
}
}
return $resultList.ToArray()
}
[hashtable] WhatIf() {
$out = @{
Name = $this.Name
_metadata = @{
whatIf = "A test message from the WhatIf method of TestClassResource"
}
}
return $out
}
}
[DscResource()]
class NoExport: BaseTestClass {
[DscProperty(Key)]
[string] $Name
[DscProperty()]
[string] $Prop1
[DscProperty()]
[string] $EnumProp
[void] Set() {
}
[bool] Test() {
return $true
}
[NoExport] Get() {
return $this
}
}
function Test-World() {
"Hello world from PSTestModule!"
}