@@ -318,6 +318,253 @@ Describe "$($script:dscResourceName)_Integration" -Tag @('Integration_SQL2016',
318318 These tests assumes that only permission left for test user 'User1' is
319319 a grant for permission 'ConnectSql'.
320320 #>
321+
322+ Context (' When using configuration <_>' ) - ForEach @ (
323+ " $ ( $script :dscResourceName ) _Role_Grant_Config"
324+ ) {
325+ BeforeAll {
326+ $configurationName = $_
327+ }
328+
329+ AfterEach {
330+ Wait-ForIdleLcm
331+ }
332+
333+ It ' Should compile and apply the MOF without throwing' {
334+ $configurationParameters = @ {
335+ OutputPath = $TestDrive
336+ # The variable $ConfigurationData was dot-sourced above.
337+ ConfigurationData = $ConfigurationData
338+ }
339+
340+ $null = & $configurationName @configurationParameters
341+
342+ $startDscConfigurationParameters = @ {
343+ Path = $TestDrive
344+ ComputerName = ' localhost'
345+ Wait = $true
346+ Verbose = $true
347+ Force = $true
348+ ErrorAction = ' Stop'
349+ }
350+
351+ $null = Start-DscConfiguration @startDscConfigurationParameters
352+ }
353+
354+ It ' Should be able to call Get-DscConfiguration without throwing' {
355+ $script :currentConfiguration = Get-DscConfiguration - Verbose - ErrorAction ' Stop'
356+ }
357+
358+ It ' Should have set the resource and all the parameters should match' {
359+ $resourceCurrentState = $script :currentConfiguration | Where-Object - FilterScript {
360+ $_.ConfigurationName -eq $configurationName `
361+ -and $_.ResourceId -eq $resourceId
362+ }
363+
364+ $resourceCurrentState.ServerName | Should - Be $ConfigurationData.AllNodes.ServerName
365+ $resourceCurrentState.InstanceName | Should - Be $ConfigurationData.AllNodes.InstanceName
366+ $resourceCurrentState.Name | Should - Be $ConfigurationData.AllNodes.Role1_Name
367+ $resourceCurrentState.Permission | Should - HaveCount 3
368+
369+ $grantState = $resourceCurrentState.Permission.Where ({ $_.State -eq ' Grant' })
370+
371+ $grantState.State | Should - Be ' Grant'
372+ $grantState.Permission | Should - HaveCount 2
373+ $grantState.Permission | Should - Contain ' ViewServerState'
374+ $grantState.Permission | Should - Contain ' AlterAnyEndpoint'
375+ }
376+
377+ It ' Should return $true when Test-DscConfiguration is run' {
378+ Test-DscConfiguration - Verbose - ErrorAction ' Stop' | Should - Be ' True'
379+ }
380+ }
381+
382+ Context (' When using configuration <_>' ) - ForEach @ (
383+ " $ ( $script :dscResourceName ) _Role_RemoveGrant_Config"
384+ ) {
385+ BeforeAll {
386+ $configurationName = $_
387+ }
388+
389+ AfterEach {
390+ Wait-ForIdleLcm
391+ }
392+
393+ It ' Should compile and apply the MOF without throwing' {
394+ $configurationParameters = @ {
395+ OutputPath = $TestDrive
396+ # The variable $ConfigurationData was dot-sourced above.
397+ ConfigurationData = $ConfigurationData
398+ }
399+
400+ $null = & $configurationName @configurationParameters
401+
402+ $startDscConfigurationParameters = @ {
403+ Path = $TestDrive
404+ ComputerName = ' localhost'
405+ Wait = $true
406+ Verbose = $true
407+ Force = $true
408+ ErrorAction = ' Stop'
409+ }
410+
411+ $null = Start-DscConfiguration @startDscConfigurationParameters
412+ }
413+
414+ It ' Should be able to call Get-DscConfiguration without throwing' {
415+ $script :currentConfiguration = Get-DscConfiguration - Verbose - ErrorAction ' Stop'
416+ }
417+
418+ It ' Should have set the resource and all the parameters should match' {
419+ $resourceCurrentState = $script :currentConfiguration | Where-Object - FilterScript {
420+ $_.ConfigurationName -eq $configurationName `
421+ -and $_.ResourceId -eq $resourceId
422+ }
423+
424+ $resourceCurrentState.ServerName | Should - Be $ConfigurationData.AllNodes.ServerName
425+ $resourceCurrentState.InstanceName | Should - Be $ConfigurationData.AllNodes.InstanceName
426+ $resourceCurrentState.Name | Should - Be $ConfigurationData.AllNodes.Role1_Name
427+ $resourceCurrentState.Permission | Should - HaveCount 3
428+
429+ $grantState = $resourceCurrentState.Permission.Where ({ $_.State -eq ' Grant' })
430+
431+ $grantState.State | Should - Be ' Grant'
432+ $grantState.Permission | Should - BeNullOrEmpty
433+ }
434+
435+ It ' Should return $true when Test-DscConfiguration is run' {
436+ Test-DscConfiguration - Verbose - ErrorAction ' Stop' | Should - Be ' True'
437+ }
438+ }
439+
440+ Context (' When using configuration <_>' ) - ForEach @ (
441+ " $ ( $script :dscResourceName ) _Role_Deny_Config"
442+ ) {
443+ BeforeAll {
444+ $configurationName = $_
445+ }
446+
447+ AfterEach {
448+ Wait-ForIdleLcm
449+ }
450+
451+ It ' Should compile and apply the MOF without throwing' {
452+ $configurationParameters = @ {
453+ OutputPath = $TestDrive
454+ # The variable $ConfigurationData was dot-sourced above.
455+ ConfigurationData = $ConfigurationData
456+ }
457+
458+ $null = & $configurationName @configurationParameters
459+
460+ $startDscConfigurationParameters = @ {
461+ Path = $TestDrive
462+ ComputerName = ' localhost'
463+ Wait = $true
464+ Verbose = $true
465+ Force = $true
466+ ErrorAction = ' Stop'
467+ }
468+
469+ $null = Start-DscConfiguration @startDscConfigurationParameters
470+ }
471+
472+ It ' Should be able to call Get-DscConfiguration without throwing' {
473+ $script :currentConfiguration = Get-DscConfiguration - Verbose - ErrorAction ' Stop'
474+ }
475+
476+ It ' Should have set the resource and all the parameters should match' {
477+ $resourceCurrentState = $script :currentConfiguration | Where-Object - FilterScript {
478+ $_.ConfigurationName -eq $configurationName `
479+ -and $_.ResourceId -eq $resourceId
480+ }
481+
482+ $resourceCurrentState.ServerName | Should - Be $ConfigurationData.AllNodes.ServerName
483+ $resourceCurrentState.InstanceName | Should - Be $ConfigurationData.AllNodes.InstanceName
484+ $resourceCurrentState.Name | Should - Be $ConfigurationData.AllNodes.Role1_Name
485+ $resourceCurrentState.Permission | Should - HaveCount 3
486+
487+ $grantState = $resourceCurrentState.Permission.Where ({ $_.State -eq ' Grant' })
488+
489+ $grantState.State | Should - Be ' Grant'
490+ $grantState.Permission | Should - BeNullOrEmpty
491+
492+ $denyState = $resourceCurrentState.Permission.Where ({ $_.State -eq ' Deny' })
493+
494+ $denyState.State | Should - Be ' Deny'
495+ $denyState.Permission | Should - HaveCount 2
496+ $denyState.Permission | Should - Contain ' ViewServerState'
497+ $denyState.Permission | Should - Contain ' AlterAnyEndpoint'
498+ }
499+
500+ It ' Should return $true when Test-DscConfiguration is run' {
501+ Test-DscConfiguration - Verbose - ErrorAction ' Stop' | Should - Be ' True'
502+ }
503+ }
504+
505+ Context (' When using configuration <_>' ) - ForEach @ (
506+ " $ ( $script :dscResourceName ) _Role_RemoveDeny_Config"
507+ ) {
508+ BeforeAll {
509+ $configurationName = $_
510+ }
511+
512+ AfterEach {
513+ Wait-ForIdleLcm
514+ }
515+
516+ It ' Should compile and apply the MOF without throwing' {
517+ $configurationParameters = @ {
518+ OutputPath = $TestDrive
519+ # The variable $ConfigurationData was dot-sourced above.
520+ ConfigurationData = $ConfigurationData
521+ }
522+
523+ $null = & $configurationName @configurationParameters
524+
525+ $startDscConfigurationParameters = @ {
526+ Path = $TestDrive
527+ ComputerName = ' localhost'
528+ Wait = $true
529+ Verbose = $true
530+ Force = $true
531+ ErrorAction = ' Stop'
532+ }
533+
534+ $null = Start-DscConfiguration @startDscConfigurationParameters
535+ }
536+
537+ It ' Should be able to call Get-DscConfiguration without throwing' {
538+ $script :currentConfiguration = Get-DscConfiguration - Verbose - ErrorAction ' Stop'
539+ }
540+
541+ It ' Should have set the resource and all the parameters should match' {
542+ $resourceCurrentState = $script :currentConfiguration | Where-Object - FilterScript {
543+ $_.ConfigurationName -eq $configurationName `
544+ -and $_.ResourceId -eq $resourceId
545+ }
546+
547+ $resourceCurrentState.ServerName | Should - Be $ConfigurationData.AllNodes.ServerName
548+ $resourceCurrentState.InstanceName | Should - Be $ConfigurationData.AllNodes.InstanceName
549+ $resourceCurrentState.Name | Should - Be $ConfigurationData.AllNodes.Role1_Name
550+ $resourceCurrentState.Permission | Should - HaveCount 3
551+
552+ $grantState = $resourceCurrentState.Permission.Where ({ $_.State -eq ' Grant' })
553+
554+ $grantState.State | Should - Be ' Grant'
555+ $grantState.Permission | Should - BeNullOrEmpty
556+
557+ $denyState = $resourceCurrentState.Permission.Where ({ $_.State -eq ' Deny' })
558+
559+ $denyState.State | Should - Be ' Deny'
560+ $denyState.Permission | Should - BeNullOrEmpty
561+ }
562+
563+ It ' Should return $true when Test-DscConfiguration is run' {
564+ Test-DscConfiguration - Verbose - ErrorAction ' Stop' | Should - Be ' True'
565+ }
566+ }
567+
321568 Context ' When using Invoke-DscResource' {
322569 BeforeAll {
323570 <#
0 commit comments