Skip to content

Commit d3c79d8

Browse files
committed
Add strictmode
1 parent 49f2301 commit d3c79d8

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

tests/Unit/Classes/SqlReason.Tests.ps1

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,23 @@ Describe 'SqlReason' -Tag 'SqlReason' {
5454
Context 'When instantiating the class' {
5555
It 'Should not throw an error' {
5656
$script:mockSqlReasonInstance = InModuleScope -ScriptBlock {
57+
Set-StrictMode -Version 1.0
58+
5759
[SqlReason]::new()
5860
}
5961
}
6062

6163
It 'Should be of the correct type' {
62-
$mockSqlReasonInstance | Should -Not -BeNullOrEmpty
63-
$mockSqlReasonInstance.GetType().Name | Should -Be 'SqlReason'
64+
$script:mockSqlReasonInstance | Should -Not -BeNullOrEmpty
65+
$script:mockSqlReasonInstance.GetType().Name | Should -Be 'SqlReason'
6466
}
6567
}
6668

6769
Context 'When setting an reading values' {
6870
It 'Should be able to set value in instance' {
6971
$script:mockSqlReasonInstance = InModuleScope -ScriptBlock {
72+
Set-StrictMode -Version 1.0
73+
7074
$sqlReasonInstance = [SqlReason]::new()
7175

7276
$sqlReasonInstance.Code = 'SqlAudit:SqlAudit:Ensure'
@@ -77,8 +81,8 @@ Describe 'SqlReason' -Tag 'SqlReason' {
7781
}
7882

7983
It 'Should be able read the values from instance' {
80-
$mockSqlReasonInstance.Code | Should -Be 'SqlAudit:SqlAudit:Ensure'
81-
$mockSqlReasonInstance.Phrase = 'The property Ensure should be "Present", but was "Absent"'
84+
$script:mockSqlReasonInstance.Code | Should -Be 'SqlAudit:SqlAudit:Ensure'
85+
$script:mockSqlReasonInstance.Phrase | Should -Be 'The property Ensure should be "Present", but was "Absent"'
8286
}
8387
}
8488
}

tests/Unit/Classes/SqlResourceBase.Tests.ps1

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,16 @@ Describe 'SqlResourceBase' {
5757
Context 'When class is instantiated' {
5858
It 'Should not throw an exception' {
5959
InModuleScope -ScriptBlock {
60+
Set-StrictMode -Version 1.0
61+
6062
$null = [SqlResourceBase]::new()
6163
}
6264
}
6365

6466
It 'Should have a default constructor' {
6567
InModuleScope -ScriptBlock {
68+
Set-StrictMode -Version 1.0
69+
6670
$instance = [SqlResourceBase]::new()
6771
$instance | Should -Not -BeNullOrEmpty
6872
$instance.SqlServerObject | Should -BeNullOrEmpty
@@ -71,6 +75,8 @@ Describe 'SqlResourceBase' {
7175

7276
It 'Should be the correct type' {
7377
InModuleScope -ScriptBlock {
78+
Set-StrictMode -Version 1.0
79+
7480
$instance = [SqlResourceBase]::new()
7581
$instance.GetType().Name | Should -Be 'SqlResourceBase'
7682
}
@@ -82,11 +88,13 @@ Describe 'SqlResourceBase\GetServerObject()' -Tag 'GetServerObject' {
8288
Context 'When a server object does not exist' {
8389
BeforeAll {
8490
$mockSqlResourceBaseInstance = InModuleScope -ScriptBlock {
91+
Set-StrictMode -Version 1.0
92+
8593
[SqlResourceBase]::new()
8694
}
8795

8896
Mock -CommandName Connect-SqlDscDatabaseEngine -MockWith {
89-
return New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Server'
97+
return [Microsoft.SqlServer.Management.Smo.Server]::new()
9098
}
9199
}
92100

@@ -101,6 +109,8 @@ Describe 'SqlResourceBase\GetServerObject()' -Tag 'GetServerObject' {
101109
Context 'When property Credential is used' {
102110
BeforeAll {
103111
$mockSqlResourceBaseInstance = InModuleScope -ScriptBlock {
112+
Set-StrictMode -Version 1.0
113+
104114
[SqlResourceBase]::new()
105115
}
106116

@@ -124,6 +134,8 @@ Describe 'SqlResourceBase\GetServerObject()' -Tag 'GetServerObject' {
124134
Context 'When property Protocol is used' {
125135
BeforeAll {
126136
$mockSqlResourceBaseInstance = InModuleScope -ScriptBlock {
137+
Set-StrictMode -Version 1.0
138+
127139
[SqlResourceBase]::new()
128140
}
129141

@@ -144,6 +156,8 @@ Describe 'SqlResourceBase\GetServerObject()' -Tag 'GetServerObject' {
144156
Context 'When property Port is used' {
145157
BeforeAll {
146158
$mockSqlResourceBaseInstance = InModuleScope -ScriptBlock {
159+
Set-StrictMode -Version 1.0
160+
147161
[SqlResourceBase]::new()
148162
}
149163

@@ -165,10 +179,12 @@ Describe 'SqlResourceBase\GetServerObject()' -Tag 'GetServerObject' {
165179
Context 'When a server object already exist' {
166180
BeforeAll {
167181
$mockSqlResourceBaseInstance = InModuleScope -ScriptBlock {
182+
Set-StrictMode -Version 1.0
183+
168184
[SqlResourceBase]::new()
169185
}
170186

171-
$mockSqlResourceBaseInstance.SqlServerObject = New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Server'
187+
$mockSqlResourceBaseInstance.SqlServerObject = [Microsoft.SqlServer.Management.Smo.Server]::new()
172188
Mock -CommandName Connect-SqlDscDatabaseEngine
173189
}
174190

0 commit comments

Comments
 (0)