本文整理汇总了C#中FakeConnection.GetInvocations方法的典型用法代码示例。如果您正苦于以下问题:C# FakeConnection.GetInvocations方法的具体用法?C# FakeConnection.GetInvocations怎么用?C# FakeConnection.GetInvocations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FakeConnection
的用法示例。
在下文中一共展示了FakeConnection.GetInvocations方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartCreatesAndOpensWebSocket
public async Task StartCreatesAndOpensWebSocket()
{
var fakeWebSocketTransport = new FakeWebSocketTransport();
fakeWebSocketTransport.Setup("OpenWebSocket", () =>
{
var tcs = new TaskCompletionSource<object>();
tcs.TrySetResult(null);
return tcs.Task;
});
var fakeConnection = new FakeConnection
{
TransportConnectTimeout = new TimeSpan(0, 0, 0, 0, 100),
TotalTransportConnectTimeout = new TimeSpan(0, 0, 0, 0, 100),
Url = "http://fake.url",
Protocol = new Version(1, 42),
ConnectionToken = "MyConnToken",
MessageId = "MsgId"
};
// connect timeout unblocks this call hence the expected exception
await Assert.ThrowsAsync<TimeoutException>(
async () => await fakeWebSocketTransport.Start(fakeConnection, "test", CancellationToken.None));
Assert.Equal(1, fakeConnection.GetInvocations("Trace").Count());
Assert.Equal(1, fakeConnection.GetInvocations("PrepareRequest").Count());
var openWebSocketInvocations = fakeWebSocketTransport.GetInvocations("OpenWebSocket").ToArray();
Assert.Equal(1, openWebSocketInvocations.Length);
Assert.StartsWith(
"ws://fake.urlconnect/?clientProtocol=1.42&transport=webSockets&connectionData=test&connectionToken=MyConnToken&messageId=MsgId",
((Uri)openWebSocketInvocations[0][1]).AbsoluteUri);
}
示例2: ReconnectRetriesReconnectingIfStartingWebSocketThrows
public async Task ReconnectRetriesReconnectingIfStartingWebSocketThrows()
{
var fakeConnection = new FakeConnection
{
LastActiveAt = DateTime.UtcNow,
ReconnectWindow = new TimeSpan(0, 0, 15),
Url = "http://fakeserver/"
};
fakeConnection.Setup("ChangeState",
() =>
{
fakeConnection.State = ConnectionState.Reconnecting;
return true;
});
var fakeWebSocketTransport = new FakeWebSocketTransport
{
ReconnectDelay = new TimeSpan(0, 0, 0, 1)
};
var openWebSocketInvoked = false;
var exception = new Exception();
fakeWebSocketTransport.Setup<Task>("OpenWebSocket", () =>
{
if (!openWebSocketInvoked)
{
openWebSocketInvoked = true;
throw exception;
}
var tcs = new TaskCompletionSource<object>();
tcs.TrySetResult(null);
return tcs.Task;
});
await fakeWebSocketTransport.Reconnect(fakeConnection, null);
Assert.Equal(2, fakeWebSocketTransport.GetInvocations("OpenWebSocket").Count());
var onErrorInvocations = fakeConnection.GetInvocations("OnError").ToArray();
Assert.Equal(1, onErrorInvocations.Length);
Assert.Same(exception, onErrorInvocations[0][0]);
Assert.Equal(1, fakeConnection.GetInvocations("OnReconnected").Count());
}
示例3: ReconnectStopsReconnectingIfStartingWebSocketCancelled
public async Task ReconnectStopsReconnectingIfStartingWebSocketCancelled()
{
var fakeConnection = new FakeConnection
{
LastActiveAt = DateTime.UtcNow,
ReconnectWindow = new TimeSpan(0, 0, 15),
Url = "http://fakeserver/"
};
fakeConnection.Setup("ChangeState",
() =>
{
fakeConnection.State = ConnectionState.Reconnecting;
return true;
});
var fakeWebSocketTransport = new FakeWebSocketTransport
{
ReconnectDelay = new TimeSpan(0, 0, 0, 1)
};
fakeWebSocketTransport.Setup<Task>("OpenWebSocket", () =>
{
var tcs = new TaskCompletionSource<object>();
tcs.SetCanceled();
return tcs.Task;
});
await fakeWebSocketTransport.Reconnect(fakeConnection, null);
Assert.Equal(1, fakeWebSocketTransport.GetInvocations("OpenWebSocket").Count());
Assert.Equal(0, fakeConnection.GetInvocations("Stop").Count());
Assert.Equal(0, fakeConnection.GetInvocations("OnError").Count());
}
示例4: ReconnectDoesNotStartNewWebSocketIfDisconnectTokenTripped
public async Task ReconnectDoesNotStartNewWebSocketIfDisconnectTokenTripped()
{
var fakeConnection = new FakeConnection
{
LastActiveAt = DateTime.UtcNow,
ReconnectWindow = new TimeSpan(0, 0, 15),
Url = "http://fakeserver/",
State = ConnectionState.Reconnecting
};
var fakeWebSocketTransport = new FakeWebSocketTransport();
// this is called just to initialize the disconnect token
var _ = fakeWebSocketTransport.Start(new FakeConnection(), string.Empty, new CancellationToken(true));
await fakeWebSocketTransport.Reconnect(fakeConnection, null);
Assert.Equal(0, fakeWebSocketTransport.GetInvocations("OpenWebSocket").Count());
Assert.Equal(0, fakeConnection.GetInvocations("Stop").Count());
}
示例5: ReconnectDoesNotStartNewWebSocketIfClientWasNotInConnectState
public async Task ReconnectDoesNotStartNewWebSocketIfClientWasNotInConnectState()
{
var fakeConnection = new FakeConnection
{
LastActiveAt = DateTime.UtcNow,
ReconnectWindow = new TimeSpan(0, 0, 15),
Url = "http://fakeserver/"
};
fakeConnection.Setup("ChangeState",
() =>
{
fakeConnection.State = ConnectionState.Disconnected;
return false;
});
var fakeWebSocketTransport = new FakeWebSocketTransport();
await fakeWebSocketTransport.Reconnect(fakeConnection, null);
Assert.Equal(0, fakeWebSocketTransport.GetInvocations("OpenWebSocket").Count());
Assert.Equal(0, fakeConnection.GetInvocations("Stop").Count());
}
示例6: ReconnectStopsConnectionAndDoesNotStartNewWebSocketIfReconnectWindowExceeded
public async Task ReconnectStopsConnectionAndDoesNotStartNewWebSocketIfReconnectWindowExceeded()
{
var fakeConnection = new FakeConnection
{
LastActiveAt = DateTime.UtcNow.AddSeconds(-10),
ReconnectWindow = new TimeSpan(0, 0, 5),
Url = "http://fakeserver/"
};
fakeConnection.Setup("ChangeState",
() =>
{
fakeConnection.State = ConnectionState.Reconnecting;
return true;
});
var fakeWebSocketTransport = new FakeWebSocketTransport();
await fakeWebSocketTransport.Reconnect(fakeConnection, null);
Assert.Equal(0, fakeWebSocketTransport.GetInvocations("OpenWebSocket").Count());
var stopInvocations = fakeConnection.GetInvocations("Stop").ToArray();
Assert.Equal(1, stopInvocations.Length);
Assert.IsType(typeof(TimeoutException), stopInvocations[0][0]);
}
示例7: ReconnectStartsNewWebSocket
public async Task ReconnectStartsNewWebSocket()
{
var fakeConnection = new FakeConnection
{
LastActiveAt = DateTime.Now.AddDays(1),
ReconnectWindow = new TimeSpan(0, 0, 0),
Url = "http://fakeserver/"
};
fakeConnection.Setup("ChangeState",
() =>
{
fakeConnection.State = ConnectionState.Reconnecting;
return true;
});
var fakeWebSocketTransport = new FakeWebSocketTransport();
fakeWebSocketTransport.Setup<Task>("OpenWebSocket", () =>
{
var tcs = new TaskCompletionSource<object>();
tcs.TrySetResult(null);
return tcs.Task;
});
await fakeWebSocketTransport.Reconnect(fakeConnection, "abc");
var openWebSocketInvocations = fakeWebSocketTransport.GetInvocations("OpenWebSocket").ToArray();
Assert.Equal(1, openWebSocketInvocations.Length);
Assert.StartsWith("ws://fakeserver/reconnect?", ((Uri)openWebSocketInvocations[0][1]).AbsoluteUri);
Assert.Contains("&connectionData=abc", ((Uri)openWebSocketInvocations[0][1]).AbsoluteUri);
Assert.Equal(1, fakeConnection.GetInvocations("OnReconnected").Count());
}
示例8: MessageReceivedReadsAndProcessesMessages
public void MessageReceivedReadsAndProcessesMessages()
{
var fakeDataReader = new FakeDataReader
{
UnicodeEncoding = (UnicodeEncoding)(-1),
UnconsumedBufferLength = 42
};
fakeDataReader.Setup("ReadString", () => "MessageBody");
var fakeWebSocketResponse = new FakeWebSocketResponse();
fakeWebSocketResponse.Setup("GetDataReader", () => fakeDataReader);
var transport = new WebSocketTransport();
transport.Start(new FakeConnection(), string.Empty, CancellationToken.None);
var fakeConnection = new FakeConnection();
transport.MessageReceived(fakeWebSocketResponse, fakeConnection);
Assert.Equal(UnicodeEncoding.Utf8, fakeDataReader.UnicodeEncoding);
fakeDataReader.Verify("ReadString", new List<object[]> {new object[] { 42u}});
// invoked by ProcessResponse
Assert.Equal(1, fakeConnection.GetInvocations("MarkLastMessage").Count());
Assert.Equal(1, fakeConnection.GetInvocations("Trace").Count());
}