From 217560fc15e5814bb440194b45b868798d1b6768 Mon Sep 17 00:00:00 2001 From: Shaneis Date: Sat, 29 Aug 2020 18:26:50 +0100 Subject: [PATCH 1/3] First mock converted off Import-Clixml --- .../dbatools/AboutDbaDatabase.Koans.ps1 | 88 ++++++++++++++++++- 1 file changed, 86 insertions(+), 2 deletions(-) diff --git a/PSKoans/Koans/Modules/dbatools/AboutDbaDatabase.Koans.ps1 b/PSKoans/Koans/Modules/dbatools/AboutDbaDatabase.Koans.ps1 index 35d46cd82..29c00c2f8 100644 --- a/PSKoans/Koans/Modules/dbatools/AboutDbaDatabase.Koans.ps1 +++ b/PSKoans/Koans/Modules/dbatools/AboutDbaDatabase.Koans.ps1 @@ -19,7 +19,91 @@ Describe 'Get-DbaDatabase' { #> BeforeAll { Mock -CommandName Get-DbaDatabase -MockWith { - Import-Clixml -Path .\PSKoans\Koans\dbatools\Mocks\Database_All.xml + [PSCustomObject]@{ + ComputerName = 'Server01' + InstanceName = 'MSSQLSERVER' + SqlInstance = 'Server01' + Name = 'testdb' + Status = 'Normal' + IsAccessible = 'True' + RecoveryModel = 'Full' + LogReuseWaitStatus = 'LogBackup' + SizeMB = '95.275' + Compatibility = 'Version120' + Collation = 'Latin1_General_CI_AS' + Owner = 'sa' + LastFullBackup = '26/02/2019 19:56:36' + LastDiffBackup = '26/02/2019 13:00:31' + LastLogBackup = '26/02/2019 20:00:02' + }, + [PSCustomObject]@{ + ComputerName = 'Server01' + InstanceName = 'MSSQLSERVER' + SqlInstance = 'Server01' + Name = 'tempdb' + Status = 'Normal' + IsAccessible = 'True' + RecoveryModel = 'Full' + LogReuseWaitStatus = 'Nothing' + SizeMB = '46.13' + Compatibility = 'Version120' + Collation = 'Latin1_General_CI_AS' + Owner = 'sa' + LastFullBackup = '26/02/2019 19:57:35' + LastDiffBackup = '26/02/2019 13:03:43' + LastLogBackup = '26/02/2019 20:02:57' + }, + [PSCustomObject]@{ + ComputerName = 'Server01' + InstanceName = 'MSSQLSERVER' + SqlInstance = 'Server01' + Name = 'primary' + Status = 'Normal' + IsAccessible = 'True' + RecoveryModel = 'Full' + LogReuseWaitStatus = 'Nothing' + SizeMB = '29.56' + Compatibility = 'Version120' + Collation = 'Latin1_General_CI_AS' + Owner = 'sa' + LastFullBackup = '26/02/2019 19:59:39' + LastDiffBackup = '26/02/2019 13:01:29' + LastLogBackup = '26/02/2019 20:04:34' + }, + [PSCustomObject]@{ + ComputerName = 'Server01' + InstanceName = 'MSSQLSERVER' + SqlInstance = 'Server01' + Name = 'model' + Status = 'Normal' + IsAccessible = 'True' + RecoveryModel = 'Full' + LogReuseWaitStatus = 'Nothing' + SizeMB = '39.68' + Compatibility = 'Version120' + Collation = 'Latin1_General_CI_AS' + Owner = 'sa' + LastFullBackup = '26/02/2019 20:01:03' + LastDiffBackup = '26/02/2019 13:02:30' + LastLogBackup = '26/02/2019 20:01:19' + }, + [PSCustomObject]@{ + ComputerName = 'Server01' + InstanceName = 'MSSQLSERVER' + SqlInstance = 'Server01' + Name = 'msdb' + Status = 'Normal' + IsAccessible = 'True' + RecoveryModel = 'Full' + LogReuseWaitStatus = 'Nothing' + SizeMB = '79.29' + Compatibility = 'Version120' + Collation = 'Latin1_General_CI_AS' + Owner = 'sa' + LastFullBackup = '26/02/2019 19:59:54' + LastDiffBackup = '26/02/2019 13:05:07' + LastLogBackup = '26/02/2019 20:04:01' + } } -ParameterFilter { $_.SqlInstance -eq 'localhost' } Mock -CommandName Get-DbaDatabase -MockWith { @@ -82,7 +166,7 @@ Describe 'Get-DbaDatabase' { -ExcludeSystem parameter switch. #> $SystemDbParams = @{ - SqlInstance = 'localhost' + SqlInstance = 'localhost' ExludeSystem = ____ } $SystemDbsExluded = Get-DbaDatabase @SystemDbParams From 90220a1b7d0c5a6f72b0a033657926b24170b468 Mon Sep 17 00:00:00 2001 From: Shaneis Date: Wed, 7 Oct 2020 07:03:20 +0100 Subject: [PATCH 2/3] Formatting on PSCustomObject in Mocks --- .../dbatools/AboutBackupDatabases.Koans.ps1 | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/PSKoans/Koans/Modules/dbatools/AboutBackupDatabases.Koans.ps1 b/PSKoans/Koans/Modules/dbatools/AboutBackupDatabases.Koans.ps1 index 8baa120ce..b56b69e49 100644 --- a/PSKoans/Koans/Modules/dbatools/AboutBackupDatabases.Koans.ps1 +++ b/PSKoans/Koans/Modules/dbatools/AboutBackupDatabases.Koans.ps1 @@ -28,14 +28,14 @@ Describe "Backup-DbaDatabase" { [PSCustomObject]@{ ComputerName = 'localhost' - SqlInstance = $ENV:COMPUTERNAME - Database = ('Database_{0:d2}' -f $_) - Type = 'Full' - TotalSize = ('{0}' -f ([Math]::PI * $_)) - DeviceType = 'Disk' - Start = $RestoreStart - Duration = $RestoreEnd - $RestoreStart - End = $RestoreEnd + SqlInstance = $ENV:COMPUTERNAME + Database = ('Database_{0:d2}' -f $_) + Type = 'Full' + TotalSize = ('{0}' -f ([Math]::PI * $_)) + DeviceType = 'Disk' + Start = $RestoreStart + Duration = $RestoreEnd - $RestoreStart + End = $RestoreEnd } $StartDate = $RestoreEnd } @@ -48,14 +48,14 @@ Describe "Backup-DbaDatabase" { [PSCustomObject]@{ ComputerName = 'localhost' - SqlInstance = $ENV:COMPUTERNAME - Database = ('Database_{0:d2}' -f $_) - Type = 'Full' - TotalSize = ('{0}' -f ([Math]::PI * $_)) - DeviceType = 'Disk' - Start = $RestoreStart - Duration = $RestoreEnd - $RestoreStart - End = $RestoreEnd + SqlInstance = $ENV:COMPUTERNAME + Database = ('Database_{0:d2}' -f $_) + Type = 'Full' + TotalSize = ('{0}' -f ([Math]::PI * $_)) + DeviceType = 'Disk' + Start = $RestoreStart + Duration = $RestoreEnd - $RestoreStart + End = $RestoreEnd } $StartDate = $RestoreEnd @@ -68,14 +68,14 @@ Describe "Backup-DbaDatabase" { $RestoreEnd = $StartDate.AddSeconds(5) [PSCustomObject]@{ ComputerName = 'localhost' - SqlInstance = $ENV:COMPUTERNAME - Database = 'Database_01' - Type = 'Differential' - TotalSize = ('{0}' -f ([Math]::PI)) - DeviceType = 'Disk' - Start = $StartDate - Duration = $RestoreEnd - $StartDate - End = $RestoreEnd + SqlInstance = $ENV:COMPUTERNAME + Database = 'Database_01' + Type = 'Differential' + TotalSize = ('{0}' -f ([Math]::PI)) + DeviceType = 'Disk' + Start = $StartDate + Duration = $RestoreEnd - $StartDate + End = $RestoreEnd } } -ParameterFilter { $_.Type -eq 'Differential' @@ -85,15 +85,15 @@ Describe "Backup-DbaDatabase" { $RestoreEnd = $StartDate.AddSeconds(5) [PSCustomObject]@{ ComputerName = 'localhost' - SqlInstance = $ENV:COMPUTERNAME - Database = 'Database_01' - Type = 'Differential' - TotalSize = ('{0}' -f ([Math]::PI)) - DeviceType = 'Disk' - Start = $StartDate - Duration = $RestoreEnd - $StartDate - End = $RestoreEnd - Path = 'E:\Backups\Database_01_201901011200.bak' + SqlInstance = $ENV:COMPUTERNAME + Database = 'Database_01' + Type = 'Differential' + TotalSize = ('{0}' -f ([Math]::PI)) + DeviceType = 'Disk' + Start = $StartDate + Duration = $RestoreEnd - $StartDate + End = $RestoreEnd + Path = 'E:\Backups\Database_01_201901011200.bak' } } -ParameterFilter { $_.Path -like 'E:\Backups\*' @@ -103,15 +103,15 @@ Describe "Backup-DbaDatabase" { $RestoreEnd = $StartDate.AddSeconds(5) [PSCustomObject]@{ ComputerName = 'localhost' - SqlInstance = $ENV:COMPUTERNAME - Database = 'Database_01' - Type = 'Differential' - TotalSize = ('{0}' -f ([Math]::PI)) - DeviceType = 'Disk' - Start = $StartDate - Duration = $RestoreEnd - $StartDate - End = $RestoreEnd - Path = 'E:\Backups\Database01-Full.bak' + SqlInstance = $ENV:COMPUTERNAME + Database = 'Database_01' + Type = 'Differential' + TotalSize = ('{0}' -f ([Math]::PI)) + DeviceType = 'Disk' + Start = $StartDate + Duration = $RestoreEnd - $StartDate + End = $RestoreEnd + Path = 'E:\Backups\Database01-Full.bak' } } -ParameterFilter { $_.FilePath -eq 'dbname-backuptype.bak' From de8f69d60e17ff321cc979f0a29d38f47325c02b Mon Sep 17 00:00:00 2001 From: Shaneis Date: Wed, 7 Oct 2020 08:30:27 +0100 Subject: [PATCH 3/3] Changed clixml to PSCustomObject for *some* mocks --- .../dbatools/AboutDbaDatabase.Koans.ps1 | 87 ++++++++++++++++++- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/PSKoans/Koans/Modules/dbatools/AboutDbaDatabase.Koans.ps1 b/PSKoans/Koans/Modules/dbatools/AboutDbaDatabase.Koans.ps1 index 29c00c2f8..c91057dbd 100644 --- a/PSKoans/Koans/Modules/dbatools/AboutDbaDatabase.Koans.ps1 +++ b/PSKoans/Koans/Modules/dbatools/AboutDbaDatabase.Koans.ps1 @@ -107,11 +107,94 @@ Describe 'Get-DbaDatabase' { } -ParameterFilter { $_.SqlInstance -eq 'localhost' } Mock -CommandName Get-DbaDatabase -MockWith { - Import-Clixml -Path .\PSKoans\Koans\dbatools\Mocks\Database_TestDb.xml + [PSCustomObject]@{ + ComputerName = 'Server01' + InstanceName = 'MSSQLSERVER' + SqlInstance = 'Server01' + Name = 'testdb' + Status = 'Normal' + IsAccessible = 'True' + RecoveryModel = 'Full' + LogReuseWaitStatus = 'LogBackup' + SizeMB = '95.275' + Compatibility = 'Version120' + Collation = 'Latin1_General_CI_AS' + Owner = 'sa' + LastFullBackup = '26/02/2019 19:56:36' + LastDiffBackup = '26/02/2019 13:00:31' + LastLogBackup = '26/02/2019 20:00:02' + } } -ParameterFilter { $_.SqlInstance -eq 'localhost' -and $_.Database -eq 'testdb' } Mock -CommandName Get-DbaDatabase -MockWith { - Import-Clixml -Path .\PSKoans\Koans\dbatools\Mocks\Database_System.xml + [PSCustomObject]@{ + ComputerName = 'Server01' + InstanceName = 'MSSQLSERVER' + SqlInstance = 'Server01' + Name = 'tempdb' + Status = 'Normal' + IsAccessible = 'True' + RecoveryModel = 'Full' + LogReuseWaitStatus = 'Nothing' + SizeMB = '46.13' + Compatibility = 'Version120' + Collation = 'Latin1_General_CI_AS' + Owner = 'sa' + LastFullBackup = '26/02/2019 19:57:35' + LastDiffBackup = '26/02/2019 13:03:43' + LastLogBackup = '26/02/2019 20:02:57' + }, + [PSCustomObject]@{ + ComputerName = 'Server01' + InstanceName = 'MSSQLSERVER' + SqlInstance = 'Server01' + Name = 'primary' + Status = 'Normal' + IsAccessible = 'True' + RecoveryModel = 'Full' + LogReuseWaitStatus = 'Nothing' + SizeMB = '29.56' + Compatibility = 'Version120' + Collation = 'Latin1_General_CI_AS' + Owner = 'sa' + LastFullBackup = '26/02/2019 19:59:39' + LastDiffBackup = '26/02/2019 13:01:29' + LastLogBackup = '26/02/2019 20:04:34' + }, + [PSCustomObject]@{ + ComputerName = 'Server01' + InstanceName = 'MSSQLSERVER' + SqlInstance = 'Server01' + Name = 'model' + Status = 'Normal' + IsAccessible = 'True' + RecoveryModel = 'Full' + LogReuseWaitStatus = 'Nothing' + SizeMB = '39.68' + Compatibility = 'Version120' + Collation = 'Latin1_General_CI_AS' + Owner = 'sa' + LastFullBackup = '26/02/2019 20:01:03' + LastDiffBackup = '26/02/2019 13:02:30' + LastLogBackup = '26/02/2019 20:01:19' + }, + [PSCustomObject]@{ + ComputerName = 'Server01' + InstanceName = 'MSSQLSERVER' + SqlInstance = 'Server01' + Name = 'msdb' + Status = 'Normal' + IsAccessible = 'True' + RecoveryModel = 'Full' + LogReuseWaitStatus = 'Nothing' + SizeMB = '79.29' + Compatibility = 'Version120' + Collation = 'Latin1_General_CI_AS' + Owner = 'sa' + LastFullBackup = '26/02/2019 19:59:54' + LastDiffBackup = '26/02/2019 13:05:07' + LastLogBackup = '26/02/2019 20:04:01' + } } -ParameterFilter { $_.SqlInstance -eq 'localhost' -and $_.ExcludeUser } Mock -CommandName Get-DbaDatabase -MockWith {