예제 #1
0
        public async Task TestByteArray()
        {
            var memoryStream = new MemoryStream();
            var testValue    = new byte[] { 1, 2, 3, 4, 5, 6 };

            memoryStream.WriteByteArray(testValue);

            var tcpDataReader = new TcpDataReader(1024);

            await tcpDataReader.NewPackageAsync(memoryStream.ToArray());

            var tc     = new CancellationTokenSource();
            var result = await tcpDataReader.ReadByteArrayAsync(tc.Token);

            TestExtensions.AsReadOnlyMemory(testValue).ArraysAreEqual(result);
        }
        public async Task TestBasicFeature()
        {
            var trafficReader = new TcpDataReader(1024);

            var incomingArray = new byte[] { 1, 2, 3, 4, 5, 6 };

            await trafficReader.NewPackageAsync(incomingArray);

            var tc   = new CancellationTokenSource();
            var data = await trafficReader.ReadAsyncAsync(3, tc.Token);

            TestExtensions.AsReadOnlyMemory(incomingArray, 0, 3).ArraysAreEqual(data.AsArray());
            trafficReader.CommitReadData(data);

            data = await trafficReader.ReadAsyncAsync(2, tc.Token);

            TestExtensions.AsReadOnlyMemory(incomingArray, 3, 2).ArraysAreEqual(data.AsArray());
            trafficReader.CommitReadData(data);
        }