From 6a8365d78f7b518aabbfc6596ef8455c4a9ecf7b Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 18 Oct 2020 11:42:34 +0100 Subject: [PATCH] add a test to resolve issue #1620 --- CHANGELOG.md | 3 +++ tests/Unit/DSC_SqlDatabaseRole.Tests.ps1 | 26 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 536bd780a..d375dfc2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - SqlEndpoint - Added support for the Service Broker Endpoint ([issue #498](https://github.com/dsccommunity/SqlServerDsc/issues/498)). +- SqlDatabaseRole + - Added test to ensure Add-SqlDscDatabaseRoleMember throws the expected error + ([issue #1620](https://github.com/dsccommunity/SqlServerDsc/issues/1620)). ### Changed diff --git a/tests/Unit/DSC_SqlDatabaseRole.Tests.ps1 b/tests/Unit/DSC_SqlDatabaseRole.Tests.ps1 index 87db1a9d4..5d4995de8 100644 --- a/tests/Unit/DSC_SqlDatabaseRole.Tests.ps1 +++ b/tests/Unit/DSC_SqlDatabaseRole.Tests.ps1 @@ -228,7 +228,7 @@ try } -PassThru )) } - }-PassThru -Force + } -PassThru -Force )) } } -PassThru -Force | @@ -1108,6 +1108,30 @@ try Assert-VerifiableMock } + + Describe 'Add-SqlDscDatabaseRoleMember' -Tag 'Helper' { + BeforeAll { + $mockSqlDatabaseObject = @{ + Name = $mockSqlDatabaseName + Roles = @{ + $mockSqlDatabaseRole1 = 'Role' + } + Users = @{ + $mockSqlServerLogin1 = 'User' + } + } + $mockName = 'MissingRole' + $mockMemberName = 'MissingUser' + + } + Context 'When calling with a role that does not exist' { + It 'Should throw the correct error' { + { + Add-SqlDscDatabaseRoleMember -SqlDatabaseObject $mockSqlDatabaseObject -Name $mockName -MemberName $mockMemberName + } | Should -Throw ($script:localizedData.DatabaseRoleOrUserNotFound -f $mockName, $mockMemberName, $mockSqlDatabaseName) + } + } + } } } finally