Skip to content

Commit 9507bb3

Browse files
committed
Merge pull request #38 from akromm/dev-tsql
Add server v12 support to sql auth.
2 parents 46015bf + 8c00f01 commit 9507bb3

21 files changed

+4740
-95
lines changed

src/ServiceManagement/Sql/Commands.SqlDatabase.Test/Commands.SqlDatabase.Test.csproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<Reference Include="System.Core">
9191
<RequiredTargetFramework>3.5</RequiredTargetFramework>
9292
</Reference>
93+
<Reference Include="System.Data" />
9394
<Reference Include="System.Data.Services.Client" />
9495
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
9596
<SpecificVersion>False</SpecificVersion>
@@ -132,6 +133,18 @@
132133
<Compile Include="UnitTests\Database\Cmdlet\NewAzureSqlPremiumDatabaseTests.cs" />
133134
<Compile Include="UnitTests\Database\Cmdlet\AzureSqlDatabaseCopyCertAuthTests.cs" />
134135
<Compile Include="UnitTests\Database\Cmdlet\RestoreDatabaseTests.cs" />
136+
<Compile Include="UnitTests\Database\Cmdlet\SqlAuthv12MockTests.cs" />
137+
<Compile Include="UnitTests\TSql\MockQueryResult.cs" />
138+
<Compile Include="UnitTests\TSql\MockSettings.cs" />
139+
<Compile Include="UnitTests\TSql\MockSqlCommand.cs">
140+
<SubType>Component</SubType>
141+
</Compile>
142+
<Compile Include="UnitTests\TSql\MockSqlConnection.cs">
143+
<SubType>Component</SubType>
144+
</Compile>
145+
<Compile Include="UnitTests\TSql\MockSqlParameter.cs" />
146+
<Compile Include="UnitTests\TSql\MockSqlParameterCollection.cs" />
147+
<Compile Include="UnitTests\TSql\RecordMockDataResultsAttribute.cs" />
135148
<Compile Include="Utilities\SqlCustomPsHostUserInterface.cs" />
136149
<Compile Include="Utilities\SqlDatabaseSettings.cs" />
137150
<Compile Include="UnitTests\MockServer\AsyncExceptionManager.cs" />
@@ -221,6 +234,9 @@
221234
<SubType>Designer</SubType>
222235
</Content>
223236
<None Include="TestScripts\Database\DeleteDatabase-ScenarioFunctions.ps1" />
237+
<Content Include="Resources\TSqlMockSessions\SqlAuthv12MockTests.xml">
238+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
239+
</Content>
224240
<Content Include="TestScripts\Database\ExpectedFormat.txt" />
225241
<Content Include="TestScripts\Server\ExpectedFormat.txt" />
226242
</ItemGroup>

src/ServiceManagement/Sql/Commands.SqlDatabase.Test/Resources/TSqlMockSessions/SqlAuthv12MockTests.xml

Lines changed: 1218 additions & 0 deletions
Large diffs are not rendered by default.

src/ServiceManagement/Sql/Commands.SqlDatabase.Test/UnitTests/Database/Cmdlet/DatabaseTestHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public static class DatabaseTestHelper
4646
/// </summary>
4747
public static readonly Guid StandardS1SloGuid = new Guid("1b1ebd4d-d903-4baa-97f9-4ea675f5e928");
4848

49+
/// <summary>
50+
/// The unique GUID for identifying the Standard S0 SLO.
51+
/// </summary>
52+
public static readonly Guid StandardS0SloGuid = new Guid("f1173c43-91bd-4aaa-973c-54e79e15235b");
53+
4954
/// <summary>
5055
/// The unique GUID for identifying the Premium P1 SLO.
5156
/// </summary>

src/ServiceManagement/Sql/Commands.SqlDatabase.Test/UnitTests/Database/Cmdlet/ImportExportCmdletTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using Microsoft.WindowsAzure.Commands.SqlDatabase.Test.Utilities;
2525
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
2626
using Microsoft.WindowsAzure.Commands.Utilities.Common;
27+
using Microsoft.WindowsAzure.Commands.SqlDatabase.Services.Server;
2728

2829
namespace Microsoft.WindowsAzure.Commands.SqlDatabase.Test.UnitTests.Database.Cmdlet
2930
{
@@ -112,6 +113,10 @@ public void ImportExportAzureSqlDatabaseTests()
112113
@" -StorageAccountKey $storageAccountKey");
113114
}).FirstOrDefault();
114115

116+
// Tell the sql auth factory to create a v2 context (skip checking sql version using select query).
117+
//
118+
SqlAuthContextFactory.sqlVersion = SqlAuthContextFactory.SqlVersion.v2;
119+
115120
//testSession.ServiceBaseUri = new Uri("https://lqtqbo6kkp.database.windows.net");
116121
Collection<PSObject> databaseContext = MockServerHelper.ExecuteWithMock(
117122
testSession,

src/ServiceManagement/Sql/Commands.SqlDatabase.Test/UnitTests/Database/Cmdlet/NewAzureSqlDatabaseServerContextTests.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ public void NewAzureSqlDatabaseServerContextWithSqlAuth()
126126
UnitTestHelper.ImportAzureModule(powershell);
127127
UnitTestHelper.CreateTestCredential(powershell);
128128

129+
// Tell the sql auth factory to create a v2 context (skip checking sql version using select query).
130+
//
131+
SqlAuthContextFactory.sqlVersion = SqlAuthContextFactory.SqlVersion.v2;
129132
using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
130133
{
131134
Collection<PSObject> serverContext;
@@ -190,6 +193,10 @@ public void NewAzureSqlDatabaseServerContextWithSqlAuthNegativeCases()
190193

191194
using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
192195
{
196+
// Tell the sql auth factory to create a v2 context (skip checking sql version using select query).
197+
//
198+
SqlAuthContextFactory.sqlVersion = SqlAuthContextFactory.SqlVersion.v2;
199+
193200
// Test warning when different $metadata is received.
194201
Collection<PSObject> serverContext;
195202
using (new MockHttpServer(
@@ -212,6 +219,10 @@ public void NewAzureSqlDatabaseServerContextWithSqlAuthNegativeCases()
212219
Assert.AreEqual(2, powershell.Streams.Warning.Count, "Should have warning!");
213220
powershell.Streams.ClearStreams();
214221

222+
// Tell the sql auth factory to create a v2 context (skip checking sql version using select query).
223+
//
224+
SqlAuthContextFactory.sqlVersion = SqlAuthContextFactory.SqlVersion.v2;
225+
215226
// Test error case
216227
using (new MockHttpServer(
217228
exceptionManager,
@@ -308,6 +319,10 @@ public static void CreateServerContextSqlAuth(
308319
testSession.SessionProperties["Username"],
309320
testSession.SessionProperties["Password"]);
310321

322+
// Tell the sql auth factory to create a v2 context (skip checking sql version using select query).
323+
//
324+
SqlAuthContextFactory.sqlVersion = SqlAuthContextFactory.SqlVersion.v2;
325+
311326
Collection<PSObject> serverContext;
312327
using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
313328
{
@@ -339,5 +354,50 @@ public static void CreateServerContextSqlAuth(
339354
contextPsObject.BaseObject is ServerDataServiceSqlAuth,
340355
"Expecting a ServerDataServiceSqlAuth object");
341356
}
357+
358+
/// <summary>
359+
/// Common helper method for other tests to create a context for ESA server.
360+
/// </summary>
361+
/// <param name="contextVariable">The variable name that will hold the new context.</param>
362+
public static void CreateServerContextSqlAuthV12(
363+
System.Management.Automation.PowerShell powershell,
364+
string manageUrl,
365+
string username,
366+
string password,
367+
string contextVariable)
368+
{
369+
UnitTestHelper.ImportAzureModule(powershell);
370+
UnitTestHelper.CreateTestCredential(
371+
powershell,
372+
username,
373+
password);
374+
375+
// Tell the sql auth factory to create a v22 context (skip checking sql version using select query).
376+
//
377+
SqlAuthContextFactory.sqlVersion = SqlAuthContextFactory.SqlVersion.v12;
378+
379+
Collection<PSObject> serverContext;
380+
using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
381+
{
382+
serverContext = powershell.InvokeBatchScript(
383+
string.Format(
384+
CultureInfo.InvariantCulture,
385+
@"{1} = New-AzureSqlDatabaseServerContext " +
386+
@"-ManageUrl {0} " +
387+
@"-Credential $credential ",
388+
manageUrl,
389+
contextVariable),
390+
contextVariable);
391+
}
392+
393+
Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!");
394+
Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!");
395+
powershell.Streams.ClearStreams();
396+
397+
PSObject contextPsObject = serverContext.Single();
398+
Assert.IsTrue(
399+
contextPsObject.BaseObject is TSqlConnectionContext,
400+
"Expecting a TSqlConnectionContext object");
401+
}
342402
}
343403
}

src/ServiceManagement/Sql/Commands.SqlDatabase.Test/UnitTests/Database/Cmdlet/NewAzureSqlPremiumDatabaseTests.cs

Lines changed: 71 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void CreatePremiumDatabasesWithSqlAuth()
4848
"$context");
4949
HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession(
5050
"UnitTest.Common.CreatePremiumDatabasesWithSqlAuth");
51-
DatabaseTestHelper.SetDefaultTestSessionSettings(testSession);
51+
DatabaseTestHelper.SetDefaultTestSessionSettings(testSession);
5252
testSession.RequestValidator =
5353
new Action<HttpMessage, HttpMessage.Request>(
5454
(expected, actual) =>
@@ -57,69 +57,79 @@ public void CreatePremiumDatabasesWithSqlAuth()
5757
Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent);
5858
});
5959

60-
using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
60+
TestCreatePremiumDatabase(powershell, testSession);
61+
}
62+
}
63+
64+
/// <summary>
65+
/// Helper function to create premium database in the powershell environment provided.
66+
/// </summary>
67+
/// <param name="powershell">The powershell environment</param>
68+
/// <param name="testSession">The test session</param>
69+
private static void TestCreatePremiumDatabase(System.Management.Automation.PowerShell powershell, HttpSession testSession)
70+
{
71+
using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
72+
{
73+
Collection<PSObject> premiumDB_P1, PremiumDB_P2;
74+
using (new MockHttpServer(
75+
exceptionManager,
76+
MockHttpServer.DefaultServerPrefixUri,
77+
testSession))
6178
{
62-
Collection<PSObject> premiumDB_P1, PremiumDB_P2;
63-
using (new MockHttpServer(
64-
exceptionManager,
65-
MockHttpServer.DefaultServerPrefixUri,
66-
testSession))
67-
{
68-
powershell.InvokeBatchScript(
69-
@"$P1 = Get-AzureSqlDatabaseServiceObjective" +
70-
@" -Context $context" +
71-
@" -ServiceObjectiveName ""P1""");
72-
73-
powershell.InvokeBatchScript(
74-
@"$P2 = Get-AzureSqlDatabaseServiceObjective " +
75-
@"-Context $context" +
76-
@" -ServiceObjectiveName ""P2""");
77-
78-
premiumDB_P1 = powershell.InvokeBatchScript(
79-
@"$premiumDB_P1 = New-AzureSqlDatabase " +
80-
@"-Context $context " +
81-
@"-DatabaseName NewAzureSqlPremiumDatabaseTests_P1 " +
82-
@"-Edition Premium " +
83-
@"-ServiceObjective $P1 ");
84-
premiumDB_P1 = powershell.InvokeBatchScript("$PremiumDB_P1");
85-
86-
powershell.InvokeBatchScript(
87-
@"$PremiumDB_P2 = New-AzureSqlDatabase " +
88-
@"-Context $context " +
89-
@"-DatabaseName NewAzureSqlPremiumDatabaseTests_P2 " +
90-
@"-Collation Japanese_CI_AS " +
91-
@"-Edition Premium " +
92-
@"-ServiceObjective $P2 " +
93-
@"-MaxSizeGB 10 " +
94-
@"-Force");
95-
PremiumDB_P2 = powershell.InvokeBatchScript("$PremiumDB_P2");
96-
}
79+
powershell.InvokeBatchScript(
80+
@"$P1 = Get-AzureSqlDatabaseServiceObjective" +
81+
@" -Context $context" +
82+
@" -ServiceObjectiveName ""P1""");
9783

98-
Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!");
99-
Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!");
100-
powershell.Streams.ClearStreams();
101-
102-
Assert.IsTrue(
103-
premiumDB_P1.Single().BaseObject is Services.Server.Database,
104-
"Expecting a Database object");
105-
Services.Server.Database databaseP1 =
106-
(Services.Server.Database)premiumDB_P1.Single().BaseObject;
107-
Assert.AreEqual("NewAzureSqlPremiumDatabaseTests_P1", databaseP1.Name, "Expected db name to be NewAzureSqlPremiumDatabaseTests_P1");
108-
109-
Assert.IsTrue(
110-
PremiumDB_P2.Single().BaseObject is Services.Server.Database,
111-
"Expecting a Database object");
112-
Services.Server.Database databaseP2 =
113-
(Services.Server.Database)PremiumDB_P2.Single().BaseObject;
114-
Assert.AreEqual("NewAzureSqlPremiumDatabaseTests_P2", databaseP2.Name, "Expected db name to be NewAzureSqlPremiumDatabaseTests_P2");
115-
116-
Assert.AreEqual(
117-
"Japanese_CI_AS",
118-
databaseP2.CollationName,
119-
"Expected collation to be Japanese_CI_AS");
120-
Assert.AreEqual("Premium", databaseP2.Edition, "Expected edition to be Premium");
121-
Assert.AreEqual(10, databaseP2.MaxSizeGB, "Expected max size to be 10 GB");
84+
powershell.InvokeBatchScript(
85+
@"$P2 = Get-AzureSqlDatabaseServiceObjective " +
86+
@"-Context $context" +
87+
@" -ServiceObjectiveName ""P2""");
88+
89+
premiumDB_P1 = powershell.InvokeBatchScript(
90+
@"$premiumDB_P1 = New-AzureSqlDatabase " +
91+
@"-Context $context " +
92+
@"-DatabaseName NewAzureSqlPremiumDatabaseTests_P1 " +
93+
@"-Edition Premium " +
94+
@"-ServiceObjective $P1 ");
95+
premiumDB_P1 = powershell.InvokeBatchScript("$PremiumDB_P1");
96+
97+
powershell.InvokeBatchScript(
98+
@"$PremiumDB_P2 = New-AzureSqlDatabase " +
99+
@"-Context $context " +
100+
@"-DatabaseName NewAzureSqlPremiumDatabaseTests_P2 " +
101+
@"-Collation Japanese_CI_AS " +
102+
@"-Edition Premium " +
103+
@"-ServiceObjective $P2 " +
104+
@"-MaxSizeGB 10 " +
105+
@"-Force");
106+
PremiumDB_P2 = powershell.InvokeBatchScript("$PremiumDB_P2");
122107
}
108+
109+
Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!");
110+
Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!");
111+
powershell.Streams.ClearStreams();
112+
113+
Assert.IsTrue(
114+
premiumDB_P1.Single().BaseObject is Services.Server.Database,
115+
"Expecting a Database object");
116+
Services.Server.Database databaseP1 =
117+
(Services.Server.Database)premiumDB_P1.Single().BaseObject;
118+
Assert.AreEqual("NewAzureSqlPremiumDatabaseTests_P1", databaseP1.Name, "Expected db name to be NewAzureSqlPremiumDatabaseTests_P1");
119+
120+
Assert.IsTrue(
121+
PremiumDB_P2.Single().BaseObject is Services.Server.Database,
122+
"Expecting a Database object");
123+
Services.Server.Database databaseP2 =
124+
(Services.Server.Database)PremiumDB_P2.Single().BaseObject;
125+
Assert.AreEqual("NewAzureSqlPremiumDatabaseTests_P2", databaseP2.Name, "Expected db name to be NewAzureSqlPremiumDatabaseTests_P2");
126+
127+
Assert.AreEqual(
128+
"Japanese_CI_AS",
129+
databaseP2.CollationName,
130+
"Expected collation to be Japanese_CI_AS");
131+
Assert.AreEqual("Premium", databaseP2.Edition, "Expected edition to be Premium");
132+
Assert.AreEqual(10, databaseP2.MaxSizeGB, "Expected max size to be 10 GB");
123133
}
124134
}
125135

0 commit comments

Comments
 (0)