Skip to content

Dev sql fixes 0.8.14 #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44,100 changes: 38,617 additions & 5,483 deletions src/ServiceManagement/Sql/Commands.SqlDatabase.Test/Resources/MockSessions.xml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public void InitializeTest()
testSession);
}


[TestCleanup]
public void CleanupTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@ public static class DatabaseTestHelper
/// The unique GUID for identifying the Shared SLO.
/// </summary>
public static readonly Guid SharedSloGuid = new Guid("910b4fcb-8a29-4c3e-958f-f7ba794388b2");

/// <summary>
/// The unique GUID for identifying the System SLO.
/// </summary>
public static readonly Guid SystemSloGuid = new Guid("26e021db-f1f9-4c98-84c6-92af8ef433d7");

/// <summary>
/// The unique GUID for identifying the System2 SLO.
/// </summary>
public static readonly Guid System2SloGuid = new Guid("620323bf-2879-4807-b30d-c2e6d7b3b3aa");

/// <summary>
/// The unique GUID for identifying the Business SLO.
/// </summary>
public static readonly Guid BusinessSloGuid = new Guid("4518ce8e-6026-4113-b4fd-3b5d777c6881");

/// <summary>
/// The unique GUID for identifying the Basic SLO.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public static void CreateTestDatabasesWithCertAuth(System.Management.Automation.
@"-ServerName $serverName " +
@"-DatabaseName testdb2 " +
@"-Collation Japanese_CI_AS " +
@"-Edition Web " +
@"-Edition Standard " +
@"-MaxSizeGB 5 " +
@"-Force",
@"$testdb2");
Expand All @@ -365,15 +365,15 @@ public static void CreateTestDatabasesWithCertAuth(System.Management.Automation.

Services.Server.Database database = database1.Single().BaseObject as Services.Server.Database;
Assert.IsTrue(database != null, "Expecting a Database object");
DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb1", "Web", 1, 1073741824L, "SQL_Latin1_General_CP1_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid);
DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb1", "Standard", 250, 268435456000L, "SQL_Latin1_General_CP1_CI_AS", "S0", false, DatabaseTestHelper.StandardS0SloGuid);

database = database2.Single().BaseObject as Services.Server.Database;
Assert.IsTrue(database != null, "Expecting a Database object");
DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb2", "Web", 5, 5368709120L, "Japanese_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid);
DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb2", "Standard", 250, 268435456000L, "Japanese_CI_AS", "S0", false, DatabaseTestHelper.StandardS0SloGuid);

database = database3.Single().BaseObject as Services.Server.Database;
Assert.IsTrue(database != null, "Expecting a Database object");
DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb3", "Web", 0, 104857600L, "SQL_Latin1_General_CP1_CI_AS", "Shared", false, DatabaseTestHelper.SharedSloGuid);
DatabaseTestHelper.ValidateDatabaseProperties(database, "testdb3", "Standard", 0, 104857600L, "SQL_Latin1_General_CP1_CI_AS", "S0", false, DatabaseTestHelper.StandardS0SloGuid);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,35 @@ namespace Microsoft.WindowsAzure.Commands.SqlDatabase.Test.UnitTests.Server.Cmdl
[TestClass]
public class ServerCmdletTests : TestBase
{
// String ID for server version 2.
public const string ServerVersion2 = "2.0";

// String ID for server version 12.
public const string ServerVersion12 = "12.0";

// The default server version
public const string DefaultServerVersion = ServerVersion12;

[TestCleanup]
public void CleanupTest()
{
// Save the mock session results
MockServerHelper.SaveDefaultSessionCollection();
}

private static void VerifyServer(SqlDatabaseServerContext server, string adminLogin, string location)
/// <summary>
/// Verifys the server object to make sure the fields match what is provided
/// </summary>
/// <param name="server">The server object to validate</param>
/// <param name="adminLogin">The expected administration login</param>
/// <param name="location">The expected server location</param>
/// <param name="version">The expected server verions</param>
/// <param name="state">The expected state of the server</param>
private static void VerifyServer(SqlDatabaseServerContext server, string adminLogin, string location, string version, string state)
{
Assert.AreEqual(adminLogin, server.AdministratorLogin, "Expecting server login to match.");
Assert.AreEqual(location, server.Location, "Expecting matching location.");
Assert.AreEqual(10, server.ServerName.Length, "Expecting a valid server name.");
}

private static void VerifyServer(SqlDatabaseServerContext server, string adminLogin, string location, string version, string state)
{
VerifyServer(server, adminLogin, location);
Assert.AreEqual(version, server.Version, "Server version doesn't match");
Assert.AreEqual(state, server.State, "Server state does not match");
}
Expand Down Expand Up @@ -190,14 +202,18 @@ public void AzureSqlDatabaseServerTests()
VerifyServer(
server,
(string)powershell.Runspace.SessionStateProxy.GetVariable("login"),
(string)powershell.Runspace.SessionStateProxy.GetVariable("location"));
(string)powershell.Runspace.SessionStateProxy.GetVariable("location"),
ServerVersion12,
"Ready");

SqlDatabaseServerContext server2 = newServerResult2.Single().BaseObject as SqlDatabaseServerContext;
Assert.IsNotNull(server2, "Expecting a SqlDatabaseServerContext object");
VerifyServer(
server,
(string)powershell.Runspace.SessionStateProxy.GetVariable("login"),
(string)powershell.Runspace.SessionStateProxy.GetVariable("location"));
(string)powershell.Runspace.SessionStateProxy.GetVariable("location"),
ServerVersion12,
"Ready");

// Validate Get-AzureSqlDatabaseServer results
server = getServerResult.Single().BaseObject as SqlDatabaseServerContext;
Expand All @@ -206,7 +222,7 @@ public void AzureSqlDatabaseServerTests()
server,
(string)powershell.Runspace.SessionStateProxy.GetVariable("login"),
(string)powershell.Runspace.SessionStateProxy.GetVariable("location"),
"2.0",
ServerVersion12,
"Ready");

server = setServerResult.Single().BaseObject as SqlDatabaseServerContext;
Expand All @@ -215,7 +231,7 @@ public void AzureSqlDatabaseServerTests()
server,
(string)powershell.Runspace.SessionStateProxy.GetVariable("login"),
(string)powershell.Runspace.SessionStateProxy.GetVariable("location"),
"2.0",
ServerVersion12,
"Ready");

server2 = setServerResult2.Single().BaseObject as SqlDatabaseServerContext;
Expand All @@ -224,7 +240,7 @@ public void AzureSqlDatabaseServerTests()
server2,
(string)powershell.Runspace.SessionStateProxy.GetVariable("login"),
(string)powershell.Runspace.SessionStateProxy.GetVariable("location"),
"2.0",
ServerVersion12,
"Ready");

// Validate Remove-AzureSqlDatabaseServer results
Expand Down Expand Up @@ -319,7 +335,9 @@ public void AzureSqlDatabaseServerV2Tests()
VerifyServer(
server,
(string)powershell.Runspace.SessionStateProxy.GetVariable("login"),
(string)powershell.Runspace.SessionStateProxy.GetVariable("location"));
(string)powershell.Runspace.SessionStateProxy.GetVariable("location"),
ServerVersion2,
"Ready");


// Validate Get-AzureSqlDatabaseServer results
Expand All @@ -329,8 +347,8 @@ public void AzureSqlDatabaseServerV2Tests()
server,
(string)powershell.Runspace.SessionStateProxy.GetVariable("login"),
(string)powershell.Runspace.SessionStateProxy.GetVariable("location"),
"2.0",
null);
ServerVersion2,
"Ready");

powershell.Streams.ClearStreams();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,13 @@ public static AzureSubscription SetupUnitTestSubscription(System.Management.Auto
{
UnitTestHelper.ImportAzureModule(powershell);

X509Certificate2 certificate = UnitTestHelper.GetUnitTestClientCertificate();
Guid subscriptionId = new Guid(UnitTestSubscriptionId);

// Set the client certificate used in the subscription
powershell.Runspace.SessionStateProxy.SetVariable(
"clientCertificate",
UnitTestHelper.GetUnitTestClientCertificate());
certificate);

ProfileClient client = new ProfileClient();
client.Profile.Environments[UnitTestEnvironmentName] = new AzureEnvironment
Expand All @@ -308,13 +311,13 @@ public static AzureSubscription SetupUnitTestSubscription(System.Management.Auto

var account = new AzureAccount
{
Id = UnitTestHelper.GetUnitTestClientCertificate().Thumbprint,
Id = certificate.Thumbprint,
Type = AzureAccount.AccountType.Certificate
};

var subscription = new AzureSubscription
{
Id = new Guid(UnitTestSubscriptionId),
Id = subscriptionId,
Name = UnitTestSubscriptionName,
Environment = UnitTestEnvironmentName,
Account = account.Id
Expand All @@ -324,7 +327,7 @@ public static AzureSubscription SetupUnitTestSubscription(System.Management.Auto
client.AddOrSetSubscription(subscription);
client.SetSubscriptionAsCurrent(UnitTestSubscriptionName, account.Id);
client.Profile.Save();

return subscription;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2192,7 +2192,7 @@ Business Edition values: 10, 20, 30, 40, 50, 100, or 150</maml:para>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
<maml:name>Version</maml:name>
<maml:description>
<maml:para>Specifies the type of SQL Database Server to create. Accepts values 1.0 or 2.0.</maml:para>
<maml:para>Specifies the type of SQL Database Server to create. Accepts values 2.0 or 12.0.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">Single</command:parameterValue>
</command:parameter>
Expand Down Expand Up @@ -2259,7 +2259,7 @@ Business Edition values: 10, 20, 30, 40, 50, 100, or 150</maml:para>
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
<maml:name>Version</maml:name>
<maml:description>
<maml:para>Specifies the type of SQL Database Server to create. Accepts values 1.0 or 2.0.</maml:para>
<maml:para>Specifies the type of SQL Database Server to create. Accepts values 2.0 or 12.0.</maml:para>
</maml:description>
<command:parameterValue required="true" variableLength="false">Single</command:parameterValue>
<dev:type>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
<value>Invalid Parameter combination: Both "DatabaseName" and "DatabaseDeletionDate" need to be specified to get a restorable dropped database.</value>
<comment>Parameter validation</comment>
</data>
<data name="CreateServerServerNotFound" xml:space="preserve">
<value>Unable to retrieve newly created server '{0}'.</value>
</data>
<data name="CredentialNotSpecified" xml:space="preserve">
<value>The Sql Authenticate Credential was not specified.</value>
<comment>Parameter validation</comment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Hyak.Common.TransientFaultHandling;
using Microsoft.WindowsAzure.Commands.SqlDatabase.Model;
using Microsoft.WindowsAzure.Commands.SqlDatabase.Properties;
using Microsoft.Azure.Common.Internals;
using Microsoft.WindowsAzure.Management.Sql;
using Microsoft.WindowsAzure.Management.Sql.Models;
using Hyak.Common;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Management.Automation;
using Hyak.Common.TransientFaultHandling;

namespace Microsoft.WindowsAzure.Commands.SqlDatabase.Server.Cmdlet
{
Expand Down Expand Up @@ -119,14 +120,26 @@ internal SqlDatabaseServerContext NewAzureSqlDatabaseServerProcess(
Version = version.HasValue ? version.Value.ToString("F1") : null
});

var newServer = sqlManagementClient.Servers.List().Servers.Where(s => s.Name == response.ServerName).FirstOrDefault();

if (newServer == null)
{
throw new ItemNotFoundException(string.Format(
CultureInfo.InvariantCulture,
Resources.CreateServerServerNotFound,
response.ServerName));
}

SqlDatabaseServerContext operationContext = new SqlDatabaseServerContext()
{
OperationStatus = Services.Constants.OperationSuccess,
OperationDescription = CommandRuntime.ToString(),
OperationId = response.RequestId,
ServerName = response.ServerName,
ServerName = newServer.Name,
Location = location,
AdministratorLogin = adminLogin,
State = newServer.State,
Version = newServer.Version
};

return operationContext;
Expand Down
Loading