public void CreatePremiumDatabasesWithSqlAuth()
        {
            using (System.Management.Automation.PowerShell powershell =
                       System.Management.Automation.PowerShell.Create())
            {
                NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth(
                    powershell,
                    "$context");
                HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession(
                    "UnitTest.Common.CreatePremiumDatabasesWithSqlAuth");
                DatabaseTestHelper.SetDefaultTestSessionSettings(testSession);
                testSession.RequestValidator =
                    new Action <HttpMessage, HttpMessage.Request>(
                        (expected, actual) =>
                {
                    Assert.AreEqual(expected.RequestInfo.Method, actual.Method);
                    Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent);
                });

                using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
                {
                    Collection <PSObject> premiumDB_P1, PremiumDB_P2;
                    using (new MockHttpServer(
                               exceptionManager,
                               MockHttpServer.DefaultServerPrefixUri,
                               testSession))
                    {
                        powershell.InvokeBatchScript(
                            @"$P1 = Get-AzureSqlDatabaseServiceObjective" +
                            @" -Context $context" +
                            @" -ServiceObjectiveName ""P1""");

                        powershell.InvokeBatchScript(
                            @"$P2 = Get-AzureSqlDatabaseServiceObjective " +
                            @"-Context $context" +
                            @" -ServiceObjectiveName ""P2""");

                        premiumDB_P1 = powershell.InvokeBatchScript(
                            @"$premiumDB_P1 = New-AzureSqlDatabase " +
                            @"-Context $context " +
                            @"-DatabaseName NewAzureSqlPremiumDatabaseTests_P1 " +
                            @"-Edition Premium " +
                            @"-ServiceObjective $P1 ");
                        premiumDB_P1 = powershell.InvokeBatchScript("$PremiumDB_P1");

                        powershell.InvokeBatchScript(
                            @"$PremiumDB_P2 = New-AzureSqlDatabase " +
                            @"-Context $context " +
                            @"-DatabaseName NewAzureSqlPremiumDatabaseTests_P2 " +
                            @"-Collation Japanese_CI_AS " +
                            @"-Edition Premium " +
                            @"-ServiceObjective $P2 " +
                            @"-MaxSizeGB 10 " +
                            @"-Force");
                        PremiumDB_P2 = powershell.InvokeBatchScript("$PremiumDB_P2");
                    }

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

                    Assert.IsTrue(
                        premiumDB_P1.Single().BaseObject is Services.Server.Database,
                        "Expecting a Database object");
                    Services.Server.Database databaseP1 =
                        (Services.Server.Database)premiumDB_P1.Single().BaseObject;
                    Assert.AreEqual("NewAzureSqlPremiumDatabaseTests_P1", databaseP1.Name, "Expected db name to be NewAzureSqlPremiumDatabaseTests_P1");

                    Assert.IsTrue(
                        PremiumDB_P2.Single().BaseObject is Services.Server.Database,
                        "Expecting a Database object");
                    Services.Server.Database databaseP2 =
                        (Services.Server.Database)PremiumDB_P2.Single().BaseObject;
                    Assert.AreEqual("NewAzureSqlPremiumDatabaseTests_P2", databaseP2.Name, "Expected db name to be NewAzureSqlPremiumDatabaseTests_P2");

                    Assert.AreEqual(
                        "Japanese_CI_AS",
                        databaseP2.CollationName,
                        "Expected collation to be Japanese_CI_AS");
                    Assert.AreEqual("Premium", databaseP2.Edition, "Expected edition to be Premium");
                    Assert.AreEqual(10, databaseP2.MaxSizeGB, "Expected max size to be 10 GB");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Create $testdb1 and $testdb2 on the given context.
        /// </summary>
        /// <param name="powershell">The powershell instance containing the context.</param>
        /// <param name="contextVariable">The variable name that holds the server context.</param>
        public static void CreateTestDatabasesWithSqlAuth(
            System.Management.Automation.PowerShell powershell,
            string contextVariable)
        {
            HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession(
                "UnitTest.Common.CreateTestDatabasesWithSqlAuth");

            DatabaseTestHelper.SetDefaultTestSessionSettings(testSession);
            testSession.RequestValidator =
                new Action <HttpMessage, HttpMessage.Request>(
                    (expected, actual) =>
            {
                Assert.AreEqual(expected.RequestInfo.Method, actual.Method);
                Assert.AreEqual(expected.RequestInfo.UserAgent, actual.UserAgent);
                switch (expected.Index)
                {
                // Request 0-2: Create testdb1
                // Request 3-5: Create testdb2
                case 0:
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                    DatabaseTestHelper.ValidateHeadersForODataRequest(
                        expected.RequestInfo,
                        actual);
                    break;

                default:
                    Assert.Fail("No more requests expected.");
                    break;
                }
            });

            using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
            {
                Collection <PSObject> database1, database2;
                using (new MockHttpServer(
                           exceptionManager,
                           MockHttpServer.DefaultServerPrefixUri,
                           testSession))
                {
                    database1 = powershell.InvokeBatchScript(
                        @"$testdb1 = New-AzureSqlDatabase " +
                        @"-Context $context " +
                        @"-DatabaseName testdb1 " +
                        @"-Force",
                        @"$testdb1");
                    database2 = powershell.InvokeBatchScript(
                        @"$testdb2 = New-AzureSqlDatabase " +
                        @"-Context $context " +
                        @"-DatabaseName testdb2 " +
                        @"-Collation Japanese_CI_AS " +
                        @"-Edition Web " +
                        @"-MaxSizeGB 5 " +
                        @"-Force",
                        @"$testdb2");
                }

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

                Assert.IsTrue(
                    database1.Single().BaseObject is Services.Server.Database,
                    "Expecting a Database object");
                Services.Server.Database database1Obj =
                    (Services.Server.Database)database1.Single().BaseObject;
                Assert.AreEqual("testdb1", database1Obj.Name, "Expected db name to be testdb1");

                Assert.IsTrue(
                    database2.Single().BaseObject is Services.Server.Database,
                    "Expecting a Database object");
                Services.Server.Database database2Obj =
                    (Services.Server.Database)database2.Single().BaseObject;
                Assert.AreEqual("testdb2", database2Obj.Name, "Expected db name to be testdb2");
                Assert.AreEqual(
                    "Japanese_CI_AS",
                    database2Obj.CollationName,
                    "Expected collation to be Japanese_CI_AS");
                Assert.AreEqual("Web", database2Obj.Edition, "Expected edition to be Web");
                Assert.AreEqual(5, database2Obj.MaxSizeGB, "Expected max size to be 5 GB");
            }
        }