Read() public method

public Read ( byte buffer, int offset, int count ) : int
buffer byte
offset int
count int
return int
Ejemplo n.º 1
0
        public void VirtualNetworkStream_ReadMoreThanWrite_Ok()
        {
            var network = new VirtualNetwork();

            using (var client = new VirtualNetworkStream(network, isServer: false))
                using (var server = new VirtualNetworkStream(network, isServer: true))
                {
                    var writeFrame = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
                    int frame1Len  = writeFrame.Length / 2;

                    client.Write(writeFrame, 0, frame1Len);
                    client.Write(writeFrame, frame1Len, writeFrame.Length - frame1Len);

                    int expectedReceivedBytes = writeFrame.Length;
                    var readFrame             = new byte[expectedReceivedBytes];

                    int bytesRead = 0;

                    do
                    {
                        bytesRead += server.Read(readFrame, bytesRead, expectedReceivedBytes - bytesRead);
                    }while (bytesRead < expectedReceivedBytes);

                    Assert.Equal(writeFrame, readFrame);
                }
        }
Ejemplo n.º 2
0
        public void VirtualNetworkStream_SingleThreadIntegrityTest_Ok()
        {
            var rnd     = new Random();
            var network = new VirtualNetwork();

            using (var client = new VirtualNetworkStream(network, isServer: false))
                using (var server = new VirtualNetworkStream(network, isServer: true))
                {
                    for (int i = 0; i < 100000; i++)
                    {
                        int    bufferSize;
                        byte[] writeFrame;

                        bufferSize = rnd.Next(1, 2048);
                        writeFrame = new byte[bufferSize];
                        rnd.NextBytes(writeFrame);

                        uint writeChecksum = Fletcher32.Checksum(writeFrame, 0, writeFrame.Length);
                        client.Write(writeFrame, 0, writeFrame.Length);

                        var readFrame = new byte[writeFrame.Length];
                        server.Read(readFrame, 0, readFrame.Length);
                        uint readChecksum = Fletcher32.Checksum(readFrame, 0, readFrame.Length);

                        Assert.Equal(writeChecksum, readChecksum);
                    }
                }
        }
Ejemplo n.º 3
0
        public void VirtualNetworkStream_SingleThreadIntegrityTest_Ok()
        {
            var rnd = new Random();
            var network = new VirtualNetwork();

            using (var client = new VirtualNetworkStream(network, isServer: false))
            using (var server = new VirtualNetworkStream(network, isServer: true))
            {
                for (int i = 0; i < 100000; i++)
                {
                    int bufferSize = rnd.Next(1, 2048);

                    byte[] writeFrame = new byte[bufferSize];
                    rnd.NextBytes(writeFrame);
                    uint writeChecksum = Fletcher32.Checksum(writeFrame, 0, writeFrame.Length);
                    client.Write(writeFrame, 0, writeFrame.Length);

                    var readFrame = new byte[writeFrame.Length];
                    server.Read(readFrame, 0, readFrame.Length);
                    uint readChecksum = Fletcher32.Checksum(readFrame, 0, readFrame.Length);

                    Assert.Equal(writeChecksum, readChecksum);
                }
            }
        }
Ejemplo n.º 4
0
        public void VirtualNetworkStream_WriteMoreThanRead_Ok()
        {
            var network = new VirtualNetwork();

            using (var client = new VirtualNetworkStream(network, isServer: false))
                using (var server = new VirtualNetworkStream(network, isServer: true))
                {
                    var writeFrame            = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
                    int expectedReceivedBytes = writeFrame.Length / 2;

                    client.Write(writeFrame, 0, expectedReceivedBytes);

                    var readFrame = new byte [expectedReceivedBytes];
                    server.Read(readFrame, 0, expectedReceivedBytes);

                    var expectedFrame = new byte[expectedReceivedBytes];
                    Array.Copy(writeFrame, expectedFrame, expectedReceivedBytes);

                    Assert.Equal(expectedFrame, readFrame);
                }
        }
Ejemplo n.º 5
0
        public void VirtualNetworkStream_WriteMoreThanRead_Ok()
        {
            var network = new VirtualNetwork();

            using (var client = new VirtualNetworkStream(network, isServer: false))
            using (var server = new VirtualNetworkStream(network, isServer: true))
            {
                var writeFrame = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
                int expectedReceivedBytes = writeFrame.Length / 2;

                client.Write(writeFrame, 0, expectedReceivedBytes);

                var readFrame = new byte [expectedReceivedBytes];
                server.Read(readFrame, 0, expectedReceivedBytes);

                var expectedFrame = new byte[expectedReceivedBytes];
                Array.Copy(writeFrame, expectedFrame, expectedReceivedBytes);

                Assert.Equal(expectedFrame, readFrame);
            }
        }
Ejemplo n.º 6
0
        public void VirtualNetworkStream_ReadMoreThanWrite_Ok()
        {
            var network = new VirtualNetwork();

            using (var client = new VirtualNetworkStream(network, isServer: false))
            using (var server = new VirtualNetworkStream(network, isServer: true))
            {
                var writeFrame = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
                int frame1Len = writeFrame.Length / 2;

                client.Write(writeFrame, 0, frame1Len);
                client.Write(writeFrame, frame1Len, writeFrame.Length - frame1Len);

                int expectedReceivedBytes = writeFrame.Length;
                var readFrame = new byte[expectedReceivedBytes];

                int bytesRead = 0;

                do
                {
                    bytesRead += server.Read(readFrame, bytesRead, expectedReceivedBytes - bytesRead);
                }
                while (bytesRead < expectedReceivedBytes); 

                Assert.Equal(writeFrame, readFrame);
            }
        }