本文整理汇总了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);
}
示例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());
}
示例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());
}
示例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());
}