本文整理汇总了C#中FakeConnection.Setup方法的典型用法代码示例。如果您正苦于以下问题:C# FakeConnection.Setup方法的具体用法?C# FakeConnection.Setup怎么用?C# FakeConnection.Setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FakeConnection
的用法示例。
在下文中一共展示了FakeConnection.Setup方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SpecificCommand
public void SpecificCommand()
{
var connection = new FakeConnection();
var cmdToReturn = new FakeCommand(new ScalarCommandResult("SELECT count(*) FROM users", null){Result = 201});
connection.Setup(cmdToReturn);
var cmd = connection.CreateCommand();
cmd.CommandText = "SELECT count(*) FROM users";
var result = cmd.ExecuteScalar();
Assert.Equal(201, result);
}
示例2: AutomaticResult
public void AutomaticResult()
{
var table = new FakeTable(new[]
{
new object[] {1, "jonas"},
new object[] {2, "arne"},
});
var connection = new FakeConnection();
connection.Setup(new FakeCommand(table));
var cmd = connection.CreateCommand();
cmd.CommandText = "SELECT Id, UserName FROM users";
var result = cmd.ExecuteReader();
Assert.True(result.Read());
Assert.Equal(1, (int)result[0]);
Assert.Equal("jonas", result[1]);
}
示例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: 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());
}
示例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());
}