Ejemplo n.º 1
0
        /// <summary>
        /// Sends a message through connection
        /// </summary>
        /// <param name="m">Message to be sent</param>
        /// <exception cref="DisconnectedException">thrown if sending message fails</exception>
        public void Send(Message m)
        {
            RawMessageSender rawMessageSender = new RawMessageSender(
                (bytes, count) => _tcpStream.Write(bytes, 0, count));
            string messageString = _parser.AsString(m);

            try
            {
                rawMessageSender.SendMessage(messageString);
                SendStreamCheckingMessage();
            }
            catch (Exception e)
            {
                throw new DisconnectedException(e);
            }
        }
Ejemplo n.º 2
0
        public void TestParseCheckHoldedPieceRequest()
        {
            // Arrange
            string expected = "{\"payload\":{},\"messageID\":1}";
            var    message  = new Message <CheckHoldedPieceRequest>()
            {
                MessagePayload = new CheckHoldedPieceRequest()
            };
            // Act
            var result = parser.AsString(message);

            // Assert
            result.Should().BeEquivalentTo(expected);
        }