public void Receive_one_message() { var slice1 = new BufferSlice(new byte[65535], 0, 65535); var encoder1 = new StringEncoder(); var decoder1 = new StringDecoder(); var expected = "Hello".PadRight(5000); var outBuffer = new byte[expected.Length + 4]; BitConverter2.GetBytes(expected.Length, outBuffer, 0); Encoding.UTF8.GetBytes(expected, 0, expected.Length, outBuffer, 4); object actual = null; var evt = new ManualResetEvent(false); var stream = new SslStream(new NetworkStream(_helper.Server)); stream.BeginAuthenticateAsServer(_certificate, OnAuthenticated, stream); var sut1 = CreateClientChannel(slice1, encoder1, decoder1); sut1.MessageReceived = (channel, message) => { actual = message; evt.Set(); }; sut1.Assign(_helper.Client); stream.Write(outBuffer); evt.WaitOne(500).Should().BeTrue(); actual.Should().Be(expected); }
public void send_message() { var slice = new BufferSlice(new byte[65535], 0, 65535); var encoder = new StringEncoder(); var decoder = new StringDecoder(); object expected = null; var sut = CreateClientChannel(slice, encoder, decoder); sut.MessageReceived += (channel, message) => expected = message; var stream = new SslStream(new NetworkStream(_helper.Server)); stream.BeginAuthenticateAsServer(_certificate, OnAuthenticated, stream); sut.Assign(_helper.Client); sut.Send("Hello world"); var buf = new byte[65535]; var tmp = stream.Read(buf, 0, 65535); var actual = Encoding.ASCII.GetString(buf, 4, tmp-4); // string encoder have a length header. actual.Should().Be("Hello world"); }
public void send_close_message() { var slice = new BufferSlice(new byte[65535], 0, 65535); var encoder = new StringEncoder(); var decoder = new StringDecoder(); var sut = CreateClientChannel(slice, encoder, decoder); sut.MessageReceived += (channel, message) => { }; var stream = new SslStream(new NetworkStream(_helper.Server)); stream.BeginAuthenticateAsServer(_certificate, OnAuthenticated, stream); sut.Assign(_helper.Client); Assert.True(sut.IsConnected); sut.Close(); Assert.False(sut.IsConnected); }