Skip to content

Commit 92216a6

Browse files
committed
Enhance New-SqlDscLogin tests to validate output and MockCreateCalled flag for various login types
1 parent 71dd535 commit 92216a6

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

tests/Unit/Public/New-SqlDscLogin.Tests.ps1

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,10 @@ Describe 'New-SqlDscLogin' -Tag 'Public' {
312312

313313
Context 'When creating a Windows user login' {
314314
It 'Should create a Windows user login without throwing' {
315-
$null = New-SqlDscLogin -ServerObject $script:mockServerObject -Name 'DOMAIN\TestUser' -WindowsUser -Confirm:$false
315+
$result = New-SqlDscLogin -ServerObject $script:mockServerObject -Name 'DOMAIN\TestUser' -WindowsUser -PassThru -Confirm:$false
316+
317+
$result | Should -Not -BeNullOrEmpty
318+
$result.MockCreateCalled | Should -BeTrue
316319

317320
Should -Invoke -CommandName Test-SqlDscIsLogin -Exactly -Times 1 -Scope It
318321
}
@@ -343,24 +346,47 @@ Describe 'New-SqlDscLogin' -Tag 'Public' {
343346
$result = New-SqlDscLogin -ServerObject $script:mockServerObject -Name 'TestLogin' -SqlLogin -SecurePassword $script:mockSecurePassword -PassThru -Confirm:$false
344347

345348
$result | Should -Not -BeNullOrEmpty
349+
$result.MockCreateCalled | Should -BeTrue
350+
351+
Should -Invoke -CommandName Test-SqlDscIsLogin -Exactly -Times 1 -Scope It
352+
}
353+
354+
It 'Should create login without throwing when PassThru is not specified' {
355+
$result = New-SqlDscLogin -ServerObject $script:mockServerObject -Name 'TestLogin2' -SqlLogin -SecurePassword $script:mockSecurePassword -Confirm:$false
356+
$result | Should -BeNullOrEmpty
357+
358+
Should -Invoke -CommandName Test-SqlDscIsLogin -Exactly -Times 1 -Scope It
346359
}
347360
}
348361

349362
Context 'When creating certificate-based login' {
350363
It 'Should create a certificate login without throwing' {
351-
$null = New-SqlDscLogin -ServerObject $script:mockServerObject -Name 'CertLogin' -Certificate -CertificateName 'MyCert' -Confirm:$false
364+
$result = New-SqlDscLogin -ServerObject $script:mockServerObject -Name 'CertLogin' -Certificate -CertificateName 'MyCert' -PassThru -Confirm:$false
365+
366+
$result | Should -Not -BeNullOrEmpty
367+
$result.MockCreateCalled | Should -BeTrue
368+
369+
Should -Invoke -CommandName Test-SqlDscIsLogin -Exactly -Times 1 -Scope It
352370
}
353371
}
354372

355373
Context 'When creating asymmetric key-based login' {
356374
It 'Should create an asymmetric key login without throwing' {
357-
$null = New-SqlDscLogin -ServerObject $script:mockServerObject -Name 'KeyLogin' -AsymmetricKey -AsymmetricKeyName 'MyKey' -Confirm:$false
375+
$result = New-SqlDscLogin -ServerObject $script:mockServerObject -Name 'KeyLogin' -AsymmetricKey -AsymmetricKeyName 'MyKey' -PassThru -Confirm:$false
376+
377+
$result | Should -Not -BeNullOrEmpty
378+
$result.MockCreateCalled | Should -BeTrue
379+
380+
Should -Invoke -CommandName Test-SqlDscIsLogin -Exactly -Times 1 -Scope It
358381
}
359382
}
360383

361384
Context 'When creating Windows group login' {
362385
It 'Should create a Windows group login without throwing' {
363-
$null = New-SqlDscLogin -ServerObject $script:mockServerObject -Name 'NT AUTHORITY\SYSTEM' -WindowsGroup -Confirm:$false
386+
$result = New-SqlDscLogin -ServerObject $script:mockServerObject -Name 'NT AUTHORITY\SYSTEM' -WindowsGroup -PassThru -Confirm:$false
387+
388+
$result | Should -Not -BeNullOrEmpty
389+
$result.MockCreateCalled | Should -BeTrue
364390

365391
Should -Invoke -CommandName Test-SqlDscIsLogin -Exactly -Times 1 -Scope It
366392
}

0 commit comments

Comments
 (0)