Exemple #1
0
        public void ReadTest()
        {
            var encoded = Helpers.GetExampleBytes("31 0D 05 00 06 09 2A 86 48 86 F7 0D 01 01 0B");

            using (var ms = new MemoryStream(encoded))
            {
                var sub1 = new SubStream(ms, 3);
                ms.Seek(3, SeekOrigin.Begin);

                var sub2 = new SubStream(ms, 5);
                ms.Seek(5, SeekOrigin.Current);

                var sub3 = new SubStream(ms, 4);
                ms.Seek(4, SeekOrigin.Current);

                var sub4 = new SubStream(ms, 3);
                ms.Seek(3, SeekOrigin.End);

                var val1 = new byte[3];
                sub1.Read(val1, 0, 3);

                //ComparisonResult result = compareLogic.Compare(new byte[] { 0x31, 0x0d, 0x05 }, val1);
                //Assert.True(result.AreEqual, result.DifferencesString);
                val1.ShouldBeEquivalentTo(new byte[] { 0x31, 0x0d, 0x05 }, options => options.AllowingInfiniteRecursion());

                var val2 = new byte[5];
                sub2.Read(val2, 0, 5);

                //result = compareLogic.Compare(new byte[] { 0x00, 0x06, 0x09, 0x2A, 0x86 }, val2);
                //Assert.True(result.AreEqual, result.DifferencesString);
                val2.ShouldBeEquivalentTo(new byte[] { 0x00, 0x06, 0x09, 0x2A, 0x86 }, options => options.AllowingInfiniteRecursion());

                var val3 = new byte[4];
                sub3.Read(val3, 0, 4);

                //result = compareLogic.Compare(new byte[] { 0x48, 0x86, 0xF7, 0x0D }, val3);
                //Assert.True(result.AreEqual, result.DifferencesString);
                val3.ShouldBeEquivalentTo(new byte[] { 0x48, 0x86, 0xF7, 0x0D }, options => options.AllowingInfiniteRecursion());


                var val4 = new byte[3];
                sub4.Read(val4, 0, 3);

                //result = compareLogic.Compare(new byte[] { 0x01, 0x01, 0x0B }, val4);
                //Assert.True(result.AreEqual, result.DifferencesString);
                val4.ShouldBeEquivalentTo(new byte[] { 0x01, 0x01, 0x0B }, options => options.AllowingInfiniteRecursion());


                sub1.Seek(0, SeekOrigin.Begin);
                val1 = new byte[3];
                sub1.Read(val1, 0, 3);
                //result = compareLogic.Compare(new byte[] { 0x31, 0x0d, 0x05 }, val1);
                //Assert.True(result.AreEqual, result.DifferencesString);
                val1.ShouldBeEquivalentTo(new byte[] { 0x31, 0x0d, 0x05 }, options => options.AllowingInfiniteRecursion());


                sub1.Seek(-2, SeekOrigin.End);

                val1 = new byte[2];
                sub1.Read(val1, 0, 2);
                //result = compareLogic.Compare(new byte[] { 0x0d, 0x05 }, val1);
                //Assert.True(result.AreEqual, result.DifferencesString);

                val1.ShouldBeEquivalentTo(new byte[] { 0x0d, 0x05 }, options => options.AllowingInfiniteRecursion());
            }
        }