public void ClientDecorator_Connected_ShouldReturnClientConnected(bool value) { _client.Setup(c => c.Connected).Returns(value); var clientDecorator = new ClientDecorator(_client.Object); Assert.That(clientDecorator.Connected, Is.EqualTo(value)); }
/// <summary>Asynchronously accepts an incoming connection attempt and creates a new <see cref="T:IClientDecorator"></see> to handle remote host communication.</summary> /// <param name="asyncResult">An <see cref="T:System.IAsyncResult"></see> returned by a call to the <see cref="M:System.Net.Sockets.TcpListener.BeginAcceptTcpClient(System.AsyncCallback,System.Object)"></see> method.</param> /// <returns>A <see cref="IClientDecorator"></see>. /// The <see cref="System.Net.Sockets.TcpClient"></see> used to send and receive data.</returns> /// <seealso cref="M:ProcessViewer.Core.Adapters.Abstract.IListenerAdapter.EndAcceptConnection(IAsyncResult)"/> public IClientDecorator EndAcceptConnection(IAsyncResult asyncResult) { var tcpClient = _tcpListener.EndAcceptTcpClient(asyncResult); var client = new ClientDecorator(new TcpClientAdapter(tcpClient)); return(client); }
protected void SecurityCheck() { var clientDecorator = new ClientDecorator(_client); if (clientDecorator.IsSuspicious() && _actionSum > 15000) { throw new OperationNotAllowedException("You are suspicious"); } }
public void ClientDecorator_Handshake_CallGetStreamOnceIfNoBytesAvailable() { _client.Setup(c => c.Available).Returns(0); _client.Setup(c => c.GetStream()).Returns(new MemoryStream()); var clientDecorator = new ClientDecorator(_client.Object); clientDecorator.Handshake(); _client.Verify(c => c.Available, Times.Once); _client.Verify(c => c.GetStream(), Times.Exactly(1)); }
public void ClientDecorator_Handshake_CallGetStreamOnceIfNotGetFoundInIncomingStream() { var testBytes = Encoding.UTF8.GetBytes("Something"); _client.Setup(c => c.Available).Returns(testBytes.Length); _client.Setup(c => c.GetStream()).Returns(new MemoryStream(testBytes)); var clientDecorator = new ClientDecorator(_client.Object); clientDecorator.Handshake(); _client.Verify(c => c.Available, Times.Once); _client.Verify(c => c.GetStream(), Times.Exactly(1)); }
public static void Main(string[] args) { Console.WriteLine("Hello Patterns!\n"); ClientComposite.ExecuteScript(); ClientStrategy.ExecuteScript(); ClientDecorator.ExecuteScript(); ClientAbstractFactory.ExecuteScript(); ClientBridge.ExecuteScript(); ClientCommand.ExecuteScript(); ClientIterator.ExecuteScript(); ClientVisitor.ExecuteScript(); }
public void ClientDecorator_SendMessage_ShouldCallGetStreamOnce() { var message = "Test message"; using (var testStream = new MemoryStream()) { _client.Setup(c => c.GetStream()).Returns(testStream); var clientDecorator = new ClientDecorator(_client.Object); clientDecorator.SendMessage(message); } _client.Verify(c => c.GetStream(), Times.Exactly(1)); }
public void ClientDecorator_Handshake_CallGetStreamTwiceIfGetFoundInIncomingStream() { var testBytes = Encoding.UTF8.GetBytes("GET"); using (var testStream = new MemoryStream()) { testStream.Write(testBytes, 0, testBytes.Length); testStream.Position = 0; _client.Setup(c => c.Available).Returns(testBytes.Length); _client.Setup(c => c.GetStream()).Returns(testStream); var clientDecorator = new ClientDecorator(_client.Object); clientDecorator.Handshake(); } _client.Verify(c => c.Available, Times.Once); _client.Verify(c => c.GetStream(), Times.Exactly(2)); }
public void ClientDecorator_SendMessage_ShouldWriteTheMessageToStream() { var message = "Test message"; byte[] responseBytes; using (var testStream = new MemoryStream()) { _client.Setup(c => c.GetStream()).Returns(testStream); var clientDecorator = new ClientDecorator(_client.Object); clientDecorator.SendMessage(message); responseBytes = new byte[testStream.Position]; testStream.Position = 0; testStream.Read(responseBytes); } var responseMessage = Encoding.UTF8.GetString(responseBytes); Assert.That(responseMessage, Does.Contain(message)); }