public void AzureSqlDatabaseServerV2Tests()
        {
            // This test uses the https endpoint, setup the certificates.
            MockHttpServer.SetupCertificates();

            using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create())
            {
                // Setup the subscription used for the test
                AzureSubscription subscription =
                    UnitTestHelper.SetupUnitTestSubscription(powershell);

                // Create a new V2 server
                HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession(
                    "UnitTest.AzureSqlDatabaseServerV2Tests");
                ServerTestHelper.SetDefaultTestSessionSettings(testSession);
                testSession.RequestValidator =
                    new Action <HttpMessage, HttpMessage.Request>(
                        (expected, actual) =>
                {
                    Assert.AreEqual(expected.RequestInfo.Method, actual.Method);
                    Assert.IsTrue(
                        actual.UserAgent.Contains(ApiConstants.UserAgentHeaderValue),
                        "Missing proper UserAgent string.");
                });

                powershell.Runspace.SessionStateProxy.SetVariable("login", "mylogin");
                powershell.Runspace.SessionStateProxy.SetVariable("password", "Pa$$w0rd!");
                powershell.Runspace.SessionStateProxy.SetVariable("location", "East Asia");
                Collection <PSObject> newServerResult = MockServerHelper.ExecuteWithMock(
                    testSession,
                    MockHttpServer.DefaultHttpsServerPrefixUri,
                    () =>
                {
                    return(powershell.InvokeBatchScript(
                               @"New-AzureSqlDatabaseServer" +
                               @" -AdministratorLogin $login" +
                               @" -AdministratorLoginPassword $password" +
                               @" -Location $location" +
                               @" -Version 2"));
                });

                Collection <PSObject> getServerResult = MockServerHelper.ExecuteWithMock(
                    testSession,
                    MockHttpServer.DefaultHttpsServerPrefixUri,
                    () =>
                {
                    powershell.Runspace.SessionStateProxy.SetVariable("server", newServerResult);
                    return(powershell.InvokeBatchScript(
                               @"Get-AzureSqlDatabaseServer $server.ServerName"));
                });

                Collection <PSObject> removeServerResult = MockServerHelper.ExecuteWithMock(
                    testSession,
                    MockHttpServer.DefaultHttpsServerPrefixUri,
                    () =>
                {
                    powershell.Runspace.SessionStateProxy.SetVariable("server", newServerResult);
                    powershell.InvokeBatchScript(
                        @"$server | Remove-AzureSqlDatabaseServer" +
                        @" -Force");

                    return(powershell.InvokeBatchScript(
                               @"Get-AzureSqlDatabaseServer"));
                });

                Assert.AreEqual(0, powershell.Streams.Error.Count, "Unexpected Errors during run!");
                Assert.AreEqual(0, powershell.Streams.Warning.Count, "Unexpected Warnings during run!");

                // Validate New-AzureSqlDatabaseServer results
                SqlDatabaseServerContext server =
                    newServerResult.Single().BaseObject as SqlDatabaseServerContext;
                Assert.IsNotNull(server, "Expecting a SqlDatabaseServerContext object");
                VerifyServer(
                    server,
                    (string)powershell.Runspace.SessionStateProxy.GetVariable("login"),
                    (string)powershell.Runspace.SessionStateProxy.GetVariable("location"));


                // Validate Get-AzureSqlDatabaseServer results
                server = getServerResult.Single().BaseObject as SqlDatabaseServerContext;
                Assert.IsNotNull(server, "Expecting a SqlDatabaseServerContext object");
                VerifyServer(
                    server,
                    (string)powershell.Runspace.SessionStateProxy.GetVariable("login"),
                    (string)powershell.Runspace.SessionStateProxy.GetVariable("location"),
                    "2.0",
                    null);

                powershell.Streams.ClearStreams();
            }
        }
Esempio n. 2
0
        public void ImportExportAzureSqlDatabaseTestv12()
        {
            using (System.Management.Automation.PowerShell powershell =
                       System.Management.Automation.PowerShell.Create())
            {
                // Setup the subscription used for the test
                AzureSubscription subscription =
                    UnitTestHelper.SetupUnitTestSubscription(powershell);

                // Set the necessary session variables
                powershell.Runspace.SessionStateProxy.SetVariable(
                    "serverName",
                    SqlDatabaseTestSettings.Instance.ServerName);
                powershell.Runspace.SessionStateProxy.SetVariable(
                    "sourceDB",
                    SqlDatabaseTestSettings.Instance.SourceDatabaseName);
                powershell.Runspace.SessionStateProxy.SetVariable(
                    "targetDB",
                    SqlDatabaseTestSettings.Instance.TargetDatabaseName);
                powershell.Runspace.SessionStateProxy.SetVariable(
                    "credential",
                    new PSCredential(
                        SqlDatabaseTestSettings.Instance.UserName,
                        SqlDatabaseTestSettings.Instance.SecurePassword));
                powershell.Runspace.SessionStateProxy.SetVariable(
                    "storageAccountName",
                    SqlDatabaseTestSettings.Instance.StorageName);
                powershell.Runspace.SessionStateProxy.SetVariable(
                    "storageAccountKey",
                    SqlDatabaseTestSettings.Instance.AccessKey);
                powershell.Runspace.SessionStateProxy.SetVariable(
                    "storageContainerName",
                    SqlDatabaseTestSettings.Instance.ContainerName);

                // Create a new server
                HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession(
                    "UnitTest.ImportExportAzureSqlDatabaseTestsv12");
                ServerTestHelper.SetDefaultTestSessionSettings(testSession);

                testSession.RequestValidator =
                    new Action <HttpMessage, HttpMessage.Request>(
                        (expected, actual) =>
                {
                    Assert.AreEqual(expected.RequestInfo.Method, actual.Method);
                    string expectedRequestText = RequestTextToString(expected.RequestInfo);
                    string actualRequestText   = RequestTextToString(actual);

                    // When checking out from GitHub, different new line setting may lead to different char \r\n or \n
                    // Replace them with String.Empty before comparison
                    Assert.AreEqual(
                        Regex.Replace(expectedRequestText, @"\s+", String.Empty),
                        Regex.Replace(actualRequestText, @"\s+", String.Empty));
                    Assert.IsTrue(
                        actual.UserAgent.Contains(ApiConstants.UserAgentHeaderValue),
                        "Missing proper UserAgent string.");
                });

                StorageCredentials  credential     = new StorageCredentials(SqlDatabaseTestSettings.Instance.StorageName, SqlDatabaseTestSettings.Instance.AccessKey);
                string              blobEndpoint   = String.Format("https://{0}.blob.{1}/", SqlDatabaseTestSettings.Instance.StorageName, "core.windows.net");
                string              tableEndpoint  = String.Format("https://{0}.table.{1}/", SqlDatabaseTestSettings.Instance.StorageName, "core.windows.net");
                string              queueEndpoint  = String.Format("http://{0}.queue.{1}/", SqlDatabaseTestSettings.Instance.StorageName, "core.windows.net");
                string              fileEndpoint   = String.Format("https://{0}.file.{1}/", SqlDatabaseTestSettings.Instance.StorageName, "core.windows.net");
                CloudStorageAccount account        = new CloudStorageAccount(credential, new Uri(blobEndpoint), new Uri(queueEndpoint), new Uri(tableEndpoint), new Uri(fileEndpoint));
                AzureStorageContext storageContext = new AzureStorageContext(account);

                // Tell the sql auth factory to create a v12 context (skip checking sql version using select query).
                //
                SqlAuthContextFactory.sqlVersion = SqlAuthContextFactory.SqlVersion.v12;

                Collection <PSObject> databaseContext = MockServerHelper.ExecuteWithMock(
                    testSession,
                    MockHttpServer.DefaultServerPrefixUri,
                    () =>
                {
                    powershell.Runspace.SessionStateProxy.SetVariable(
                        "manageUrl",
                        MockHttpServer.DefaultServerPrefixUri.AbsoluteUri);
                    return(powershell.InvokeBatchScript(
                               @"New-AzureSqlDatabaseServerContext" +
                               @" -ServerName $serverName" +
                               @" -ManageUrl $manageUrl" +
                               @" -Credential $credential"));
                });

                Collection <PSObject> startExportResult = MockServerHelper.ExecuteWithMock(
                    testSession,
                    MockHttpServer.DefaultHttpsServerPrefixUri,
                    () =>
                {
                    powershell.Runspace.SessionStateProxy.SetVariable("storageContext", storageContext);
                    powershell.Runspace.SessionStateProxy.SetVariable(
                        "databaseContext",
                        databaseContext.FirstOrDefault());
                    return(powershell.InvokeBatchScript(
                               @"Start-AzureSqlDatabaseExport" +
                               @" -SqlConnectionContext $databaseContext" +
                               @" -DatabaseName $sourceDB" +
                               @" -StorageContext $storageContext" +
                               @" -StorageContainerName $storageContainerName" +
                               @" -BlobName backup1"));
                });

                // Wait here for operation to finish

                Collection <PSObject> getExportStatusResult = MockServerHelper.ExecuteWithMock(
                    testSession,
                    MockHttpServer.DefaultHttpsServerPrefixUri,
                    () =>
                {
                    powershell.Runspace.SessionStateProxy.SetVariable(
                        "exportResult",
                        startExportResult.FirstOrDefault());
                    return(powershell.InvokeBatchScript(
                               @"Get-AzureSqlDatabaseImportExportStatus" +
                               @" -ServerName $serverName" +
                               @" -RequestId $exportResult.RequestGuid" +
                               @" -Username $exportResult.SqlCredentials.UserName" +
                               @" -Password $exportResult.SqlCredentials.Password"));
                });

                Collection <PSObject> startImportResult = MockServerHelper.ExecuteWithMock(
                    testSession,
                    MockHttpServer.DefaultHttpsServerPrefixUri,
                    () =>
                {
                    return(powershell.InvokeBatchScript(
                               @"Start-AzureSqlDatabaseImport" +
                               @" -SqlConnectionContext $databaseContext" +
                               @" -DatabaseName $targetDB" +
                               @" -Edition Business" +
                               @" -DatabaseMaxSize 10" +
                               @" -StorageContext $storageContext" +
                               @" -StorageContainerName $storageContainerName" +
                               @" -BlobName backup1"));
                });

                // Wait here for import to finish

                Collection <PSObject> getImportStatusResult = MockServerHelper.ExecuteWithMock(
                    testSession,
                    MockHttpServer.DefaultHttpsServerPrefixUri,
                    () =>
                {
                    powershell.Runspace.SessionStateProxy.SetVariable(
                        "importResult",
                        startImportResult.FirstOrDefault());
                    return(powershell.InvokeBatchScript(
                               @"Get-AzureSqlDatabaseImportExportStatus" +
                               @" -ServerName $serverName" +
                               @" -RequestId $importResult.RequestGuid" +
                               @" -Username $importResult.SqlCredentials.UserName" +
                               @" -Password $importResult.SqlCredentials.Password"));
                });

                Assert.AreEqual(0, powershell.Streams.Error.Count, "Unexpected Errors during run!");
                Assert.AreEqual(0, powershell.Streams.Warning.Count, "Unexpected Warnings during run!");
            }
        }
Esempio n. 3
0
 public void Cleanup()
 {
     // Save the mock session results
     MockServerHelper.SaveDefaultSessionCollection();
 }
Esempio n. 4
0
        public void AzureSqlDatabaseCertTests()
        {
            // This test uses the https endpoint, setup the certificates.
            MockHttpServer.SetupCertificates();

            using (PowerShell powershell = PowerShell.Create())
            {
                // Setup the subscription used for the test
                WindowsAzureSubscription subscription =
                    UnitTestHelper.SetupUnitTestSubscription(powershell);

                powershell.Runspace.SessionStateProxy.SetVariable(
                    "serverName",
                    SqlDatabaseTestSettings.Instance.ServerName);

                // Create a new server
                HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession(
                    "UnitTest.AzureSqlDatabaseCertTests");
                ServerTestHelper.SetDefaultTestSessionSettings(testSession);
                //testSession.ServiceBaseUri = new Uri("https://management.core.windows.net");
                testSession.RequestValidator =
                    new Action <HttpMessage, HttpMessage.Request>(
                        (expected, actual) =>
                {
                    Assert.AreEqual(expected.RequestInfo.Method, actual.Method);
                    Assert.IsTrue(
                        actual.UserAgent.Contains(ApiConstants.UserAgentHeaderValue),
                        "Missing proper UserAgent string.");
                    Assert.IsTrue(
                        UnitTestHelper.GetUnitTestClientCertificate().Equals(actual.Certificate),
                        "Expected correct client certificate");
                });

                Collection <PSObject> newDatabaseResult1 = MockServerHelper.ExecuteWithMock(
                    testSession,
                    MockHttpServer.DefaultHttpsServerPrefixUri,
                    () =>
                {
                    return(powershell.InvokeBatchScript(
                               @"New-AzureSqlDatabase" +
                               @" -ServerName $serverName" +
                               @" -DatabaseName testdbcert1"));
                });

                Collection <PSObject> newDatabaseResult2 = MockServerHelper.ExecuteWithMock(
                    testSession,
                    MockHttpServer.DefaultHttpsServerPrefixUri,
                    () =>
                {
                    return(powershell.InvokeBatchScript(
                               @"New-AzureSqlDatabase" +
                               @" -ServerName $serverName" +
                               @" -DatabaseName testdbcert2" +
                               @" -Edition Business" +
                               @" -MaxSizeGB 10" +
                               @" -Collation Japanese_CI_AS"));
                });

                Collection <PSObject> getDatabaseResult = MockServerHelper.ExecuteWithMock(
                    testSession,
                    MockHttpServer.DefaultHttpsServerPrefixUri,
                    () =>
                {
                    return(powershell.InvokeBatchScript(
                               @"Get-AzureSqlDatabase" +
                               @" $serverName"));
                });

                Collection <PSObject> getSingleDatabaseResult = MockServerHelper.ExecuteWithMock(
                    testSession,
                    MockHttpServer.DefaultHttpsServerPrefixUri,
                    () =>
                {
                    return(powershell.InvokeBatchScript(
                               @"Get-AzureSqlDatabase" +
                               @" $serverName" +
                               @" -DatabaseName testdbcert1"));
                });

                Collection <PSObject> setDatabaseNameResult = MockServerHelper.ExecuteWithMock(
                    testSession,
                    MockHttpServer.DefaultHttpsServerPrefixUri,
                    () =>
                {
                    powershell.Runspace.SessionStateProxy.SetVariable("db", newDatabaseResult1.FirstOrDefault());
                    return(powershell.InvokeBatchScript(
                               @"$db | Set-AzureSqlDatabase" +
                               @" -NewDatabaseName testdbcert3" +
                               @" -PassThru"));
                });

                Collection <PSObject> setDatabaseSizeResult = MockServerHelper.ExecuteWithMock(
                    testSession,
                    MockHttpServer.DefaultHttpsServerPrefixUri,
                    () =>
                {
                    powershell.Runspace.SessionStateProxy.SetVariable("db", newDatabaseResult1.FirstOrDefault());
                    return(powershell.InvokeBatchScript(
                               @"$db | Set-AzureSqlDatabase" +
                               @" -MaxSizeGB 5" +
                               @" -PassThru"));
                });

                Collection <PSObject> removeDatabaseResult = MockServerHelper.ExecuteWithMock(
                    testSession,
                    MockHttpServer.DefaultHttpsServerPrefixUri,
                    () =>
                {
                    powershell.Runspace.SessionStateProxy.SetVariable("db1", newDatabaseResult1.FirstOrDefault());
                    powershell.Runspace.SessionStateProxy.SetVariable("db2", newDatabaseResult2.FirstOrDefault());
                    powershell.InvokeBatchScript(
                        @"$db1 | Remove-AzureSqlDatabase" +
                        @" -Force");
                    powershell.InvokeBatchScript(
                        @"$db2 | Remove-AzureSqlDatabase" +
                        @" -Force");

                    return(powershell.InvokeBatchScript(
                               @"Get-AzureSqlDatabase" +
                               @" $serverName"));
                });

                Assert.AreEqual(0, powershell.Streams.Error.Count, "Unexpected Errors during run!");
                Assert.AreEqual(0, powershell.Streams.Warning.Count, "Unexpected Warnings during run!");

                // Validate New-AzureSqlDatabase
                Database[] databases = new Database[] { newDatabaseResult1.Single().BaseObject as Database };
                Assert.AreEqual(1, databases.Length, "Expecting one database");
                Assert.IsNotNull(databases[0],
                                 "Expecting a Database object.");
                // Note: Because the object is piped, this is the final state of the
                // database object, after all the Set- cmdlet has run.
                Assert.AreEqual("testdbcert3", databases[0].Name);
                Assert.AreEqual("Web", databases[0].Edition);
                Assert.AreEqual(5, databases[0].MaxSizeGB);
                Assert.AreEqual("SQL_Latin1_General_CP1_CI_AS", databases[0].CollationName);

                databases = new Database[] { newDatabaseResult2.Single().BaseObject as Database };
                Assert.AreEqual(1, databases.Length, "Expecting one database");
                Assert.IsNotNull(databases[0],
                                 "Expecting a Database object.");
                Assert.AreEqual("testdbcert2", databases[0].Name);
                Assert.AreEqual("Business", databases[0].Edition);
                Assert.AreEqual(10, databases[0].MaxSizeGB);
                Assert.AreEqual("Japanese_CI_AS", databases[0].CollationName);

                // Validate Get-AzureSqlDatabase
                databases = getDatabaseResult.Single().BaseObject as Database[];
                Assert.AreEqual(3, databases.Length, "Expecting three databases");
                Assert.IsNotNull(databases[0], "Expecting a Database object.");
                Assert.IsNotNull(databases[1], "Expecting a Database object.");
                Assert.IsNotNull(databases[2], "Expecting a Database object.");
                Assert.AreEqual("master", databases[0].Name);
                Assert.AreEqual("Web", databases[0].Edition);
                Assert.AreEqual(5, databases[0].MaxSizeGB);
                Assert.AreEqual("SQL_Latin1_General_CP1_CI_AS", databases[0].CollationName);
                Assert.AreEqual(true, databases[0].IsSystemObject);
                Assert.AreEqual("testdbcert1", databases[1].Name);
                Assert.AreEqual("Web", databases[1].Edition);
                Assert.AreEqual(1, databases[1].MaxSizeGB);
                Assert.AreEqual("SQL_Latin1_General_CP1_CI_AS", databases[1].CollationName);
                Assert.AreEqual(false, databases[1].IsSystemObject);
                Assert.AreEqual("testdbcert2", databases[2].Name);
                Assert.AreEqual("Business", databases[2].Edition);
                Assert.AreEqual(10, databases[2].MaxSizeGB);
                Assert.AreEqual("Japanese_CI_AS", databases[2].CollationName);
                Assert.AreEqual(false, databases[2].IsSystemObject);

                databases = new Database[] { getSingleDatabaseResult.Single().BaseObject as Database };
                Assert.AreEqual(1, databases.Length, "Expecting one database");
                Assert.IsNotNull(databases[0],
                                 "Expecting a Database object.");
                Assert.AreEqual("testdbcert1", databases[0].Name);
                Assert.AreEqual("Web", databases[0].Edition);
                Assert.AreEqual(1, databases[0].MaxSizeGB);
                Assert.AreEqual("SQL_Latin1_General_CP1_CI_AS", databases[0].CollationName);

                // Validate Set-AzureSqlDatabase
                databases = new Database[] { setDatabaseNameResult.Single().BaseObject as Database };
                Assert.AreEqual(1, databases.Length, "Expecting one database");
                Assert.IsNotNull(databases[0],
                                 "Expecting a Database object.");
                Assert.AreEqual("testdbcert3", databases[0].Name);
                Assert.AreEqual("Web", databases[0].Edition);
                Assert.AreEqual(1, databases[0].MaxSizeGB);
                Assert.AreEqual("SQL_Latin1_General_CP1_CI_AS", databases[0].CollationName);

                databases = new Database[] { setDatabaseSizeResult.Single().BaseObject as Database };
                Assert.AreEqual(1, databases.Length, "Expecting one database");
                Assert.IsNotNull(databases[0],
                                 "Expecting a Database object.");
                Assert.AreEqual("testdbcert3", databases[0].Name);
                Assert.AreEqual("Web", databases[0].Edition);
                Assert.AreEqual(5, databases[0].MaxSizeGB);
                Assert.AreEqual("SQL_Latin1_General_CP1_CI_AS", databases[0].CollationName);

                // Validate Remove-AzureSqlDatabase
                databases = removeDatabaseResult.Single().BaseObject as Database[];
                Assert.AreEqual(1, databases.Length, "Expecting no databases");
                Assert.IsNotNull(databases[0], "Expecting a Database object.");
                Assert.AreEqual("master", databases[0].Name);
                Assert.AreEqual("Web", databases[0].Edition);
                Assert.AreEqual(5, databases[0].MaxSizeGB);
                Assert.AreEqual("SQL_Latin1_General_CP1_CI_AS", databases[0].CollationName);
            }
        }
Esempio n. 5
0
        public void AzureSqlDatabaseServerTests()
        {
            // This test uses the https endpoint, setup the certificates.
            MockHttpServer.SetupCertificates();

            SqlTestPsHost host = new SqlTestPsHost();
            SqlCustomPsHostUserInterface ui = host.UI as SqlCustomPsHostUserInterface;

            using (Runspace space = RunspaceFactory.CreateRunspace(host))
            {
                space.Open();

                using (System.Management.Automation.PowerShell powershell = System.Management.Automation.PowerShell.Create())
                {
                    powershell.Runspace = space;

                    // Setup the subscription used for the test
                    AzureSubscription subscription =
                        UnitTestHelper.SetupUnitTestSubscription(powershell);

                    // Create a new server
                    HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession(
                        "UnitTest.AzureSqlDatabaseServerTests");
                    ServerTestHelper.SetDefaultTestSessionSettings(testSession);
                    testSession.RequestValidator =
                        new Action <HttpMessage, HttpMessage.Request>(
                            (expected, actual) =>
                    {
                        Assert.AreEqual(expected.RequestInfo.Method, actual.Method);
                        Assert.IsTrue(
                            actual.UserAgent.Contains(ApiConstants.UserAgentHeaderValue),
                            "Missing proper UserAgent string.");
                    });

                    powershell.Runspace.SessionStateProxy.SetVariable("login", "mylogin");
                    powershell.Runspace.SessionStateProxy.SetVariable("password", "Pa$$w0rd!");
                    powershell.Runspace.SessionStateProxy.SetVariable("location", "East Asia");
                    Collection <PSObject> newServerResult = MockServerHelper.ExecuteWithMock(
                        testSession,
                        MockHttpServer.DefaultHttpsServerPrefixUri,
                        () =>
                    {
                        return(powershell.InvokeBatchScript(
                                   @"New-AzureSqlDatabaseServer" +
                                   @" -AdministratorLogin $login" +
                                   @" -AdministratorLoginPassword $password" +
                                   @" -Location $location"));
                    });

                    ui.PromptInputs = new PSObject[] { "mylogin", "Pa$$w0rd", "East Asia" };
                    Collection <PSObject> newServerResult2 = MockServerHelper.ExecuteWithMock(
                        testSession,
                        MockHttpServer.DefaultHttpsServerPrefixUri,
                        () =>
                    {
                        return(powershell.InvokeBatchScript(@"New-AzureSqlDatabaseServer"));
                    });
                    ui.PromptInputs = null;

                    Collection <PSObject> getServerResult = MockServerHelper.ExecuteWithMock(
                        testSession,
                        MockHttpServer.DefaultHttpsServerPrefixUri,
                        () =>
                    {
                        powershell.Runspace.SessionStateProxy.SetVariable("server", newServerResult);
                        return(powershell.InvokeBatchScript(
                                   @"Get-AzureSqlDatabaseServer $server.ServerName"));
                    });

                    Collection <PSObject> setServerResult = MockServerHelper.ExecuteWithMock(
                        testSession,
                        MockHttpServer.DefaultHttpsServerPrefixUri,
                        () =>
                    {
                        powershell.Runspace.SessionStateProxy.SetVariable("server", newServerResult);
                        powershell.Runspace.SessionStateProxy.SetVariable("password", "Pa$$w0rd2");
                        powershell.InvokeBatchScript(
                            @"$server | Set-AzureSqlDatabaseServer" +
                            @" -AdminPassword $password" +
                            @" -Force");
                        return(powershell.InvokeBatchScript(
                                   @"$server | Get-AzureSqlDatabaseServer"));
                    });

                    ui.PromptInputs = new PSObject[] { "Pa$$w0rd2" };
                    Collection <PSObject> setServerResult2 = MockServerHelper.ExecuteWithMock(
                        testSession,
                        MockHttpServer.DefaultHttpsServerPrefixUri,
                        () =>
                    {
                        powershell.Runspace.SessionStateProxy.SetVariable("server", newServerResult2);
                        powershell.InvokeBatchScript(@"$server | Set-AzureSqlDatabaseServer");
                        return(powershell.InvokeBatchScript(@"$server | Get-AzureSqlDatabaseServer"));
                    });
                    ui.PromptInputs = null;

                    Collection <PSObject> removeServerResult = MockServerHelper.ExecuteWithMock(
                        testSession,
                        MockHttpServer.DefaultHttpsServerPrefixUri,
                        () =>
                    {
                        powershell.Runspace.SessionStateProxy.SetVariable("server", newServerResult);
                        powershell.InvokeBatchScript(
                            @"$server | Remove-AzureSqlDatabaseServer" +
                            @" -Force");

                        return(powershell.InvokeBatchScript(
                                   @"Get-AzureSqlDatabaseServer"));
                    });

                    ui.PromptInputs = new PSObject[] { ((SqlDatabaseServerContext)newServerResult2[0].BaseObject).ServerName };
                    ui.PromptForChoiceInputIndex = 0;   //answer yes to delete database prompt
                    Collection <PSObject> removeServerResult2 = MockServerHelper.ExecuteWithMock(
                        testSession,
                        MockHttpServer.DefaultHttpsServerPrefixUri,
                        () =>
                    {
                        powershell.InvokeBatchScript(@"Remove-AzureSqlDatabaseServer");

                        return(powershell.InvokeBatchScript(
                                   @"Get-AzureSqlDatabaseServer"));
                    });
                    ui.PromptForChoiceInputIndex = -1;
                    ui.PromptInputs = null;

                    Assert.AreEqual(0, powershell.Streams.Error.Count, "Unexpected Errors during run!");
                    Assert.AreEqual(0, powershell.Streams.Warning.Count, "Unexpected Warnings during run!");

                    // Validate New-AzureSqlDatabaseServer results
                    SqlDatabaseServerContext server =
                        newServerResult.Single().BaseObject as SqlDatabaseServerContext;
                    Assert.IsNotNull(server, "Expecting a SqlDatabaseServerContext object");
                    VerifyServer(
                        server,
                        (string)powershell.Runspace.SessionStateProxy.GetVariable("login"),
                        (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"),
                        ServerVersion12,
                        "Ready");

                    // Validate Get-AzureSqlDatabaseServer results
                    server = getServerResult.Single().BaseObject as SqlDatabaseServerContext;
                    Assert.IsNotNull(server, "Expecting a SqlDatabaseServerContext object");
                    VerifyServer(
                        server,
                        (string)powershell.Runspace.SessionStateProxy.GetVariable("login"),
                        (string)powershell.Runspace.SessionStateProxy.GetVariable("location"),
                        ServerVersion12,
                        "Ready");

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

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

                    // Validate Remove-AzureSqlDatabaseServer results
                    Assert.IsFalse(
                        removeServerResult.Any((o) => o.GetVariableValue <string>("ServerName") == server.ServerName),
                        "Server should have been removed.");

                    Assert.IsFalse(
                        removeServerResult2.Any((o) => o.GetVariableValue <string>("ServerName") == server2.ServerName),
                        "Server 2 should have been removed.");

                    powershell.Streams.ClearStreams();
                }

                space.Close();
            }
        }
Esempio n. 6
0
 public void CleanupTest()
 {
     MockServerHelper.SaveDefaultSessionCollection();
 }