• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# AsyncExceptionManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中AsyncExceptionManager的典型用法代码示例。如果您正苦于以下问题:C# AsyncExceptionManager类的具体用法?C# AsyncExceptionManager怎么用?C# AsyncExceptionManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AsyncExceptionManager类属于命名空间,在下文中一共展示了AsyncExceptionManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: RecoverAzureSqlDatabaseWithDatabaseName

        public void RecoverAzureSqlDatabaseWithDatabaseName()
        {
            var testSession = MockServerHelper.DefaultSessionCollection.GetSession(
                "UnitTests.RecoverAzureSqlDatabaseWithDatabaseName");
            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.");
                    });

            using (var exceptionManager = new AsyncExceptionManager())
            {
                Collection<PSObject> operation;
                using (new MockHttpServer(
                    exceptionManager, MockHttpServer.DefaultHttpsServerPrefixUri, testSession))
                {
                    operation = powershell.InvokeBatchScript(
                        @"Start-AzureSqlDatabaseRecovery " +
                        @"-SourceServerName $serverName " +
                        @"-SourceDatabaseName testdb1 " +
                        @"-TargetDatabaseName testdb1-restored");
                }

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

                // Expecting one operation object
                Assert.AreEqual(1, operation.Count, "Expecting one operation object");

                Assert.IsInstanceOfType(
                    operation[0].BaseObject, typeof(RecoverDatabaseOperation),
                    "Expecting a RecoverDatabaseOperation object");

                var operationObject = (RecoverDatabaseOperation)operation[0].BaseObject;
                Guid operationId;
                Assert.IsTrue(
                    Guid.TryParse(operationObject.Id, out operationId),
                    "Expecting a operation ID that's a GUID");
                Assert.AreNotEqual(
                    Guid.Empty, operationId,
                    "Expecting an operation ID that's not an empty GUID");
                Assert.AreEqual(
                    operationObject.SourceDatabaseName, "testdb1",
                    "Source database name mismatch");
                Assert.AreEqual(
                    operationObject.TargetServerName, serverName,
                    "Target server name mismatch");
                Assert.AreEqual(
                    operationObject.TargetDatabaseName, "testdb1-restored",
                    "Target database name mismatch");
            }
        }
开发者ID:hovsepm,项目名称:azure-sdk-tools,代码行数:59,代码来源:RecoverDatabaseTests.cs


示例2: RecoverAzureSqlDatabaseWithDatabaseNameWithCertAuth

        public void RecoverAzureSqlDatabaseWithDatabaseNameWithCertAuth()
        {
            var testSession = MockServerHelper.DefaultSessionCollection.GetSession(
                "UnitTests.RecoverAzureSqlDatabaseWithDatabaseNameWithCertAuth");
            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.");
                        Assert.IsTrue(
                            UnitTestHelper.GetUnitTestClientCertificate().Equals(actual.Certificate),
                            "Expected correct client certificate");
                    });

            using (var exceptionManager = new AsyncExceptionManager())
            {
                Collection<PSObject> operation;
                using (new MockHttpServer(
                    exceptionManager, MockHttpServer.DefaultHttpsServerPrefixUri, testSession))
                {
                    operation = powershell.InvokeBatchScript(
                        @"Start-AzureSqlDatabaseRecovery " +
                        @"-TargetServerName $serverName " +
                        @"-SourceDatabaseName testdb1 " +
                        @"-TargetDatabaseName testdb1-restored");
                }

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

                // Expecting one operation object
                Assert.AreEqual(1, operation.Count, "Expecting one operation object");

                Assert.IsTrue(
                    operation[0].BaseObject is RecoverDatabaseOperation,
                    "Expecting a RecoverDatabaseOperation object");

                var operationObject = (RecoverDatabaseOperation)operation[0].BaseObject;
                Assert.IsTrue(
                    operationObject.RequestID != Guid.Empty,
                    "Expecting a non-empty operation ID");
                Assert.AreEqual(
                    operationObject.TargetDatabaseName, "testdb1-restored",
                    "Target database name mismatch");
            }
        }
开发者ID:EmmaZhu,项目名称:azure-sdk-tools,代码行数:52,代码来源:RecoverDatabaseTests.cs


示例3: MockHttpServer

 /// <summary>
 /// Initializes a new instance of the <see cref="MockHttpServer" /> class that record or
 /// playback responses for requests in a session.
 /// </summary>
 /// <param name="exceptionManager">
 /// The exception manager that captures all async exceptions.
 /// </param>
 /// <param name="baseUri">The server prefix to use.</param>
 /// <param name="session">The object that stores request/response information.</param>
 public MockHttpServer(
     AsyncExceptionManager exceptionManager,
     Uri baseUri,
     HttpSession session)
     : this(exceptionManager, baseUri)
 {
     this.stopListenerUri = new Uri(baseUri, Guid.NewGuid().ToString());
     this.listener = this.CreateListener(
         context => HandleMockRequest(
             context,
             this.baseUri,
             session),
         int.MaxValue);
 }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:23,代码来源:MockHttpServer.cs


示例4: CreateServerContextSqlAuth

        /// <summary>
        /// Common helper method for other tests to create a context.
        /// </summary>
        /// <param name="contextVariable">The variable name that will hold the new context.</param>
        public static void CreateServerContextSqlAuth(
            System.Management.Automation.PowerShell powershell,
            string contextVariable)
        {
            HttpSession testSession = DatabaseTestHelper.DefaultSessionCollection.GetSession(
                "UnitTest.Common.NewAzureSqlDatabaseServerContextWithSqlAuth");
            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 context with both ManageUrl and ServerName overriden
                        case 0:
                            // GetAccessToken call
                            DatabaseTestHelper.ValidateGetAccessTokenRequest(
                                expected.RequestInfo,
                                actual);
                            break;
                        case 1:
                            // Get server call
                            DatabaseTestHelper.ValidateHeadersForODataRequest(
                                expected.RequestInfo,
                                actual);
                            break;
                        case 2:
                            // $metadata call
                            Assert.IsTrue(
                                actual.RequestUri.AbsoluteUri.EndsWith("$metadata"),
                                "Incorrect Uri specified for $metadata");
                            DatabaseTestHelper.ValidateHeadersForServiceRequest(
                                expected.RequestInfo,
                                actual);
                            Assert.AreEqual(
                                expected.RequestInfo.Headers[DataServiceConstants.AccessTokenHeader],
                                actual.Headers[DataServiceConstants.AccessTokenHeader],
                                "AccessToken header does not match");
                            Assert.AreEqual(
                                expected.RequestInfo.Cookies[DataServiceConstants.AccessCookie],
                                actual.Cookies[DataServiceConstants.AccessCookie],
                                "AccessCookie does not match");
                            break;
                        default:
                            Assert.Fail("No more requests expected.");
                            break;
                    }
                });

            UnitTestHelper.ImportSqlDatabaseModule(powershell);
            UnitTestHelper.CreateTestCredential(powershell);

            Collection<PSObject> serverContext;
            using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
            {
                using (new MockHttpServer(
                    exceptionManager,
                    MockHttpServer.DefaultServerPrefixUri,
                    testSession))
                {
                    serverContext = powershell.InvokeBatchScript(
                        string.Format(
                            CultureInfo.InvariantCulture,
                            @"{1} = New-AzureSqlDatabaseServerContext " +
                            @"-ServerName testserver " +
                            @"-ManageUrl {0} " +
                            @"-Credential $credential",
                            MockHttpServer.DefaultServerPrefixUri.AbsoluteUri,
                            contextVariable),
                        contextVariable);
                }
            }

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

            PSObject contextPsObject = serverContext.Single();
            Assert.IsTrue(
                contextPsObject.BaseObject is ServerDataServiceSqlAuth,
                "Expecting a ServerDataServiceSqlAuth object");
        }
开发者ID:nicopeelen,项目名称:azure-sdk-tools,代码行数:88,代码来源:NewAzureSqlDatabaseServerContextTests.cs


示例5: NewAzureSqlDatabaseServerContextWithSqlAuthNegativeCases

        public void NewAzureSqlDatabaseServerContextWithSqlAuthNegativeCases()
        {
            HttpSession testSession = DatabaseTestHelper.DefaultSessionCollection.GetSession(
                "UnitTests.NewAzureSqlDatabaseServerContextWithSqlAuthNegativeCases");

            using (System.Management.Automation.PowerShell powershell =
                System.Management.Automation.PowerShell.Create())
            {
                UnitTestHelper.ImportSqlDatabaseModule(powershell);
                UnitTestHelper.CreateTestCredential(powershell);

                using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
                {
                    // Test warning when different $metadata is received.
                    Collection<PSObject> serverContext;
                    using (new MockHttpServer(
                        exceptionManager,
                        MockHttpServer.DefaultServerPrefixUri,
                        testSession))
                    {
                        serverContext = powershell.InvokeBatchScript(
                            string.Format(
                                CultureInfo.InvariantCulture,
                                @"$context = New-AzureSqlDatabaseServerContext " +
                                @"-ServerName testserver " +
                                @"-ManageUrl {0} " +
                                @"-Credential $credential",
                                MockHttpServer.DefaultServerPrefixUri.AbsoluteUri),
                            @"$context");
                    }

                    Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!");
                    Assert.AreEqual(1, powershell.Streams.Warning.Count, "Should have warning!");
                    Assert.AreEqual(
                        Resources.WarningModelOutOfDate,
                        powershell.Streams.Warning.First().Message);
                    powershell.Streams.ClearStreams();

                    PSObject contextPsObject = serverContext.Single();
                    Assert.IsTrue(
                        contextPsObject.BaseObject is ServerDataServiceSqlAuth,
                        "Expecting a ServerDataServiceSqlAuth object");

                    // Test error case
                    using (new MockHttpServer(
                        exceptionManager,
                        MockHttpServer.DefaultServerPrefixUri,
                        testSession))
                    {
                        powershell.InvokeBatchScript(
                            string.Format(
                                CultureInfo.InvariantCulture,
                                @"$context = New-AzureSqlDatabaseServerContext " +
                                @"-ServerName testserver " +
                                @"-ManageUrl {0} " +
                                @"-Credential $credential",
                                MockHttpServer.DefaultServerPrefixUri.AbsoluteUri),
                            @"$context");
                    }

                    Assert.AreEqual(1, powershell.Streams.Error.Count, "Should have errors!");
                    Assert.AreEqual(2, powershell.Streams.Warning.Count, "Should have warning!");
                    Assert.AreEqual(
                        "Test error message",
                        powershell.Streams.Error.First().Exception.Message);
                    Assert.IsTrue(
                        powershell.Streams.Warning.Any(
                            (w) => w.Message.StartsWith("Client Session Id:")),
                        "Client session Id not written to warning");
                    Assert.IsTrue(
                        powershell.Streams.Warning.Any(
                            (w) => w.Message.StartsWith("Client Request Id:")),
                        "Client request Id not written to warning");
                    powershell.Streams.ClearStreams();
                }
            }
        }
开发者ID:nicopeelen,项目名称:azure-sdk-tools,代码行数:77,代码来源:NewAzureSqlDatabaseServerContextTests.cs


示例6: NewAzureSqlDatabaseServerContextWithSqlAuthNegativeCases

        public void NewAzureSqlDatabaseServerContextWithSqlAuthNegativeCases()
        {
            HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession(
                "UnitTests.NewAzureSqlDatabaseServerContextWithSqlAuthNegativeCases");

            using (System.Management.Automation.PowerShell powershell =
                System.Management.Automation.PowerShell.Create())
            {
                UnitTestHelper.ImportAzureModule(powershell);
                UnitTestHelper.CreateTestCredential(powershell);

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

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

                    // Test warning when different $metadata is received.
                    Collection<PSObject> serverContext;
                    using (new MockHttpServer(
                        exceptionManager,
                        MockHttpServer.DefaultServerPrefixUri,
                        testSession))
                    {
                        serverContext = powershell.InvokeBatchScript(
                            string.Format(
                                CultureInfo.InvariantCulture,
                                @"$context = New-AzureSqlDatabaseServerContext " +
                                @"-ServerName $servername " +
                                @"-ManageUrl {0} " +
                                @"-Credential $credential",
                                MockHttpServer.DefaultServerPrefixUri.AbsoluteUri),
                            @"$context");
                    }

                    Assert.AreEqual(1, powershell.Streams.Error.Count, "Errors during run!");
                    Assert.AreEqual(2, powershell.Streams.Warning.Count, "Should have warning!");
                    powershell.Streams.ClearStreams();

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

                    // Test error case
                    using (new MockHttpServer(
                        exceptionManager,
                        MockHttpServer.DefaultServerPrefixUri,
                        testSession))
                    {
                        powershell.InvokeBatchScript(
                            string.Format(
                                CultureInfo.InvariantCulture,
                                @"$context = New-AzureSqlDatabaseServerContext " +
                                @"-ServerName $servername " +
                                @"-ManageUrl {0} " +
                                @"-Credential $credential",
                                MockHttpServer.DefaultServerPrefixUri.AbsoluteUri),
                            @"$context");
                    }

                    Assert.AreEqual(1, powershell.Streams.Error.Count, "Should have errors!");
                    Assert.AreEqual(2, powershell.Streams.Warning.Count, "Should have warning!");
                    Assert.AreEqual(
                        "Test error message",
                        powershell.Streams.Error.First().Exception.Message);
                    Assert.IsTrue(
                        powershell.Streams.Warning.Any(
                            (w) => w.Message.StartsWith("Client Session Id:")),
                        "Client session Id not written to warning");
                    Assert.IsTrue(
                        powershell.Streams.Warning.Any(
                            (w) => w.Message.StartsWith("Client Request Id:")),
                        "Client request Id not written to warning");
                    powershell.Streams.ClearStreams();
                }
            }
        }
开发者ID:rohmano,项目名称:azure-powershell,代码行数:81,代码来源:NewAzureSqlDatabaseServerContextTests.cs


示例7: GetAzureSqlDatabaseWithSqlAuthNonExistentDb

        public void GetAzureSqlDatabaseWithSqlAuthNonExistentDb()
        {
            using (System.Management.Automation.PowerShell powershell =
                System.Management.Automation.PowerShell.Create())
            {
                // Create a context
                NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth(
                    powershell,
                    "$context");

                // Query a non-existent test database
                HttpSession testSession = DatabaseTestHelper.DefaultSessionCollection.GetSession(
                    "UnitTests.GetAzureSqlDatabaseWithSqlAuthNonExistentDb");
                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: Get database requests
                            case 0:
                            case 1:
                            case 2:
                                DatabaseTestHelper.ValidateHeadersForODataRequest(
                                    expected.RequestInfo,
                                    actual);
                                break;
                            default:
                                Assert.Fail("No more requests expected.");
                                break;
                        }
                    });

                using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
                {
                    using (new MockHttpServer(
                        exceptionManager,
                        MockHttpServer.DefaultServerPrefixUri,
                        testSession))
                    {
                        powershell.InvokeBatchScript(
                            @"Get-AzureSqlDatabase " +
                            @"-Context $context " +
                            @"-DatabaseName testdb3");
                    }
                }

                Assert.AreEqual(1, powershell.Streams.Error.Count, "Expecting errors");
                Assert.AreEqual(2, powershell.Streams.Warning.Count, "Expecting tracing IDs");
                Assert.AreEqual(
                    "Database 'testserver.testdb3' not found.",
                    powershell.Streams.Error.First().Exception.Message,
                    "Unexpected error message");
                Assert.IsTrue(
                    powershell.Streams.Warning.Any(w => w.Message.StartsWith("Client Session Id")),
                    "Expecting Client Session Id");
                Assert.IsTrue(
                    powershell.Streams.Warning.Any(w => w.Message.StartsWith("Client Request Id")),
                    "Expecting Client Request Id");
                powershell.Streams.ClearStreams();
            }
        }
开发者ID:huangpf,项目名称:azure-sdk-tools,代码行数:65,代码来源:GetAzureSqlDatabaseTests.cs


示例8: StartDatabaseContinuousCopyWithSqlAuth

        /// <summary>
        /// Create continuous copy of testdb1 to partnersrv.
        /// </summary>
        /// <param name="powershell">The powershell instance containing the context.</param>
        /// <param name="contextVariable">The variable name that holds the server context.</param>
        /// <param name="copyVariable">The variable name that holds the copy object.</param>
        /// <param name="databaseName">The name of the database to copy.</param>
        public static void StartDatabaseContinuousCopyWithSqlAuth(
            System.Management.Automation.PowerShell powershell,
            string contextVariable,
            string copyVariable,
            string databaseName)
        {
            HttpSession testSession = DatabaseTestHelper.DefaultSessionCollection.GetSession(
                "UnitTest.Common.StartAzureSqlDatabaseContinuousCopyWithSqlAuth." + databaseName);
            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-1: Start database copy request
                        case 0:
                        case 1:
                            DatabaseTestHelper.ValidateHeadersForODataRequest(
                                expected.RequestInfo,
                                actual);
                            break;
                        default:
                            Assert.Fail("No more requests expected.");
                            break;
                    }
                });

            using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
            {
                Collection<PSObject> databaseCopy;
                using (new MockHttpServer(
                    exceptionManager,
                    MockHttpServer.DefaultServerPrefixUri,
                    testSession))
                {
                    databaseCopy = powershell.InvokeBatchScript(
                        string.Format(
                            CultureInfo.InvariantCulture,
                            @"{0} = Start-AzureSqlDatabaseCopy " +
                            @"-Context $context " +
                            @"-DatabaseName {1} " +
                            @"-PartnerServer partnersrv " +
                            @"-ContinuousCopy",
                            copyVariable,
                            databaseName),
                        copyVariable);
                }

                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(
                    databaseCopy.Single().BaseObject is Services.Server.DatabaseCopy,
                    "Expecting a Database Copy object");
                Services.Server.DatabaseCopy databaseCopyObj =
                    (Services.Server.DatabaseCopy)databaseCopy.Single().BaseObject;
                Assert.AreEqual(
                    "testserver",
                    databaseCopyObj.SourceServerName,
                    "Unexpected source server name");
                Assert.AreEqual(
                    databaseName,
                    databaseCopyObj.SourceDatabaseName,
                    "Unexpected source database name");
                Assert.AreEqual(
                    "partnersrv",
                    databaseCopyObj.DestinationServerName,
                    "Unexpected destination server name");
                Assert.AreEqual(
                    databaseName,
                    databaseCopyObj.DestinationDatabaseName,
                    "Unexpected destination database name");
                Assert.IsTrue(
                    databaseCopyObj.IsContinuous,
                    "Expected copy to be continuous");
            }
        }
开发者ID:B-Rich,项目名称:azure-sdk-tools,代码行数:88,代码来源:StartAzureSqlDatabaseCopyTests.cs


示例9: CreateWebException

        /// <summary>
        /// Create a <see cref="WebException"/> with the specified content.
        /// </summary>
        /// <param name="status">The status code to use in the exception.</param>
        /// <param name="content">A <see cref="MemoryStream"/> of the exception content.</param>
        /// <param name="contextHandler">An action that adds extra info to the response.</param>
        /// <returns>An <see cref="WebException"/> with the specified content.</returns>
        public static WebException CreateWebException(
            HttpStatusCode status,
            MemoryStream content,
            Action<HttpListenerContext> contextHandler)
        {
            HttpListener server = null;
            try
            {
                // Create a mock server that always returns the response code and exception stream
                // specified in the parameter.
                using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
                {
                    MockHttpServer mockServer = new MockHttpServer(
                        exceptionManager,
                        MockHttpServer.DefaultServerPrefixUri);
                    server = mockServer.CreateListener(
                        (context) =>
                        {
                            contextHandler(context);
                            context.Response.StatusCode = (int)status;
                            content.Position = 0;
                            content.CopyTo(context.Response.OutputStream);
                            context.Response.Close();
                        },
                        1);
                }

                WebClient client = new WebClient();
                try
                {
                    client.OpenRead(new Uri(DefaultServerPrefixUri, "exception.htm"));
                }
                catch (WebException ex)
                {
                    return ex;
                }
            }
            finally
            {
                server.Stop();
            }

            return null;
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:51,代码来源:MockHttpServer.cs


示例10: GetRestorableDroppedDatabaseWithCertAuthNonExistentDb

        public void GetRestorableDroppedDatabaseWithCertAuthNonExistentDb()
        {
            var testSession = MockServerHelper.DefaultSessionCollection.GetSession(
                "UnitTest.GetRestorableDroppedDatabaseWithCertAuthNonExistentDb");
            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.");
                    });

            using (var exceptionManager = new AsyncExceptionManager())
            {
                using (new MockHttpServer(
                    exceptionManager, MockHttpServer.DefaultHttpsServerPrefixUri, testSession))
                {
                    powershell.InvokeBatchScript(
                        @"Get-AzureSqlDatabase -RestorableDropped " +
                        @"-ServerName $serverName " +
                        @"-DatabaseName testdbnonexistent " +
                        @"-DatabaseDeletionDate '10/01/2013 12:00:00 AM'");
                }

                Assert.AreEqual(
                    1, powershell.Streams.Error.Count,
                    "Expecting errors");
                Assert.AreEqual(
                    1, powershell.Streams.Warning.Count,
                    "Expecting tracing IDs");
                Assert.AreEqual(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "Resource with the name '{0}' does not exist. To continue, specify a valid resource name.",
                        "testdbnonexistent,2013-10-01T00:00:00.000Z"),
                    powershell.Streams.Error.First().Exception.Message,
                    "Unexpected error message");
                Assert.IsTrue(
                    powershell.Streams.Warning[0].Message.StartsWith("Request Id"),
                    "Expecting Client Request Id");
            }
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:46,代码来源:GetRestorableDroppedDatabaseCertAuthTests.cs


示例11: GetAzureSqlDatabaseOperationWithSqlAuth

        public void GetAzureSqlDatabaseOperationWithSqlAuth()
        {
            using (System.Management.Automation.PowerShell powershell =
                System.Management.Automation.PowerShell.Create())
            {
                NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth(
                    powershell,
                    "$context");
                HttpSession testSession = MockServerHelper.DefaultSessionCollection.GetSession(
                    "UnitTest.Common.GetAzureSqlDatabaseOperationWithSqlAuth");
                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-7: Create and Query $testdb                                                                
                                case 0:
                                case 1:
                                case 2:
                                case 3:
                                case 4:
                                case 5:
                                case 6:
                                case 7:
                                // Request 8: Delete $testdb
                                case 8:
                                // Request 9-11: Query Database Operations                                
                                case 9:
                                case 10:
                                case 11:                                
                                    DatabaseTestHelper.ValidateHeadersForODataRequest(
                                    expected.RequestInfo,
                                    actual);
                                    break;
                                default:
                                    Assert.Fail("No more requests expected.");
                                    break;
                            }
                        });

                using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
                {
                    // There is a known issue about the Get-AzureSqlDatabaseOperation that it returns all
                    // operations which has the required database name no matter it's been deleted and recreated.
                    // So when run it against the mock session, please use the hard coded testsDBName.
                    // Run against onebox, please use the one with NewGuid(). 
                    // This unit test should be updated once that behavior get changed which was already been 
                    // created as a task.

                    // string testsDBName = string.Format("getAzureSqlDatabaseOperationTestsDB_{0}",
                    //     Guid.NewGuid().ToString());
                    string testsDBName = "getAzureSqlDatabaseOperationTestsDB_08ebd7c9-bfb7-426a-9e2f-9921999567e1";
                    Collection<PSObject> database, operationsByName, operationsByDatabase, operationsById;
                    using (new MockHttpServer(
                            exceptionManager,
                            MockHttpServer.DefaultServerPrefixUri,
                            testSession))
                    {
                        database = powershell.InvokeBatchScript(
                            string.Format(
                                @"$testdb = New-AzureSqlDatabase " +
                                @"-Context $context " +
                                @"-DatabaseName {0} " +
                                @"-Force", testsDBName),
                            @"$testdb");

                        powershell.InvokeBatchScript(
                            string.Format(
                                @"Remove-AzureSqlDatabase " +
                                @"-Context $context " +
                                @"-DatabaseName {0} " +
                                @"-Force", testsDBName));

                        operationsByName = powershell.InvokeBatchScript(
                            string.Format(
                                @"$operations = Get-AzureSqlDatabaseOperation " +
                                @"-ConnectionContext $context " +
                                @"-DatabaseName {0}",
                                testsDBName),
                            @"$operations");

                        operationsByDatabase = powershell.InvokeBatchScript(
                            @"Get-AzureSqlDatabaseOperation " +
                            @"-ConnectionContext $context " +
                            @"-Database $testdb");

                        operationsById = powershell.InvokeBatchScript(
                            @"Get-AzureSqlDatabaseOperation " +
                            @"-ConnectionContext $context " +
                            @"-OperationGuid $operations[0].Id"
                            );
                    }

                    Assert.AreEqual(0, powershell.Streams.Error.Count, "Errors during run!");
                    Assert.AreEqual(0, powershell.Streams.Warning.Count, "Warnings during run!");
                    powershell.Streams.ClearStreams();
//.........这里部分代码省略.........
开发者ID:hovsepm,项目名称:azure-sdk-tools,代码行数:101,代码来源:GetAzureSqlDatabaseOperationTests.cs


示例12: SetAzureSqlDatabaseNameWithSqlAuth

        public void SetAzureSqlDatabaseNameWithSqlAuth()
        {
            using (System.Management.Automation.PowerShell powershell =
                System.Management.Automation.PowerShell.Create())
            {
                // Create a context
                NewAzureSqlDatabaseServerContextTests.CreateServerContextSqlAuth(
                    powershell,
                    "$context");
                // Create 2 test databases
                NewAzureSqlDatabaseTests.CreateTestDatabasesWithSqlAuth(
                    powershell,
                    "$context");

                HttpSession testSession = DatabaseTestHelper.DefaultSessionCollection.GetSession(
                    "UnitTests.SetAzureSqlDatabaseNameWithSqlAuth");
                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 1-2: Set testdb1 with new name of testdb2
                            case 0:
                            case 1:
                            // Request 3: Get updated testdb2
                            case 2:
                                DatabaseTestHelper.ValidateHeadersForODataRequest(
                                    expected.RequestInfo,
                                    actual);
                                break;
                            default:
                                Assert.Fail("No more requests expected.");
                                break;
                        }
                    });

                using (AsyncExceptionManager exceptionManager = new AsyncExceptionManager())
                {
                    // Create context with both ManageUrl and ServerName overriden
                    Collection<PSObject> database;
                    using (new MockHttpServer(
                        exceptionManager,
                        MockHttpServer.DefaultServerPrefixUri,
                        testSession))
                    {
                        database = powershell.InvokeBatchScript(
                           @"Set-AzureSqlDatabase " +
                           @"-Context $context " +
                           @"-DatabaseName testdb1 " +
                           @"-NewName testdb3 " +
                           @"-Force " +
                           @"-PassThru");
                    }

                    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(
                        database.Single().BaseObject is Services.Server.Database,
                        "Expecting a Database object");
                    Services.Server.Database databaseObj =
                        (Services.Server.Database)database.Single().BaseObject;
                    Assert.AreEqual("testdb3", databaseObj.Name, "Expected db name to be testdb3");
                    Assert.AreEqual("Web", databaseObj.Edition, "Expected edition to be Web");
                    Assert.AreEqual(1, databaseObj.MaxSizeGB, "Expected max size to be 1 GB");
                }
            }
        }
开发者ID:nicopeelen,项目名称:azure-sdk-tools,代码行数:73,代码来源:SetAzureSqlDatabaseTests.cs


示例13: RestoreAzureSqlDatabaseWithRestorableDroppedDatabaseObjectWithCertAuth

        public void RestoreAzureSqlDatabaseWithRestorableDroppedDatabaseObjectWithCertAuth()
        {
            DropTestDatabases();

            var deletionDate = DateTime.UtcNow;
            var restorePoint = deletionDate - TimeSpan.FromMinutes(1);

            var testSession = MockServerHelper.DefaultSessionCollection.GetSession(
                "UnitTests.RestoreAzureSqlDatabaseWithRestorableDroppedDatabaseObjectWithCertAuth");
            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.");
                    });

            using (var exceptionManager = new AsyncExceptionManager())
            {
                Collection<PSObject> droppedDatabase, operation;
                using (new MockHttpServer(
                    exceptionManager, MockHttpServer.DefaultHttpsServerPrefixUri, testSession))
                {
                    droppedDatabase = powershell.InvokeBatchScript(
                        @"$database = $(Get-AzureSqlDatabase -ServerName $serverName -RestorableDropped)[0];" +
                        @"$database");
                }

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

                var droppedDatabaseObject = (RestorableDroppedDatabase)droppedDatabase[0].BaseObject;

                using (new MockHttpServer(
                    exceptionManager, MockHttpServer.DefaultHttpsServerPrefixUri, testSession))
                {
                    operation = powershell.InvokeBatchScript(
                        @"$database | Start-AzureSqlDatabaseRestore " +
                        @"-TargetDatabaseName testdb1-restored");
                }

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

                // Expecting one operation object
                Assert.AreEqual(1, operation.Count, "Expecting one operation object");

                Assert.IsTrue(
                    operation[0].BaseObject is RestoreDatabaseOperation,
                    "Expecting a RestoreDatabaseOperation object");

                var operationObject = (RestoreDatabaseOperat 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# AsyncLazy类代码示例发布时间:2022-05-24
下一篇:
C# AsyncDelegate类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap