Exemple #1
0
 /// <summary>
 /// Set the default mock session settings to modify request and responses.
 /// </summary>
 /// <param name="testSession"></param>
 public static void SetDefaultTestSessionSettings(HttpSession testSession)
 {
     testSession.ServiceBaseUri = DatabaseTestHelper.CommonServiceBaseUri;
     testSession.SessionProperties["Servername"] = "testserver";
     testSession.SessionProperties["Username"]   = "******";
     testSession.SessionProperties["Password"]   = "******";
     testSession.ResponseModifier =
         new Action <HttpMessage>(
             (message) =>
     {
         DatabaseTestHelper.FixODataResponseUri(
             message.ResponseInfo,
             testSession.ServiceBaseUri,
             MockHttpServer.DefaultServerPrefixUri);
     });
     testSession.RequestModifier =
         new Action <HttpMessage.Request>(
             (request) =>
     {
         DatabaseTestHelper.FixODataRequestPayload(
             request,
             testSession.ServiceBaseUri,
             MockHttpServer.DefaultServerPrefixUri);
     });
 }
Exemple #2
0
        public void GetAzureSqlDatabaseServiceObjectiveWithSqlAuth()
        {
            using (System.Management.Automation.PowerShell powershell =
                       System.Management.Automation.PowerShell.Create())
            {
                // Create a context
                NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth(
                    powershell,
                    "$context");

                HttpSession testSession = DatabaseTestHelper.DefaultSessionCollection.GetSession(
                    "UnitTests.GetAzureSqlServiceObjectiveWithSqlAuth");
                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-6: Retrieving all (6) ServiceObjectives and DimensionSettings
                    case 0:
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                    case 5:
                    case 6:
                    // Request 7-8: Retrieving Reserved P1 ServiceObjectives and DimensionSettings
                    case 7:
                    case 8:
                        DatabaseTestHelper.ValidateHeadersForODataRequest(
                            expected.RequestInfo,
                            actual);
                        break;

                    default:
                        Assert.Fail("No more requests expected.");
                        break;
                    }
                });
                testSession.ResponseModifier =
                    new Action <HttpMessage>(
                        (message) =>
                {
                    DatabaseTestHelper.FixODataResponseUri(
                        message.ResponseInfo,
                        testSession.ServiceBaseUri,
                        MockHttpServer.DefaultServerPrefixUri);
                });

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

                        objective1 = powershell.InvokeBatchScript(
                            @"Get-AzureSqlDatabaseServiceObjective " +
                            @"-Context $context " +
                            @"-ServiceObjectiveName ""Reserved P1""");
                    }

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

                    Assert.AreEqual(6, objectives.Count, "Expecting 6 Objective objects");

                    Assert.IsTrue(
                        objective1.Single().BaseObject is Services.Server.ServiceObjective,
                        "Expecting a ServiceObjective object");
                    Services.Server.ServiceObjective objective1Obj =
                        (Services.Server.ServiceObjective)objective1.Single().BaseObject;
                    Assert.AreEqual("Reserved P1", objective1Obj.Name, "Expected objective name to be 'Reserved P1'");
                }
            }
        }