4343 Context ' When the system is in the desired present state' {
4444 BeforeEach {
4545 Mock - CommandName Get-CimInstance - MockWith {
46- return New-Object Object |
47- Add-Member - MemberType NoteProperty - Name AutomaticManagedPagefile - Value $false - PassThru - Force |
48- Add-Member - MemberType NoteProperty - Name Name - Value " D:\pagefile.sys" - PassThru - Force
46+ [PSObject ] @ { AutomaticManagedPageFile = $false ; Name = ' D:\pagefile.sys' }
4947 } - ModuleName $script :DSCResourceName - Verifiable
5048 }
5149
@@ -59,10 +57,11 @@ try {
5957 Context ' When the system is not in the desired present state' {
6058 BeforeEach {
6159 Mock - CommandName Get-CimInstance - MockWith {
62- return New-Object Object |
63- Add-Member - MemberType NoteProperty - Name InitialSize - Value 0 - PassThru - Force |
64- Add-Member - MemberType NoteProperty - Name MaximumSize - Value 0 - PassThru - Force |
65- Add-Member - MemberType NoteProperty - Name Name - Value " C:\pagefile.sys" - PassThru - Force
60+ [PSObject ] @ {
61+ InitialSize = 0
62+ MaximumSize = 0
63+ Name = " C:\pagefile.sys"
64+ }
6665 } - ModuleName $script :DSCResourceName - Verifiable
6766 }
6867
@@ -109,11 +108,12 @@ try {
109108 Mock - CommandName New-CimInstance - MockWith {} - ModuleName $script :DSCResourceName - Verifiable
110109 Mock - CommandName Remove-CimInstance - MockWith {} - ModuleName $script :DSCResourceName - Verifiable
111110 Mock - CommandName Get-CimInstance - MockWith {
112- New-Object psobject |
113- Add-Member - MemberType NoteProperty - Name InitialSize - Value 0 - PassThru - Force |
114- Add-Member - MemberType NoteProperty - Name MaximumSize - Value 1338 - PassThru - Force |
115- Add-Member - MemberType NoteProperty - Name Name - Value " D:\pagefile.sys" - PassThru - Force |
116- Add-Member - MemberType NoteProperty - Name AutomaticManagedPageFile - Value $false - PassThru - Force
111+ [PSObject ] @ {
112+ InitialSize = 0
113+ MaximumSize = 1338
114+ Name = " D:\pagefile.sys"
115+ AutomaticManagedPageFile = $false
116+ }
117117 }
118118
119119 $testParameters = @ {
@@ -122,7 +122,9 @@ try {
122122 InitialSize = 0
123123 MaximumSize = 1337
124124 }
125- It ' Should throw if no valid drive letter has been used' { { Set-TargetResource @testParameters } | Should Throw
125+ It ' Should throw if no valid drive letter has been used'
126+ {
127+ { Set-TargetResource @testParameters } | Should Throw
126128 }
127129
128130 $testParameters = @ {
@@ -131,7 +133,9 @@ try {
131133 InitialSize = 0
132134 MaximumSize = 1337
133135 }
134- It ' Should throw if the drive is not ready' { { Set-TargetResource @testParameters } | Should Throw
136+ It ' Should throw if the drive is not ready'
137+ {
138+ { Set-TargetResource @testParameters } | Should Throw
135139 }
136140 }
137141
@@ -147,41 +151,42 @@ try {
147151 InitialSize = 0
148152 MaximumSize = 1337
149153 }
150- }
154+ }
155+
156+ $pageFileObject = [PSObject ] @ {
157+ InitialSize = 0
158+ MaximumSize = 1338
159+ Name = " D:\pagefile.sys"
160+ AutomaticManagedPageFile = $false
161+ }
162+
151163 Mock - CommandName Get-CimInstance - MockWith {
152- New-Object psobject |
153- Add-Member - MemberType NoteProperty - Name InitialSize - Value 0 - PassThru - Force |
154- Add-Member - MemberType NoteProperty - Name MaximumSize - Value 1337 - PassThru - Force |
155- Add-Member - MemberType NoteProperty - Name Name - Value " D:\pagefile.sys" - PassThru - Force |
156- Add-Member - MemberType NoteProperty - Name AutomaticManagedPageFile - Value $false - PassThru - Force
164+ $pageFileObject.MaximumSize = 1337
165+ $pageFileObject
157166 }
158167 It ' Should return True if the input matches the actual values' {
159168 Test-TargetResource @testParameters | Should Be $true
160169 }
161170
162171 Mock - CommandName Get-CimInstance - MockWith {
163- New-Object psobject |
164- Add-Member - MemberType NoteProperty - Name InitialSize - Value 0 - PassThru - Force |
165- Add-Member - MemberType NoteProperty - Name MaximumSize - Value 1337 - PassThru - Force |
166- Add-Member - MemberType NoteProperty - Name Name - Value " D:\pagefile.sys" - PassThru - Force |
167- Add-Member - MemberType NoteProperty - Name AutomaticManagedPageFile - Value $true - PassThru - Force
172+ $pageFileObject.MaximumSize = 1337
173+ $pageFileObject.AutomaticManagedPageFile = $true
174+ $pageFileObject
168175 }
169176 It ' Should return False if the type is wrong' {
170177 Test-TargetResource @testParameters | Should Be $false
171178 }
172179
173180 Mock - CommandName Get-CimInstance - MockWith {
174- New-Object psobject |
175- Add-Member - MemberType NoteProperty - Name InitialSize - Value 0 - PassThru - Force |
176- Add-Member - MemberType NoteProperty - Name MaximumSize - Value 1338 - PassThru - Force |
177- Add-Member - MemberType NoteProperty - Name Name - Value " D:\pagefile.sys" - PassThru - Force |
178- Add-Member - MemberType NoteProperty - Name AutomaticManagedPageFile - Value $false - PassThru - Force
181+ $pageFileObject.MaximumSize = 1338
182+ $pageFileObject
179183 }
180184 It ' Should return False if InitialSize and/or MaximumSize do not match' {
181185 Test-TargetResource @testParameters | Should Be $false
182186 }
183187
184- Mock - CommandName Get-CimInstance - MockWith { # In this case Get-CimInstance returns an empty object
188+ Mock - CommandName Get-CimInstance - MockWith {
189+ # In this case Get-CimInstance returns an empty object
185190 }
186191 It ' Should return False if Name does not match' {
187192 Test-TargetResource @testParameters | Should Be $false
0 commit comments