public void Do_ExtractMessageBytes_Extracts_Messages_From_Bytes(bool inputIsText, int blobCount, int extractedCount, Func<byte[], byte[]> alterFirstPacket = null)
        {
            var worksheet = new ExcelWorksheetData(TestContext);
            var comments = worksheet.String("Comments");

            var input = new List<byte[]>();
            for(var i = 1;i <= blobCount;++i) {
                var blobColumn = String.Format("Blob{0}", i);
                if(worksheet.String(blobColumn) != null) {
                    byte[] bytes;
                    if(inputIsText) bytes = Encoding.ASCII.GetBytes(worksheet.String(blobColumn).Replace("\\n", "\n").Replace("\\r", "\r"));
                    else bytes = worksheet.Bytes(blobColumn);

                    if(input.Count == 0 && alterFirstPacket != null) bytes = alterFirstPacket(bytes);
                    input.Add(bytes);
                }
            }

            var expectedOutput = new List<ExtractedBytes>();
            for(var i = 1;i <= extractedCount;++i) {
                var bytesColumn = String.Format("Extracted{0}", i);
                var parityColumn = String.Format("HadParity{0}", i);
                var checksumColumn = String.Format("BadChecksum{0}", i);
                if(worksheet.String(bytesColumn) != null || worksheet.String(checksumColumn) != null) {
                    expectedOutput.Add(new ExtractedBytes() { 
                        Bytes = worksheet.Bytes(bytesColumn),
                        HasParity = worksheet.Bool(parityColumn),
                        ChecksumFailed = worksheet.Bool(checksumColumn),
                    });
                }
            }

            var output = new List<ExtractedBytes>();
            foreach(var inputBytes in input) {
                foreach(var extractedBytes in Extractor.ExtractMessageBytes(inputBytes, 0, inputBytes.Length)) {
                    output.Add((ExtractedBytes)extractedBytes.Clone());
                }
            }

            Assert.AreEqual(expectedOutput.Count, output.Count, comments);
            for(var i = 0;i < expectedOutput.Count;++i) {
                var expected = expectedOutput[i];
                var actual = output[i];
                Assert.AreEqual(Format, actual.Format);
                Assert.AreEqual(expected.ChecksumFailed, actual.ChecksumFailed, comments);
                if(!expected.ChecksumFailed) {
                    Assert.AreEqual(expected.HasParity, actual.HasParity, comments);

                    var actualBytes = new byte[actual.Length];
                    Array.Copy(actual.Bytes, actual.Offset, actualBytes, 0, actual.Length);

                    Assert.IsTrue(expected.Bytes.SequenceEqual(actualBytes), comments);
                }
            }
        }
        public void ModeSParity_StripParity_Removes_Parity_From_Last_Three_Bytes()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            var bytes = worksheet.Bytes("Bytes");
            var offset = worksheet.Int("Offset");
            var length = worksheet.Int("Length");

            _ModeSParity.StripParity(bytes, offset, length);

            Assert.IsTrue(worksheet.Bytes("Expected").SequenceEqual(bytes));
        }
Example #3
0
        public void ModeSParity_StripParity_Removes_Parity_From_Last_Three_Bytes()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            var bytes  = worksheet.Bytes("Bytes");
            var offset = worksheet.Int("Offset");
            var length = worksheet.Int("Length");

            _ModeSParity.StripParity(bytes, offset, length);

            Assert.IsTrue(worksheet.Bytes("Expected").SequenceEqual(bytes));
        }
Example #4
0
        public void Responder_SendText_Fills_Response_Correctly()
        {
            ExcelWorksheetData worksheet = new ExcelWorksheetData(TestContext);

            string encodingName = worksheet.String("Encoding");
            var    encoding     = encodingName == null ? (Encoding)null : (Encoding)typeof(Encoding).GetProperty(encodingName, BindingFlags.Static | BindingFlags.Public).GetValue(null, null);

            _Responder.SendText(_Request.Object, _Response.Object, worksheet.EString("Text"), encoding, worksheet.EString("MimeType"));

            byte[] expectedStreamContent = worksheet.Bytes("ResponseContent");
            byte[] actualStreamContent   = _OutputStream.ToArray();

            Assert.IsTrue(expectedStreamContent.SequenceEqual(actualStreamContent));
            Assert.AreEqual(expectedStreamContent.Length, _Response.Object.ContentLength);
            Assert.AreEqual(worksheet.String("ResponseMimeType"), _Response.Object.MimeType);
            Assert.AreEqual(HttpStatusCode.OK, _Response.Object.StatusCode);
        }
        public void Do_ExtractMessageBytes_Extracts_Messages_From_Bytes(bool inputIsText, int blobCount, int extractedCount, Func <byte[], byte[]> alterFirstPacket = null)
        {
            var worksheet = new ExcelWorksheetData(TestContext);
            var comments  = worksheet.String("Comments");

            var input = new List <byte[]>();

            for (var i = 1; i <= blobCount; ++i)
            {
                var blobColumn = String.Format("Blob{0}", i);
                if (worksheet.String(blobColumn) != null)
                {
                    byte[] bytes;
                    if (inputIsText)
                    {
                        bytes = Encoding.ASCII.GetBytes(worksheet.String(blobColumn).Replace("\\n", "\n").Replace("\\r", "\r"));
                    }
                    else
                    {
                        bytes = worksheet.Bytes(blobColumn);
                    }

                    if (input.Count == 0 && alterFirstPacket != null)
                    {
                        bytes = alterFirstPacket(bytes);
                    }
                    input.Add(bytes);
                }
            }

            var expectedOutput = new List <ExtractedBytes>();

            for (var i = 1; i <= extractedCount; ++i)
            {
                var bytesColumn    = String.Format("Extracted{0}", i);
                var parityColumn   = String.Format("HadParity{0}", i);
                var checksumColumn = String.Format("BadChecksum{0}", i);
                if (worksheet.String(bytesColumn) != null || worksheet.String(checksumColumn) != null)
                {
                    expectedOutput.Add(new ExtractedBytes()
                    {
                        Bytes          = worksheet.Bytes(bytesColumn),
                        HasParity      = worksheet.Bool(parityColumn),
                        ChecksumFailed = worksheet.Bool(checksumColumn),
                    });
                }
            }

            var output = new List <ExtractedBytes>();

            foreach (var inputBytes in input)
            {
                foreach (var extractedBytes in Extractor.ExtractMessageBytes(inputBytes, 0, inputBytes.Length))
                {
                    output.Add((ExtractedBytes)extractedBytes.Clone());
                }
            }

            Assert.AreEqual(expectedOutput.Count, output.Count, comments);
            for (var i = 0; i < expectedOutput.Count; ++i)
            {
                var expected = expectedOutput[i];
                var actual   = output[i];
                Assert.AreEqual(Format, actual.Format);
                Assert.AreEqual(expected.ChecksumFailed, actual.ChecksumFailed, comments);
                if (!expected.ChecksumFailed)
                {
                    Assert.AreEqual(expected.HasParity, actual.HasParity, comments);

                    var actualBytes = new byte[actual.Length];
                    Array.Copy(actual.Bytes, actual.Offset, actualBytes, 0, actual.Length);

                    Assert.IsTrue(expected.Bytes.SequenceEqual(actualBytes), comments);
                }
            }
        }
        public void Responder_SendText_Fills_Response_Correctly()
        {
            ExcelWorksheetData worksheet = new ExcelWorksheetData(TestContext);

            string encodingName = worksheet.String("Encoding");
            var encoding = encodingName == null ? (Encoding)null : (Encoding)typeof(Encoding).GetProperty(encodingName, BindingFlags.Static | BindingFlags.Public).GetValue(null, null);

            _Responder.SendText(_Response.Object, worksheet.EString("Text"), encoding, worksheet.EString("MimeType"));

            byte[] expectedStreamContent = worksheet.Bytes("ResponseContent");
            byte[] actualStreamContent = _OutputStream.ToArray();

            Assert.IsTrue(expectedStreamContent.SequenceEqual(actualStreamContent));
            Assert.AreEqual(expectedStreamContent.Length, _Response.Object.ContentLength);
            Assert.AreEqual(worksheet.String("ResponseMimeType"), _Response.Object.MimeType);
            Assert.AreEqual(HttpStatusCode.OK, _Response.Object.StatusCode);
        }