@@ -23,6 +23,7 @@ BeforeDiscovery {
23
23
}
24
24
}
25
25
26
+ # cSpell: ignore DSCSQLTEST
26
27
Describe ' Connect-SqlDscDatabaseEngine' - Tag @ (' Integration_SQL2016' , ' Integration_SQL2017' , ' Integration_SQL2019' , ' Integration_SQL2022' ) {
27
28
BeforeAll {
28
29
Write-Verbose - Message (' Running integration test as user '' {0}'' .' -f $env: UserName ) - Verbose
@@ -40,65 +41,98 @@ Describe 'Connect-SqlDscDatabaseEngine' -Tag @('Integration_SQL2016', 'Integrati
40
41
# }
41
42
42
43
Context ' When connecting to the default instance impersonating a Windows user' {
43
- It ' Should return the correct result' {
44
- {
45
- $sqlAdministratorUserName = ' SqlAdmin' # Using computer name as NetBIOS name throw exception.
46
- $sqlAdministratorPassword = ConvertTo-SecureString - String ' P@ssw0rd1' - AsPlainText - Force
44
+ BeforeAll {
45
+ # Starting the default instance SQL Server service prior to running tests.
46
+ Start-Service - Name ' MSSQLSERVER' - Verbose - ErrorAction ' Stop'
47
+ }
48
+
49
+ AfterAll {
50
+ # Stop the default instance SQL Server service to save memory on the build worker.
51
+ Stop-Service - Name ' MSSQLSERVER' - Verbose - ErrorAction ' Stop'
52
+ }
53
+
54
+ It ' Should have the default instance SQL Server service started' {
55
+ $getServiceResult = Get-Service - Name ' MSSQLSERVER' - ErrorAction ' Stop'
47
56
48
- $connectSqlDscDatabaseEngineParameters = @ {
49
- Credential = [System.Management.Automation.PSCredential ]::new($sqlAdministratorUserName , $sqlAdministratorPassword )
50
- Verbose = $true
51
- ErrorAction = ' Stop'
52
- }
57
+ $getServiceResult.Status | Should - Be ' Running'
58
+ }
59
+
60
+ Context ' When impersonating a Windows user' {
61
+ It ' Should return the correct result' {
62
+ {
63
+ $sqlAdministratorUserName = ' SqlAdmin' # Using computer name as NetBIOS name throw exception.
64
+ $sqlAdministratorPassword = ConvertTo-SecureString - String ' P@ssw0rd1' - AsPlainText - Force
53
65
66
+ $connectSqlDscDatabaseEngineParameters = @ {
67
+ Credential = [System.Management.Automation.PSCredential ]::new($sqlAdministratorUserName , $sqlAdministratorPassword )
68
+ Verbose = $true
69
+ ErrorAction = ' Stop'
70
+ }
54
71
55
- $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters
72
+ $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters
56
73
57
- $sqlServerObject.Status.ToString () | Should -Match ' ^Online$'
58
- } | Should -Not - Throw
74
+ $sqlServerObject.Status.ToString () | Should -Match ' ^Online$'
75
+ } | Should -Not - Throw
76
+ }
59
77
}
60
78
}
61
79
62
- Context ' When connecting to the named instance impersonating a Windows user' {
63
- It ' Should return the correct result' {
64
- {
65
- $sqlAdministratorUserName = ' SqlAdmin' # Using computer name as NetBIOS name throw exception.
66
- $sqlAdministratorPassword = ConvertTo-SecureString - String ' P@ssw0rd1' - AsPlainText - Force
67
-
68
- $connectSqlDscDatabaseEngineParameters = @ {
69
- InstanceName = ' DSCSQLTEST'
70
- Credential = [System.Management.Automation.PSCredential ]::new($sqlAdministratorUserName , $sqlAdministratorPassword )
71
- Verbose = $true
72
- ErrorAction = ' Stop'
73
- }
80
+ Context ' When connecting to a named instance' {
81
+ BeforeAll {
82
+ # Starting the named instance SQL Server service prior to running tests.
83
+ Start-Service - Name ' MSSQL$DSCSQLTEST' - Verbose - ErrorAction ' Stop'
84
+ }
74
85
86
+ AfterAll {
87
+ # Stop the named instance SQL Server service to save memory on the build worker.
88
+ Stop-Service - Name ' MSSQL$DSCSQLTEST' - Verbose - ErrorAction ' Stop'
89
+ }
75
90
76
- $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters
91
+ It ' Should have the named instance SQL Server service started' {
92
+ $getServiceResult = Get-Service - Name ' MSSQL$DSCSQLTEST' - ErrorAction ' Stop'
77
93
78
- $sqlServerObject.Status.ToString () | Should -Match ' ^Online$'
79
- } | Should -Not - Throw
94
+ $getServiceResult.Status | Should - Be ' Running'
80
95
}
81
- }
82
96
83
- Context ' When connecting to the named instance using a SQL login' {
84
- It ' Should return the correct result' {
85
- {
86
- $sqlAdministratorUserName = ' sa'
87
- $sqlAdministratorPassword = ConvertTo-SecureString - String ' P@ssw0rd1' - AsPlainText - Force
97
+ Context ' When impersonating a Windows user' {
98
+ It ' Should return the correct result' {
99
+ {
100
+ $sqlAdministratorUserName = ' SqlAdmin' # Using computer name as NetBIOS name throw exception.
101
+ $sqlAdministratorPassword = ConvertTo-SecureString - String ' P@ssw0rd1' - AsPlainText - Force
102
+
103
+ $connectSqlDscDatabaseEngineParameters = @ {
104
+ InstanceName = ' DSCSQLTEST'
105
+ Credential = [System.Management.Automation.PSCredential ]::new($sqlAdministratorUserName , $sqlAdministratorPassword )
106
+ Verbose = $true
107
+ ErrorAction = ' Stop'
108
+ }
88
109
89
- $connectSqlDscDatabaseEngineParameters = @ {
90
- InstanceName = ' DSCSQLTEST' # cSpell: disable-line
91
- LoginType = ' SqlLogin'
92
- Credential = [System.Management.Automation.PSCredential ]::new($sqlAdministratorUserName , $sqlAdministratorPassword )
93
- Verbose = $true
94
- ErrorAction = ' Stop'
95
- }
110
+ $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters
96
111
112
+ $sqlServerObject.Status.ToString () | Should -Match ' ^Online$'
113
+ } | Should -Not - Throw
114
+ }
115
+ }
116
+
117
+ Context ' When using a SQL login' {
118
+ It ' Should return the correct result' {
119
+ {
120
+ $sqlAdministratorUserName = ' sa'
121
+ $sqlAdministratorPassword = ConvertTo-SecureString - String ' P@ssw0rd1' - AsPlainText - Force
97
122
98
- $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters
123
+ $connectSqlDscDatabaseEngineParameters = @ {
124
+ InstanceName = ' DSCSQLTEST' # cSpell: disable-line
125
+ LoginType = ' SqlLogin'
126
+ Credential = [System.Management.Automation.PSCredential ]::new($sqlAdministratorUserName , $sqlAdministratorPassword )
127
+ Verbose = $true
128
+ ErrorAction = ' Stop'
129
+ }
99
130
100
- $sqlServerObject.Status.ToString () | Should -Match ' ^Online$'
101
- } | Should -Not - Throw
131
+ $sqlServerObject = Connect-SqlDscDatabaseEngine @connectSqlDscDatabaseEngineParameters
132
+
133
+ $sqlServerObject.Status.ToString () | Should -Match ' ^Online$'
134
+ } | Should -Not - Throw
135
+ }
102
136
}
103
137
}
104
138
}
0 commit comments