@@ -5,7 +5,6 @@ BeforeAll {
55 $settingsTestDirectory = [System.IO.Path ]::Combine($PSScriptRoot , " SettingsTest" )
66 $project1Root = [System.IO.Path ]::Combine($settingsTestDirectory , " Project1" )
77 $project2Root = [System.IO.Path ]::Combine($settingsTestDirectory , " Project2" )
8- $settingsTypeName = ' Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings'
98}
109
1110Describe " Settings Precedence" {
@@ -53,7 +52,7 @@ Describe "Settings Class" {
5352 ) {
5453 Param ($Name )
5554
56- $settings = New-Object - TypeName $settingsTypeName - ArgumentList @ {}
55+ $settings = [ Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings ]::Create( @ {})
5756 ${settings} .${Name}.Count | Should - Be 0
5857 }
5958
@@ -67,7 +66,7 @@ Describe "Settings Class" {
6766 Context " When a string is provided for IncludeRules in a hashtable" {
6867 BeforeAll {
6968 $ruleName = " PSAvoidCmdletAliases"
70- $settings = New-Object - TypeName $settingsTypeName - ArgumentList @ { IncludeRules = $ruleName }
69+ $settings = [ Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings ]::Create( @ { IncludeRules = $ruleName })
7170 }
7271
7372 It " Should return an IncludeRules array with 1 element" {
@@ -88,7 +87,7 @@ Describe "Settings Class" {
8887 }
8988 }
9089 }
91- $settings = New-Object - TypeName $settingsTypeName - ArgumentList $ settingsHashtable
90+ $settings = [ Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings ]::Create( $ settingsHashtable)
9291 }
9392
9493 It ' Should return the rule arguments' {
@@ -113,7 +112,7 @@ Describe "Settings Class" {
113112 }
114113 }
115114 }
116- $settings = New-Object - TypeName $settingsTypeName - ArgumentList $ settingsHashtable
115+ $settings = [ Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings ]::Create( $ settingsHashtable)
117116 }
118117
119118 It " Should return the rule arguments" {
@@ -131,8 +130,9 @@ Describe "Settings Class" {
131130
132131 Context " When a settings file path is provided" {
133132 BeforeAll {
134- $settings = New-Object - TypeName $settingsTypeName `
135- - ArgumentList ([System.IO.Path ]::Combine($project1Root , " ExplicitSettings.psd1" ))
133+ $settings = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings ]::Create(
134+ ([System.IO.Path ]::Combine($project1Root , " ExplicitSettings.psd1" ))
135+ )
136136 $expectedNumberOfIncludeRules = 3
137137 }
138138
@@ -168,7 +168,7 @@ Describe "Settings Class" {
168168 CustomRulePath = $rulePath
169169 }
170170
171- $settings = New-Object - TypeName $settingsTypeName - ArgumentList $ settingsHashtable
171+ $settings = [ Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings ]::Create( $ settingsHashtable)
172172 $settings.CustomRulePath.Count | Should - Be 1
173173 $settings.CustomRulePath [0 ] | Should - Be $rulePath
174174 }
@@ -179,15 +179,16 @@ Describe "Settings Class" {
179179 CustomRulePath = $rulePaths
180180 }
181181
182- $settings = New-Object - TypeName $settingsTypeName - ArgumentList $ settingsHashtable
182+ $settings = [ Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings ]::Create( $ settingsHashtable)
183183 $settings.CustomRulePath.Count | Should - Be $rulePaths.Count
184184 0 .. ($rulePaths.Count - 1 ) | ForEach-Object { $settings.CustomRulePath [$_ ] | Should - Be $rulePaths [$_ ] }
185185
186186 }
187187
188188 It " Should detect the parameter in a settings file" {
189- $settings = New-Object - TypeName $settingsTypeName `
190- - ArgumentList ([System.IO.Path ]::Combine($project1Root , " CustomRulePathSettings.psd1" ))
189+ $settings = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings ]::Create(
190+ ([System.IO.Path ]::Combine($project1Root , " CustomRulePathSettings.psd1" ))
191+ )
191192 $settings.CustomRulePath.Count | Should - Be 2
192193 }
193194 }
@@ -197,28 +198,29 @@ Describe "Settings Class" {
197198 $settingsHashtable = @ {}
198199 $settingsHashtable.Add ($ParamName , $true )
199200
200- $settings = New-Object - TypeName $settingsTypeName - ArgumentList $ settingsHashtable
201+ $settings = [ Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings ]::Create( $ settingsHashtable)
201202 $settings ." $ParamName " | Should - BeTrue
202203 }
203204
204205 It " <ParamName>: Should correctly set the value if a boolean is given - false" - TestCases $customRuleParameterTestCases {
205206 $settingsHashtable = @ {}
206207 $settingsHashtable.Add ($ParamName , $false )
207208
208- $settings = New-Object - TypeName $settingsTypeName - ArgumentList $ settingsHashtable
209+ $settings = [ Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings ]::Create( $ settingsHashtable)
209210 $settings ." $ParamName " | Should - BeFalse
210211 }
211212
212213 It " <ParamName>: Should throw if a non-boolean value is given" - TestCases $customRuleParameterTestCases {
213214 $settingsHashtable = @ {}
214215 $settingsHashtable.Add ($ParamName , " some random string" )
215216
216- { New-Object - TypeName $settingsTypeName - ArgumentList $ settingsHashtable } | Should - Throw
217+ { [ Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings ]::Create( $ settingsHashtable) } | Should - Throw
217218 }
218219
219220 It " <ParamName>: Should detect the parameter in a settings file" - TestCases $customRuleParameterTestCases {
220- $settings = New-Object - TypeName $settingsTypeName `
221- - ArgumentList ([System.IO.Path ]::Combine($project1Root , " CustomRulePathSettings.psd1" ))
221+ $settings = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings ]::Create(
222+ ([System.IO.Path ]::Combine($project1Root , " CustomRulePathSettings.psd1" ))
223+ )
222224 $settings ." $ParamName " | Should - BeTrue
223225 }
224226 }
@@ -378,33 +380,33 @@ Describe "Settings Class" {
378380 )
379381 }
380382
381- Context " FindSettingsMode" {
382- BeforeAll {
383- $findSettingsMode = ($settingsTypeName -as [type ]).GetMethod(
384- ' FindSettingsMode' ,
385- [System.Reflection.BindingFlags ]::NonPublic -bor [System.Reflection.BindingFlags ]::Static )
386-
387- $outputObject = [System.Object ]::new()
388- }
389-
390- It " Should detect hashtable" {
391- $settings = @ {}
392- $findSettingsMode.Invoke ($null , @ ($settings , $null , [ref ]$outputObject )) | Should - Be " Hashtable"
393- }
394-
395- It " Should detect hashtable wrapped by a PSObject" {
396- $settings = [PSObject ]@ {} # Force the settings hashtable to be wrapped
397- $findSettingsMode.Invoke ($null , @ ($settings , $null , [ref ]$outputObject )) | Should - Be " Hashtable"
398- }
399-
400- It " Should detect string" {
401- $settings = " "
402- $findSettingsMode.Invoke ($null , @ ($settings , $null , [ref ]$outputObject )) | Should - Be " File"
403- }
404-
405- It " Should detect string wrapped by a PSObject" {
406- $settings = [PSObject ]" " # Force the settings string to be wrapped
407- $findSettingsMode.Invoke ($null , @ ($settings , $null , [ref ]$outputObject )) | Should - Be " File"
408- }
409- }
383+ # Context "FindSettingsMode" {
384+ # BeforeAll {
385+ # $findSettingsMode = ('Microsoft.Windows.PowerShell.ScriptAnalyzer.Settings' -as [type]).GetMethod(
386+ # 'FindSettingsMode',
387+ # [System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Static)
388+
389+ # $outputObject = [System.Object]::new()
390+ # }
391+
392+ # It "Should detect hashtable" {
393+ # $settings = @{}
394+ # $findSettingsMode.Invoke($null, @($settings, $null, [ref]$outputObject)) | Should -Be "Hashtable"
395+ # }
396+
397+ # It "Should detect hashtable wrapped by a PSObject" {
398+ # $settings = [PSObject]@{} # Force the settings hashtable to be wrapped
399+ # $findSettingsMode.Invoke($null, @($settings, $null, [ref]$outputObject)) | Should -Be "Hashtable"
400+ # }
401+
402+ # It "Should detect string" {
403+ # $settings = ""
404+ # $findSettingsMode.Invoke($null, @($settings, $null, [ref]$outputObject)) | Should -Be "File"
405+ # }
406+
407+ # It "Should detect string wrapped by a PSObject" {
408+ # $settings = [PSObject]"" # Force the settings string to be wrapped
409+ # $findSettingsMode.Invoke($null, @($settings, $null, [ref]$outputObject)) | Should -Be "File"
410+ # }
411+ # }
410412}
0 commit comments