예제 #1
0
        public void SeekReaderBackwardToMatchByteSignature_WhenReaderNull_Throws()
        {
            var exception = Assert.Throws <ArgumentNullException>(
                () => SignedPackageArchiveIOUtility.SeekReaderBackwardToMatchByteSignature(
                    reader: null,
                    byteSignature: new byte[] { 0 }));

            Assert.Equal("reader", exception.ParamName);
        }
예제 #2
0
        public void SeekReaderBackwardToMatchByteSignature_WhenByteSignatureNullOrEmpty_Throws(byte[] byteSignature)
        {
            using (var test = new ReadTest())
            {
                test.Reader.BaseStream.Seek(offset: 0, origin: SeekOrigin.End);

                var exception = Assert.Throws <ArgumentException>(
                    () => SignedPackageArchiveIOUtility.SeekReaderBackwardToMatchByteSignature(
                        test.Reader,
                        byteSignature));

                Assert.Equal("byteSignature", exception.ParamName);
                Assert.Equal(test.Reader.BaseStream.Length, test.Reader.BaseStream.Position);
            }
        }
예제 #3
0
        public void SeekReaderBackwardToMatchByteSignature_WhenInitialPositionNearEndAndByteSignatureNotFound_Throws()
        {
            using (var test = new ReadTest())
            {
                var byteSignature = new byte[] { 3, 2 };

                test.Reader.BaseStream.Seek(offset: -byteSignature.Length, origin: SeekOrigin.End);

                Assert.Throws <InvalidDataException>(
                    () => SignedPackageArchiveIOUtility.SeekReaderBackwardToMatchByteSignature(
                        test.Reader,
                        byteSignature));

                Assert.Equal(4, test.Reader.BaseStream.Position);
            }
        }
예제 #4
0
        public void SeekReaderBackwardToMatchByteSignature_WhenInitialPositionNearEndAndByteSignatureAtStart_Seeks()
        {
            using (var test = new ReadTest())
            {
                var byteSignature = new byte[] { 0, 1 };

                test.Reader.BaseStream.Seek(offset: -byteSignature.Length, origin: SeekOrigin.End);

                SignedPackageArchiveIOUtility.SeekReaderBackwardToMatchByteSignature(test.Reader, byteSignature);

                Assert.Equal(0, test.Reader.BaseStream.Position);

                var actual = test.Reader.ReadBytes(byteSignature.Length);

                Assert.Equal(byteSignature, actual);
            }
        }
예제 #5
0
        public void SeekReaderBackwardToMatchByteSignature_WhenInitialPositionAtEnd_Throws()
        {
            using (var test = new ReadTest())
            {
                var byteSignature = new byte[] { 2, 3 };

                test.Reader.BaseStream.Seek(offset: 0, origin: SeekOrigin.End);

                var exception = Assert.Throws <ArgumentOutOfRangeException>(
                    () => SignedPackageArchiveIOUtility.SeekReaderBackwardToMatchByteSignature(
                        test.Reader,
                        byteSignature));

                Assert.Equal("byteSignature", exception.ParamName);
                Assert.Equal(test.Reader.BaseStream.Length, test.Reader.BaseStream.Position);
            }
        }
예제 #6
0
        public void SeekReaderBackwardToMatchByteSignature_WhenByteSignatureNotFound_MessageContainsByteSignature()
        {
            using (var test = new ReadTest())
            {
                var byteSignature = new byte[] { 6, 7 };

                test.Reader.BaseStream.Seek(offset: -byteSignature.Length, origin: SeekOrigin.End);

                var exception = Assert.Throws <InvalidDataException>(
                    () => SignedPackageArchiveIOUtility.SeekReaderBackwardToMatchByteSignature(
                        test.Reader,
                        byteSignature));

                Assert.Contains(BitConverter.ToString(byteSignature).Replace("-", ""), exception.Message);
                Assert.Equal(4, test.Reader.BaseStream.Position);
            }
        }