25
25
26
26
namespace Microsoft . WindowsAzure . Commands . SqlDatabase . Test . UnitTests . Database . Cmdlet
27
27
{
28
- [ RecordMockDataResults ( "./" ) ]
29
28
[ TestClass ]
30
29
public class SqlAuthv12MockTests
31
30
{
@@ -36,8 +35,6 @@ public class SqlAuthv12MockTests
36
35
[ TestInitialize ]
37
36
public void Setup ( )
38
37
{
39
- var mockConn = new MockSqlConnection ( ) ;
40
- TSqlConnectionContext . MockSqlConnection = mockConn ;
41
38
}
42
39
43
40
[ TestCleanup ]
@@ -46,9 +43,13 @@ public void Cleanup()
46
43
// Do any test clean up here.
47
44
}
48
45
46
+ //[RecordMockDataResults("./")]
49
47
[ TestMethod ]
50
48
public void NewAzureSqlDatabaseWithSqlAuthv12 ( )
51
49
{
50
+ var mockConn = new MockSqlConnection ( ) ;
51
+ TSqlConnectionContext . MockSqlConnection = mockConn ;
52
+
52
53
using ( System . Management . Automation . PowerShell powershell =
53
54
System . Management . Automation . PowerShell . Create ( ) )
54
55
{
@@ -121,6 +122,171 @@ public void NewAzureSqlDatabaseWithSqlAuthv12()
121
122
}
122
123
123
124
125
+ //[RecordMockDataResults("./")]
126
+ [ TestMethod ]
127
+ public void GetAzureSqlDatabaseWithSqlAuthv12 ( )
128
+ {
129
+ var mockConn = new MockSqlConnection ( ) ;
130
+ TSqlConnectionContext . MockSqlConnection = mockConn ;
131
+
132
+ using ( System . Management . Automation . PowerShell powershell =
133
+ System . Management . Automation . PowerShell . Create ( ) )
134
+ {
135
+ // Create a context
136
+ NewAzureSqlDatabaseServerContextTests . CreateServerContextSqlAuthV2 (
137
+ powershell ,
138
+ manageUrl ,
139
+ username ,
140
+ password ,
141
+ "$context" ) ;
142
+
143
+ Collection < PSObject > database1 , database2 , database3 ;
144
+
145
+ database1 = powershell . InvokeBatchScript (
146
+ @"$testdb1 = Get-AzureSqlDatabase " +
147
+ @"-Context $context " +
148
+ @"-DatabaseName testdb1 " ,
149
+ @"$testdb1" ) ;
150
+ database2 = powershell . InvokeBatchScript (
151
+ @"$testdb2 = Get-AzureSqlDatabase " +
152
+ @"-Context $context " +
153
+ @"-Database $testdb1 " ,
154
+ @"$testdb2" ) ;
155
+ database3 = powershell . InvokeBatchScript (
156
+ @"$testdb3 = Get-AzureSqlDatabase " +
157
+ @"-Context $context " ,
158
+ @"$testdb3" ) ;
159
+
160
+ Assert . AreEqual ( 0 , powershell . Streams . Error . Count , "Errors during run!" ) ;
161
+ Assert . AreEqual ( 0 , powershell . Streams . Warning . Count , "Warnings during run!" ) ;
162
+ powershell . Streams . ClearStreams ( ) ;
163
+
164
+ Services . Server . Database database = database1 . Single ( ) . BaseObject as Services . Server . Database ;
165
+ Assert . IsTrue ( database != null , "Expecting a Database object" ) ;
166
+ ValidateDatabaseProperties ( database , "testdb1" , "Standard" , 250 , 268435456000L , "SQL_Latin1_General_CP1_CI_AS" , false , DatabaseTestHelper . StandardS0SloGuid ) ;
167
+
168
+ database = database2 . Single ( ) . BaseObject as Services . Server . Database ;
169
+ Assert . IsTrue ( database != null , "Expecting a Database object" ) ;
170
+ ValidateDatabaseProperties ( database , "testdb1" , "Standard" , 250 , 268435456000L , "SQL_Latin1_General_CP1_CI_AS" , false , DatabaseTestHelper . StandardS0SloGuid ) ;
171
+
172
+ Assert . IsTrue ( database3 . Count == 5 ) ;
173
+ foreach ( var entry in database3 )
174
+ {
175
+ var db = entry . BaseObject as Services . Server . Database ;
176
+ Assert . IsTrue ( db != null , "Expecting a Database object" ) ;
177
+ }
178
+ }
179
+ }
180
+
181
+ //[RecordMockDataResults("./")]
182
+ [ TestMethod ]
183
+ public void SetAzureSqlDatabaseWithSqlAuthv12 ( )
184
+ {
185
+ var mockConn = new MockSqlConnection ( ) ;
186
+ TSqlConnectionContext . MockSqlConnection = mockConn ;
187
+
188
+ using ( System . Management . Automation . PowerShell powershell =
189
+ System . Management . Automation . PowerShell . Create ( ) )
190
+ {
191
+ // Create a context
192
+ NewAzureSqlDatabaseServerContextTests . CreateServerContextSqlAuthV2 (
193
+ powershell ,
194
+ manageUrl ,
195
+ username ,
196
+ password ,
197
+ "$context" ) ;
198
+
199
+ Collection < PSObject > database1 , database2 , database3 , database4 ;
200
+
201
+ database1 = powershell . InvokeBatchScript (
202
+ @"$testdb1 = Set-AzureSqlDatabase " +
203
+ @"-Context $context " +
204
+ @"-DatabaseName testdb1 " +
205
+ @"-Edition Basic " +
206
+ @"-MaxSizeGb 1 " +
207
+ @"-Force " +
208
+ @"-PassThru " ,
209
+ @"$testdb1" ) ;
210
+ database2 = powershell . InvokeBatchScript (
211
+ @"$testdb2 = Set-AzureSqlDatabase " +
212
+ @"-Context $context " +
213
+ @"-DatabaseName testdb2 " +
214
+ @"-Edition Standard " +
215
+ @"-MaxSizeBytes 107374182400 " +
216
+ @"-Force " +
217
+ @"-PassThru " ,
218
+ @"$testdb2" ) ;
219
+ database3 = powershell . InvokeBatchScript (
220
+ @"$testdb3 = Set-AzureSqlDatabase " +
221
+ @"-Context $context " +
222
+ @"-DatabaseName testdb3 " +
223
+ @"-NewDatabaseName testdb3alt " +
224
+ @"-Force " +
225
+ @"-PassThru " ,
226
+ @"$testdb3" ) ;
227
+ var slo = powershell . InvokeBatchScript (
228
+ @"$so = Get-AzureSqlDatabaseServiceObjective " +
229
+ @"-Context $context " +
230
+ @"-ServiceObjectiveName S0 " ,
231
+ @"$so" ) ;
232
+ database4 = powershell . InvokeBatchScript (
233
+ @"$testdb4 = Set-AzureSqlDatabase " +
234
+ @"-Context $context " +
235
+ @"-DatabaseName testdb4 " +
236
+ @"-ServiceObjective $so " +
237
+ @"-Force " +
238
+ @"-PassThru " ,
239
+ @"$testdb4" ) ;
240
+
241
+ //
242
+ // Wait for operations to complete
243
+ //
244
+
245
+ database1 = powershell . InvokeBatchScript (
246
+ @"$testdb1 = Get-AzureSqlDatabase " +
247
+ @"-Context $context " +
248
+ @"-DatabaseName testdb1 " ,
249
+ @"$testdb1" ) ;
250
+ database2 = powershell . InvokeBatchScript (
251
+ @"$testdb2 = Get-AzureSqlDatabase " +
252
+ @"-Context $context " +
253
+ @"-DatabaseName testdb2 " ,
254
+ @"$testdb2" ) ;
255
+ database3 = powershell . InvokeBatchScript (
256
+ @"$testdb3 = Get-AzureSqlDatabase " +
257
+ @"-Context $context " +
258
+ @"-DatabaseName testdb3alt " ,
259
+ @"$testdb3" ) ;
260
+ database4 = powershell . InvokeBatchScript (
261
+ @"$testdb4 = Get-AzureSqlDatabase " +
262
+ @"-Context $context " +
263
+ @"-DatabaseName testdb4 " ,
264
+ @"$testdb4" ) ;
265
+
266
+ Assert . AreEqual ( 0 , powershell . Streams . Error . Count , "Errors during run!" ) ;
267
+ Assert . AreEqual ( 0 , powershell . Streams . Warning . Count , "Warnings during run!" ) ;
268
+ powershell . Streams . ClearStreams ( ) ;
269
+
270
+ Services . Server . Database database = database1 . Single ( ) . BaseObject as Services . Server . Database ;
271
+ Assert . IsTrue ( database != null , "Expecting a Database object" ) ;
272
+ ValidateDatabaseProperties ( database , "testdb1" , "Basic" , 1 , 1073741824L , "SQL_Latin1_General_CP1_CI_AS" , false , DatabaseTestHelper . BasicSloGuid ) ;
273
+
274
+ database = database2 . Single ( ) . BaseObject as Services . Server . Database ;
275
+ Assert . IsTrue ( database != null , "Expecting a Database object" ) ;
276
+ ValidateDatabaseProperties ( database , "testdb2" , "Standard" , 100 , 107374182400L , "Japanese_CI_AS" , false , DatabaseTestHelper . StandardS0SloGuid ) ;
277
+
278
+ database = database3 . Single ( ) . BaseObject as Services . Server . Database ;
279
+ Assert . IsTrue ( database != null , "Expecting a Database object" ) ;
280
+ ValidateDatabaseProperties ( database , "testdb3alt" , "Standard" , 100 , 107374182400L , "SQL_Latin1_General_CP1_CI_AS" , false , DatabaseTestHelper . StandardS0SloGuid ) ;
281
+
282
+ database = database4 . Single ( ) . BaseObject as Services . Server . Database ;
283
+ Assert . IsTrue ( database != null , "Expecting a Database object" ) ;
284
+ ValidateDatabaseProperties ( database , "testdb4" , "Standard" , 250 , 268435456000L , "SQL_Latin1_General_CP1_CI_AS" , false , DatabaseTestHelper . StandardS0SloGuid ) ;
285
+ }
286
+ }
287
+
288
+ #region Helpers
289
+
124
290
/// <summary>
125
291
/// Validate the properties of a database against the expected values supplied as input.
126
292
/// </summary>
@@ -148,5 +314,7 @@ internal static void ValidateDatabaseProperties(
148
314
Assert . AreEqual ( isSystem , database . IsSystemObject ) ;
149
315
// Assert.AreEqual(slo, database.ServiceObjectiveId);
150
316
}
317
+
318
+ #endregion
151
319
}
152
320
}
0 commit comments