Beispiel #1
0
        public void Read_DataBelongsToTheNextPacket_ReturnsTheSameDataOfTheFirstPacket_StartsNewSessionAndReturnsTheDataOfTheSecondPacket()
        {
            byte[] dataOne = { 0, 1, 2 };
            byte[] dataTwo = { 3, 4, 5 };

            byte[] finalBytes = new byte[dataOne.Length + dataTwo.Length];
            dataOne.CopyTo(finalBytes, 0);
            dataTwo.CopyTo(finalBytes, dataOne.Length);


            byte[] framedDataOne = MessageFramingProtocol.Frame(dataOne);
            byte[] framedDataTwo = MessageFramingProtocol.Frame(dataTwo);

            byte[] finalFramedBytes = new byte[framedDataOne.Length + framedDataTwo.Length];
            framedDataOne.CopyTo(finalFramedBytes, 0);
            framedDataTwo.CopyTo(finalFramedBytes, framedDataOne.Length);

            byte[] receivedData = null;
            var    protocol     = new MessageFramingProtocol(20);

            protocol.DataReceivedEvent += (received) => Task.Run(() =>
            {
                if (receivedData == null)
                {
                    receivedData = received;
                }
                else
                {
                    received.FlexCopyTo <byte>(ref receivedData);
                }
            });
            protocol.Read(finalFramedBytes);

            Assert.AreEqual(finalBytes, receivedData);
        }
Beispiel #2
0
        public void Read_PassingHighSizeDataWithNetworkSimulation_ReturnsTheSameData()
        {
            var path = Path.GetFullPath(TestContext.CurrentContext.TestDirectory) + @"\SampleTextFile_1000kb.txt";

            byte[] data         = File.ReadAllBytes(path);
            byte[] framedData   = MessageFramingProtocol.Frame(data);
            byte[] receivedData = null;
            var    protocol     = new MessageFramingProtocol(20 * 1024 * 1024);

            protocol.DataReceivedEvent += (receive) => Task.Run(() => receivedData = receive);

            using (var ms = new MemoryStream(framedData))
            {
                var tempBuffer = new byte[100];

                for (int i = 100; i <= framedData.Length; i += 100)
                {
                    ms.Read(tempBuffer, 0, tempBuffer.Length);
                    protocol.Read(tempBuffer);
                    ms.Seek(i, SeekOrigin.Begin);
                }
            }

            Assert.AreEqual(data, receivedData);
        }
Beispiel #3
0
        public void Read_PassingLowSizeData_ReturnsTheSameData()
        {
            byte[] data         = { 0, 1, 2 };
            byte[] framedData   = MessageFramingProtocol.Frame(data);
            byte[] receivedData = null;
            var    protocol     = new MessageFramingProtocol(20);

            protocol.DataReceivedEvent += (receive) => Task.Run(() => receivedData = receive);

            protocol.Read(framedData);

            Assert.AreEqual(data, receivedData);
        }
Beispiel #4
0
        public void Read_PassingHighSizeData_ReturnsTheSameData()
        {
            var path = Path.GetFullPath(TestContext.CurrentContext.TestDirectory) + @"\SampleTextFile_1000kb.txt";

            byte[] data         = File.ReadAllBytes(path);
            byte[] framedData   = MessageFramingProtocol.Frame(data);
            byte[] receivedData = null;
            var    protocol     = new MessageFramingProtocol(20 * 1024 * 1024);

            protocol.DataReceivedEvent += (receive) => Task.Run(() => receivedData = receive);

            protocol.Read(framedData);

            Assert.AreEqual(data, receivedData);
        }