Skip to content

Commit 3744510

Browse files
committed
Fix failing SqlDatabasePermission
1 parent 1594d47 commit 3744510

File tree

1 file changed

+64
-41
lines changed

1 file changed

+64
-41
lines changed

tests/Unit/Classes/SqlDatabasePermission.Tests.ps1

Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -935,16 +935,18 @@ Describe 'SqlDatabasePermission\Set()' -Tag 'Set' {
935935
BeforeEach {
936936
InModuleScope -ScriptBlock {
937937
$script:mockMethodModifyCallCount = 0
938+
$script:mockMethodTestCallCount = 0
938939
}
939940
}
940941

941942
Context 'When the system is in the desired state' {
942943
BeforeAll {
943944
InModuleScope -ScriptBlock {
944945
$script:mockSqlDatabasePermissionInstance |
945-
# Mock method Compare() which is called by the base method Set()
946-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Compare' -Value {
947-
return $null
946+
# Mock method Test() which is called by the base method Set()
947+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Test' -Value {
948+
$script:mockMethodTestCallCount += 1
949+
return $true
948950
}
949951
}
950952
}
@@ -954,6 +956,7 @@ Describe 'SqlDatabasePermission\Set()' -Tag 'Set' {
954956
$script:mockSqlDatabasePermissionInstance.Set()
955957

956958
$script:mockMethodModifyCallCount | Should -Be 0
959+
$script:mockMethodTestCallCount | Should -Be 1
957960
}
958961
}
959962
}
@@ -962,32 +965,38 @@ Describe 'SqlDatabasePermission\Set()' -Tag 'Set' {
962965
BeforeAll {
963966
InModuleScope -ScriptBlock {
964967
$script:mockSqlDatabasePermissionInstance |
965-
# Mock method Compare() which is called by the base method Set()
966-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Compare' -Value {
967-
return @{
968-
Property = 'Permission'
969-
ExpectedValue = [DatabasePermission[]] @(
970-
[DatabasePermission] @{
971-
State = 'Grant'
972-
Permission = @('Connect', 'Update')
973-
}
974-
)
975-
ActualValue = [DatabasePermission[]] @(
976-
[DatabasePermission] @{
977-
State = 'Grant'
978-
Permission = @('Connect')
979-
}
980-
)
981-
}
968+
# Mock method Test() which is called by the base method Set()
969+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Test' -Value {
970+
$script:mockMethodTestCallCount += 1
971+
return $false
972+
}
973+
974+
$script:mockSqlDatabasePermissionInstance.PropertiesNotInDesiredState = @(
975+
@{
976+
Property = 'Permission'
977+
ExpectedValue = [DatabasePermission[]] @(
978+
[DatabasePermission] @{
979+
State = 'Grant'
980+
Permission = @('Connect', 'Update')
981+
}
982+
)
983+
ActualValue = [DatabasePermission[]] @(
984+
[DatabasePermission] @{
985+
State = 'Grant'
986+
Permission = @('Connect')
987+
}
988+
)
982989
}
990+
)
983991
}
984992
}
985993

986-
It 'Should not call method Modify()' {
994+
It 'Should call method Modify()' {
987995
InModuleScope -ScriptBlock {
988996
$script:mockSqlDatabasePermissionInstance.Set()
989997

990998
$script:mockMethodModifyCallCount | Should -Be 1
999+
$script:mockMethodTestCallCount | Should -Be 1
9911000
}
9921001
}
9931002
}
@@ -1018,20 +1027,28 @@ Describe 'SqlDatabasePermission\Test()' -Tag 'Test' {
10181027
}
10191028
}
10201029

1030+
BeforeEach {
1031+
InModuleScope -ScriptBlock {
1032+
$script:mockMethodGetCallCount = 0
1033+
}
1034+
}
1035+
10211036
Context 'When the system is in the desired state' {
10221037
BeforeAll {
10231038
InModuleScope -ScriptBlock {
10241039
$script:mockSqlDatabasePermissionInstance |
1025-
# Mock method Compare() which is called by the base method Set()
1026-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Compare' -Value {
1027-
return $null
1040+
# Mock method Get() which is called by the base method Test()
1041+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Get' -Value {
1042+
$script:mockMethodGetCallCount += 1
10281043
}
10291044
}
10301045
}
10311046

10321047
It 'Should return $true' {
10331048
InModuleScope -ScriptBlock {
10341049
$script:mockSqlDatabasePermissionInstance.Test() | Should -BeTrue
1050+
1051+
$script:mockMethodGetCallCount | Should -Be 1
10351052
}
10361053
}
10371054
}
@@ -1040,30 +1057,36 @@ Describe 'SqlDatabasePermission\Test()' -Tag 'Test' {
10401057
BeforeAll {
10411058
InModuleScope -ScriptBlock {
10421059
$script:mockSqlDatabasePermissionInstance |
1043-
# Mock method Compare() which is called by the base method Set()
1044-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Compare' -Value {
1045-
return @{
1046-
Property = 'Permission'
1047-
ExpectedValue = [DatabasePermission[]] @(
1048-
[DatabasePermission] @{
1049-
State = 'Grant'
1050-
Permission = @('Connect', 'Update')
1051-
}
1052-
)
1053-
ActualValue = [DatabasePermission[]] @(
1054-
[DatabasePermission] @{
1055-
State = 'Grant'
1056-
Permission = @('Connect')
1057-
}
1058-
)
1059-
}
1060+
# Mock method Get() which is called by the base method Test()
1061+
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Get' -Value {
1062+
$script:mockMethodGetCallCount += 1
10601063
}
1064+
1065+
$script:mockSqlDatabasePermissionInstance.PropertiesNotInDesiredState = @(
1066+
@{
1067+
Property = 'Permission'
1068+
ExpectedValue = [DatabasePermission[]] @(
1069+
[DatabasePermission] @{
1070+
State = 'Grant'
1071+
Permission = @('Connect', 'Update')
1072+
}
1073+
)
1074+
ActualValue = [DatabasePermission[]] @(
1075+
[DatabasePermission] @{
1076+
State = 'Grant'
1077+
Permission = @('Connect')
1078+
}
1079+
)
1080+
}
1081+
)
10611082
}
10621083
}
10631084

10641085
It 'Should return $false' {
10651086
InModuleScope -ScriptBlock {
10661087
$script:mockSqlDatabasePermissionInstance.Test() | Should -BeFalse
1088+
1089+
$script:mockMethodGetCallCount | Should -Be 1
10671090
}
10681091
}
10691092
}

0 commit comments

Comments
 (0)