Send() public method

Send a new message

Outbound messages are enqueued and sent in order.

You may enqueue byte[] arrays or Stream objects. They will not be serialized but MicroMessage framed directly.

public Send ( object message ) : void
message object Message to send
return void
        public void send_message()
        {
            var slice = new BufferSlice(new byte[65535], 0, 65535);
            var encoder = new FakeEncoder();
            var decoder = new FakeDecoder();
            object expected = null;

            var sut = new TcpChannel(slice, encoder, decoder);
            sut.MessageReceived += (channel, message) => expected = message;
            sut.Assign(_helper.Client);
            sut.Send("Hello world");

            
        }
        public void Send_one_messages()
        {
            var slice1 = new BufferSlice(new byte[65535], 0, 65535);
            var encoder1 = new MicroMessageEncoder(new DataContractMessageSerializer());
            var decoder1 = new MicroMessageDecoder(new DataContractMessageSerializer());
            var slice2 = new BufferSlice(new byte[65535], 0, 65535);
            var encoder2 = new MicroMessageEncoder(new DataContractMessageSerializer());
            var decoder2 = new MicroMessageDecoder(new DataContractMessageSerializer());
            var evt = new ManualResetEvent(false);
            string actual = null;
            var sut2 = new TcpChannel(slice2, encoder2, decoder2);
            sut2.MessageReceived += (channel, message) =>
            {
                actual = message.ToString();
                evt.Set();
            };
            sut2.Assign(_helper.Server);

            var sut1 = new TcpChannel(slice1, encoder1, decoder1);
            sut1.MessageReceived += (channel, message) => { };
            sut1.Assign(_helper.Client);
            sut1.Send("Hello".PadRight(1000));

            evt.WaitOne(500).Should().BeTrue();
            actual.Should().StartWith("Hello");
        }
        public void Send_500_messages()
        {
            var slice1 = new BufferSlice(new byte[65535], 0, 65535);
            var encoder1 = new MicroMessageEncoder(new DataContractMessageSerializer());
            var decoder1 = new MicroMessageDecoder(new DataContractMessageSerializer());
            var slice2 = new BufferSlice(new byte[65535], 0, 65535);
            var encoder2 = new MicroMessageEncoder(new DataContractMessageSerializer());
            var decoder2 = new MicroMessageDecoder(new DataContractMessageSerializer());
            var evt = new ManualResetEvent(false);
            var messages = new List<object>();
            var sut1 = new TcpChannel(slice1, encoder1, decoder1);
            sut1.MessageReceived += (channel, message) => { };
            sut1.Assign(_helper.Client);
            var sut2 = new TcpChannel(slice2, encoder2, decoder2);
            sut2.MessageReceived += (channel, message) =>
            {
                messages.Add(message);
                if (messages.Count == 500) evt.Set();
            };
            sut2.Assign(_helper.Server);

            for (int i = 0; i < 500; i++)
            {
                sut1.Send("Hello" + i + "".PadRight(1000));
            }

            sut1.Send("Hello world");

            evt.WaitOne(500).Should().BeTrue();
            for (int i = 0; i < 500; i++)
            {
                messages[i].ToString().Should().StartWith("Hello" + i);
            }
        }