public void Setup() { _socketMock = new Mock<ISocket>(); _handlerMock = new Mock<IHandler>(); _connection = new WebSocketConnection(_socketMock.Object, connection => { }, b => new WebSocketHttpRequest(), r => _handlerMock.Object); }
public void ShouldNotRaiseInitializeIfHandlerFactoryReturnsNull() { bool initializeRaised = false; var connection = new WebSocketConnection(_socketMock.Object, conn => { initializeRaised = true; }, b => new WebSocketHttpRequest(), r => null); _socketMock.SetupGet(x => x.Connected).Returns(true); SetupReadLengths(1, 0); connection.StartReceiving(); Assert.IsFalse(initializeRaised); }
public void ShouldRaiseInitializeOnFirstRead() { bool initializeRaised = false; var connection = new WebSocketConnection(_socketMock.Object, conn => { initializeRaised = true; }, b => new WebSocketHttpRequest(), r => _handlerMock.Object); _socketMock.SetupGet(x => x.Connected).Returns(true); SetupReadLengths(1, 0); connection.StartReceiving(); Assert.IsTrue(initializeRaised); }
private void OnClientConnect(ISocket clientSocket) { FleckLog.Debug(String.Format("Client connected from {0}:{1}", clientSocket.RemoteIpAddress, clientSocket.RemotePort.ToString(CultureInfo.InvariantCulture))); ListenForClients(); WebSocketConnection connection = null; connection = new WebSocketConnection( clientSocket, _config, bytes => RequestParser.Parse(bytes, _scheme), r => HandlerFactory.BuildHandler(r, s => connection.OnMessage(s), connection.Close, b => connection.OnBinary(b))); if (IsSecure) { FleckLog.Debug("Authenticating Secure Connection"); clientSocket .Authenticate(Certificate, connection.StartReceiving, e => FleckLog.Warn("Failed to Authenticate", e)); } else { connection.StartReceiving(); } }