using DotNetty.Buffers; using DotNetty.Transport.Channels.Embedded; using EmbededChannelTest; using System; using System.Collections.Generic; using System.Text; using Xunit;
namespace UnitTest { public class UnitTester { [Fact] public void testFrameDecoder() { IByteBuffer buf = Unpooled.Buffer(); for (int i = 0; i < 9; i++) { buf.WriteByte(i); } IByteBuffer input = buf.Duplicate(); EmbeddedChannel channel = new EmbeddedChannel(new FixedLengthFrameDecoder(3)); // 写数据 // retain能够将buffer的引用计数加1,并且返回这个buffer本身 Assert.True(channel.WriteInbound(input.Retain())); Assert.True(channel.Finish()); // 读数据 IByteBuffer read = channel.ReadInbound<IByteBuffer>(); Assert.Equal(buf.ReadSlice(3), read); read.Release();