当前位置: 首页>>代码示例>>C#>>正文


C# Mock.Abort方法代码示例

本文整理汇总了C#中Mock.Abort方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.Abort方法的具体用法?C# Mock.Abort怎么用?C# Mock.Abort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mock的用法示例。


在下文中一共展示了Mock.Abort方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AbortValidatesArguments

        public void AbortValidatesArguments()
        {
            var httpClient = Mock.Of<IHttpClient>();
            var abortHandler = new TransportAbortHandler(httpClient, "fakeTransport");

            var transport =
                new Mock<ClientTransportBase>(httpClient, "fakeTransport", Mock.Of<TransportHelper>(), abortHandler)
                {
                    CallBase = true
                }.Object;

            Assert.Equal("connection",
                Assert.Throws<ArgumentNullException>(() => transport.Abort(null, new TimeSpan(0, 0, 5), "connectionData")).ParamName);
        }
开发者ID:kietnha,项目名称:SignalR,代码行数:14,代码来源:ClientTransportBaseFacts.cs

示例2: AbortRequestNotSentIfConnectionTokenNull

        public void AbortRequestNotSentIfConnectionTokenNull()
        {
            var mockClient = new Mock<IHttpClient>();
            var abortHandler = new TransportAbortHandler(mockClient.Object, "fakeTransport");
            var transport =
                new Mock<ClientTransportBase>(mockClient.Object, "fakeTransport", Mock.Of<TransportHelper>(), abortHandler)
                {
                    CallBase = true
                }.Object;

            transport.Abort(Mock.Of<IConnection>(), new TimeSpan(0, 0, 5), "connectionData");

            mockClient.Verify(
                m => m.Post(It.IsAny<string>(), It.IsAny<Action<IRequest>>(), It.IsAny<IDictionary<string, string>>(), It.IsAny<bool>()),
                Times.Never());
        }
开发者ID:kietnha,项目名称:SignalR,代码行数:16,代码来源:ClientTransportBaseFacts.cs

示例3: FailuresWhileSendingAbortRequestsAreLoggedAndSwallowed

        public void FailuresWhileSendingAbortRequestsAreLoggedAndSwallowed()
        {
            const string exceptionMessage = "Abort request failed";

            var tcs = new TaskCompletionSource<IResponse>();
            tcs.SetException(new InvalidOperationException(exceptionMessage));

            var traceStringBuilder = new StringBuilder();
            var connection = new Connection("http://fake.url/")
            {
                ConnectionToken = "connectionToken",
                TraceWriter = new StringWriter(traceStringBuilder)
            };

            var mockClient = new Mock<IHttpClient>();
            mockClient
                .Setup(m => m.Post(It.IsAny<string>(), It.IsAny<Action<IRequest>>(), It.IsAny<IDictionary<string, string>>(), It.IsAny<bool>()))
                .Returns(tcs.Task);

            var abortHandler = new TransportAbortHandler(mockClient.Object, "fakeTransport");

            var transport =
                new Mock<ClientTransportBase>(mockClient.Object, "fakeTransport", Mock.Of<TransportHelper>(), abortHandler)
                {
                    CallBase = true
                }.Object;

            transport.Abort(connection, new TimeSpan(0, 0, 5), "connectionData");

            mockClient.Verify(
                m => m.Post(It.Is<string>(url => url.StartsWith("http://fake.url/abort?")), It.IsAny<Action<IRequest>>(),
                        It.IsAny<IDictionary<string, string>>(), false),
                Times.Once());

            Assert.Contains(exceptionMessage, traceStringBuilder.ToString());
        }
开发者ID:kietnha,项目名称:SignalR,代码行数:36,代码来源:ClientTransportBaseFacts.cs

示例4: AbortSendsAbortRequestOnlyOnce

        public void AbortSendsAbortRequestOnlyOnce()
        {
            var connection = new Connection("http://fake.url/") { ConnectionToken = "connectionToken" };

            var mockClient = new Mock<IHttpClient>();

            var abortHandler = new TransportAbortHandler(mockClient.Object, "fakeTransport");

            mockClient
                .Setup(m => m.Post(It.IsAny<string>(), It.IsAny<Action<IRequest>>(), It.IsAny<IDictionary<string, string>>(), It.IsAny<bool>()))
                .Returns(() =>
                {
                    abortHandler.CompleteAbort();
                    return Task.FromResult((IResponse)null);
                });

            var transport =
                new Mock<ClientTransportBase>(mockClient.Object, "fakeTransport", Mock.Of<TransportHelper>(), abortHandler)
                {
                    CallBase = true
                }.Object;

            transport.Abort(connection, new TimeSpan(0, 0, 5), "connectionData");

            transport.Abort(connection, new TimeSpan(0, 0, 5), "connectionData");

            mockClient.Verify(
                m => m.Post(It.Is<string>(url => url.StartsWith("http://fake.url/abort?")), It.IsAny<Action<IRequest>>(),
                        It.IsAny<IDictionary<string, string>>(), false),
                Times.Once());
        }
开发者ID:kietnha,项目名称:SignalR,代码行数:31,代码来源:ClientTransportBaseFacts.cs


注:本文中的Mock.Abort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。