/
AboutDbaDatabase.Koans.ps1
101 lines (90 loc) · 3.9 KB
/
AboutDbaDatabase.Koans.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#Requires -Modules dbatools
using module PSKoans
[Koan(Position = 1001, Module = 'dbatools')]
param()
<#
Get-DbaDatabase
The Get-DbaDatabase command gets SQL database information for each database
that is present on the target instance(s) of SQL Server by default. If the
name of the database is provided, the command will return only the specific
database.
#>
Describe 'Get-DbaDatabase' {
#region Mocks
<#
Let's setup the environment for you. Unless you want your Koans to
nearly always fail I'd suggest not messing with this bit.
#>
BeforeAll {
Mock -CommandName Get-DbaDatabase -MockWith {
Import-Clixml -Path .\PSKoans\Koans\dbatools\Mocks\Database_All.xml
} -ParameterFilter { $_.SqlInstance -eq 'localhost' }
Mock -CommandName Get-DbaDatabase -MockWith {
Import-Clixml -Path .\PSKoans\Koans\dbatools\Mocks\Database_TestDb.xml
} -ParameterFilter { $_.SqlInstance -eq 'localhost' -and $_.Database -eq 'testdb' }
Mock -CommandName Get-DbaDatabase -MockWith {
Import-Clixml -Path .\PSKoans\Koans\dbatools\Mocks\Database_System.xml
} -ParameterFilter { $_.SqlInstance -eq 'localhost' -and $_.ExcludeUser }
Mock -CommandName Get-DbaDatabase -MockWith {
Import-Clixml -Path .\PSKoans\Koans\dbatools\Mocks\Database_TestDb.xml
} -ParameterFilter { $_.SqlInstance -eq 'localhost' -and $_.ExludeSystem }
}
#endregion
It 'Gathers databases by SQL Server instance...' {
<#
Get-DbaDatabase requires one thing; A SQL Server instance name.
You can pass in "localhost" for the default name for a SQL Server
instance.
The simplest usage of Get-DbaDatabase is to run it and passing in the
name of the SQL Server instance. This will get information about all
the databases on the instance.
#>
$AllDatabases = Get-DbaDatabase -SqlInstance ____
$AllDatabases.Count | Should -Be 5
}
It 'Gathers database by SQL Server instance and specific name...' {
<#
By passing in the SQL Server instance and the name of a specific
database, using the -Database parameter, we can get information on
that single database instead.
#>
$primaryDatabase = Get-DbaDatabase -SqlInstance localhost -Database ____
$primaryDatabase.Name | Should -Be 'testdb'
}
It 'Gathers system databases only if specified...' {
<#
You may want to get only the system databases on an instance.
While you can pass in the specific names of the system databases, it
would be easier if there was a parameter you could add that would
return the system databases.
A switch parameter like -ExcludeUser.
#>
$UserDbParams = @{
SqlInstance = 'localhost'
ExcludeUser = $____
}
$UserDbsExcluded = Get-DbaDatabase @UserDbParams
$UserDbsExcluded.Name | Should -BeIn 'tempdb', 'primary', 'model', 'msdb'
}
It 'Excludes system databases if specified...' {
<#
The same can be done to exclude system databases by providing the
-ExcludeSystem parameter switch.
#>
$SystemDbParams = @{
SqlInstance = 'localhost'
ExludeSystem = ____
}
$SystemDbsExluded = Get-DbaDatabase @SystemDbParams
$SystemDbsExluded.Name | Should -Be 'testdb'
}
It 'Gathers databases based on their recovery model...' {
<#
Some common questions that people who work with databases
may have getting databases that are in the 'Full', 'Simple', or
'BulkLogged' recovery models.
#>
$FullRecoveryDbs = Get-DbaDatabase -SqlInstance localhost -RecoveryModel ____
$FullRecoveryDbs.RecoveryModel | Should -Be 'Full'
}
}