Skip to content

Commit 17ed078

Browse files
committed
Add mock GetCurrentState method to SqlAudit, SqlDatabasePermission, and SqlPermission tests
1 parent cead530 commit 17ed078

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

tests/Unit/Classes/SqlAudit.Tests.ps1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@ Describe 'SqlAudit\Set()' -Tag 'Set' {
243243
InstanceName = 'NamedInstance'
244244
Path = 'C:\Temp'
245245
} |
246+
# Mock method GetCurrentState() which is called by the base method Get()
247+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetCurrentState' -Value {
248+
return [System.Collections.Hashtable] @{
249+
Name = 'MockAuditName'
250+
InstanceName = 'NamedInstance'
251+
ServerName = Get-ComputerName
252+
}
253+
} -PassThru |
246254
# Mock method Modify which is called by the base method Set().
247255
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Modify' -Value {
248256
$script:mockMethodModifyCallCount += 1
@@ -314,7 +322,15 @@ Describe 'SqlAudit\Test()' -Tag 'Test' {
314322
Name = 'MockAuditName'
315323
InstanceName = 'NamedInstance'
316324
Path = 'C:\Temp'
317-
}
325+
} |
326+
# Mock method GetCurrentState() which is called by the base method Get()
327+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetCurrentState' -Value {
328+
return [System.Collections.Hashtable] @{
329+
Name = 'MockAuditName'
330+
InstanceName = 'NamedInstance'
331+
ServerName = Get-ComputerName
332+
}
333+
} -PassThru
318334
}
319335
}
320336

tests/Unit/Classes/SqlDatabasePermission.Tests.ps1

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,15 @@ Describe 'SqlDatabasePermission\Set()' -Tag 'Set' {
924924
}
925925
)
926926
} |
927+
# Mock method GetCurrentState() which is called by the base method Get()
928+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetCurrentState' -Value {
929+
return [System.Collections.Hashtable] @{
930+
Name = 'MockUserName'
931+
DatabaseName = 'MockDatabaseName'
932+
InstanceName = 'NamedInstance'
933+
ServerName = Get-ComputerName
934+
}
935+
} -PassThru |
927936
# Mock method Modify which is called by the base method Set().
928937
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Modify' -Value {
929938
$script:mockMethodModifyCallCount += 1
@@ -1013,7 +1022,16 @@ Describe 'SqlDatabasePermission\Test()' -Tag 'Test' {
10131022
Permission = @()
10141023
}
10151024
)
1016-
}
1025+
} |
1026+
# Mock method GetCurrentState() which is called by the base method Get()
1027+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetCurrentState' -Value {
1028+
return [System.Collections.Hashtable] @{
1029+
Name = 'MockUserName'
1030+
DatabaseName = 'MockDatabaseName'
1031+
InstanceName = 'NamedInstance'
1032+
ServerName = Get-ComputerName
1033+
}
1034+
} -PassThru
10171035
}
10181036
}
10191037

tests/Unit/Classes/SqlPermission.Tests.ps1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,14 @@ Describe 'SqlPermission\Set()' -Tag 'Set' {
902902
}
903903
)
904904
} |
905+
# Mock method GetCurrentState() which is called by the base method Get()
906+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetCurrentState' -Value {
907+
return [System.Collections.Hashtable] @{
908+
Name = 'MockUserName'
909+
InstanceName = 'NamedInstance'
910+
ServerName = Get-ComputerName
911+
}
912+
} -PassThru |
905913
# Mock method Modify which is called by the base method Set().
906914
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Modify' -Value {
907915
$script:mockMethodModifyCallCount += 1
@@ -990,7 +998,15 @@ Describe 'SqlPermission\Test()' -Tag 'Test' {
990998
Permission = @()
991999
}
9921000
)
993-
}
1001+
} |
1002+
# Mock method GetCurrentState() which is called by the base method Get()
1003+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetCurrentState' -Value {
1004+
return [System.Collections.Hashtable] @{
1005+
Name = 'MockUserName'
1006+
InstanceName = 'NamedInstance'
1007+
ServerName = Get-ComputerName
1008+
}
1009+
} -PassThru
9941010
}
9951011
}
9961012

0 commit comments

Comments
 (0)