public ConnectionTestsBase() { App = new FakeApp(); Socket = new FakeSocket(); Connection = new Connection(new FakeServices(), App.Call, Socket, OnDisconnected); DisconnectedEvent = new ManualResetEvent(false); }
public void SetUp() { socket = new FakeSocket(); file = TorrentTestUtils.CreateMultiFileTorrent(); socket.response = TrackerResponseTest.CreateTestResponseString(); }
public NewTests() { _app = env => TaskHelpers.Completed(); _socket = new FakeSocket(); _services = new FakeServices(); _connection = new Connection(_services, Invoke, _socket, Disconnect); _connection.Execute(); }
public async Task <FakeSocket> Connect(FakeSocket socket) { _pendingConnections.Enqueue(socket); while (!socket.IsConnected) { await Task.Delay(100); } return(socket.ConnectedSocket); }
public void WhenExistingId_ShouldReturnSocket() { var socket = new FakeSocket(); _manager.AddSocket(socket); var id = _manager.GetId(socket); Assert.Same(socket, _manager.GetSocketById(id)); }
public void WhenExistingId_ShouldReturnSocket() { var socket = new FakeSocket(); _manager.AdicionarWebSocket(socket); var id = _manager.Obter(socket)?.Id; Assert.Same(socket, _manager.ObterWebSocket(id)); }
public async Task <string> Receive(FakeSocket sender, FakeSocket receiver) { while (sender.QueuedMessage == null || sender.QueuedMessage.Target != receiver) { await Task.Delay(10); } sender.QueuedMessage.Received = true; return(sender.QueuedMessage.Message); }
public async Task <string> Send(FakeSocket sender) { while (!sender.QueuedMessage.Received) { await Task.Delay(10); } sender.QueuedMessage = null; return("OK"); }
public void WhenTrackedInstance_ShouldReturnId() { var socket = new FakeSocket(); ILoggerFactory loggerFactory = new LoggerFactory(); var connection = _manager.AddConnection(new WebSocketChannel(socket, new IMiddleware[] { }, loggerFactory)); var id = _manager.GetId(connection); Assert.NotNull(id); }
public async Task TestThrowing() { SocketSettings settings = new SocketSettings() { CatchApplicationExceptions = false, RsaKey = RsaStatic.GenerateKeyPairParams() }; IVSLCallback callback = new FakeCallback(); FakeSocket socket = new FakeSocket(settings, callback); await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => socket.OnPacketReceived(0, null)); }
public async Task <string> SendAsync(FakeSocket receiver, string message) { QueuedMessage = new QueuedMessage(); QueuedMessage.Target = receiver; QueuedMessage.Message = message; QueuedMessage.Received = false; await _fakeSocketProvider.Send(this); return("OK"); }
public void WhenExistingId_ShouldReturnSocket() { var socket = new FakeSocket(); ILoggerFactory loggerFactory = new LoggerFactory(); var connection = _manager.AddConnection(new WebSocketChannel(socket, new IMiddleware[] {}, loggerFactory)); var id = _manager.GetId(connection); Assert.Same(socket, ((WebSocketChannel)_manager.GetConnectionById(id).Channel).Socket); }
public void WhenTrackedInstance_ShouldReturnId() { var socket = new FakeSocket(); _manager.AddSocket(socket); var id = _manager.GetId(socket); Assert.NotNull(id); }
public async Task TestCatching() { SocketSettings settings = new SocketSettings() { CatchApplicationExceptions = true, RsaKey = RsaStatic.GenerateKeyPairParams() }; IVSLCallback callback = new FakeCallback(); FakeSocket socket = new FakeSocket(settings, callback); Assert.IsFalse(await socket.OnPacketReceived(0, null)); }
public void WhenOneSocketInGroup_ShouldReturnOne() { var socket = new FakeSocket(); _manager.AddSocket(socket); var socketID = _manager.GetId(socket); _manager.AddToGroup(socketID, GroupName); Assert.Equal(1, _manager.GetAllFromGroup(GroupName).Count); }
public async Task <FakeSocket> Accept(FakeSocket socket) { while (_pendingConnections.Count < 1) { await Task.Delay(100); FakeSocket target = null; if (_pendingConnections.TryDequeue(out target)) { target.ConnectedSocket = socket; return(target); } } return(null); }
public async Task <FakeSocket> AcceptAsync() { ConnectedSocket = await _fakeSocketProvider.Accept(this); return(ConnectedSocket); }
public async Task ConnectAsync() { ConnectedSocket = await _fakeSocketProvider.Connect(this); }
public async Task <string> ReceiveAsync(FakeSocket sender) { var response = await _fakeSocketProvider.Receive(sender, this); return(response); }
public void Close() { ConnectedSocket = null; }
public WriteSocketTests() { Services = new FakeServices(); Socket = new FakeSocket(); Sender = new SocketSender(Services, Socket); }