public void ReadAndHashUntilPosition_WhenReaderNull_Throws()
        {
            using (var test = new ReadHashTest())
            {
                var exception = Assert.Throws <ArgumentNullException>(
                    () => SignedPackageArchiveIOUtility.ReadAndHashUntilPosition(
                        reader: null,
                        hashAlgorithm: test.HashAlgorithm,
                        position: 0));

                Assert.Equal("reader", exception.ParamName);
            }
        }
        public void ReadAndHashUntilPosition_WhenPositionTooBig_Throws()
        {
            using (var test = new ReadHashTest())
            {
                var exception = Assert.Throws <ArgumentOutOfRangeException>(
                    () => SignedPackageArchiveIOUtility.ReadAndHashUntilPosition(
                        test.Reader,
                        test.HashAlgorithm,
                        test.Reader.BaseStream.Length + 1));

                Assert.Equal("position", exception.ParamName);
                Assert.Equal(0, test.Reader.BaseStream.Position);
            }
        }
        public void ReadAndHashUntilPosition_WhenPositionAtStart_ReadsAndHashes()
        {
            using (var test = new ReadHashTest())
            {
                SignedPackageArchiveIOUtility.ReadAndHashUntilPosition(
                    test.Reader,
                    test.HashAlgorithm,
                    test.Reader.BaseStream.Length);

                var actualHash = test.GetHash();

                Assert.Equal("F+iNsYev1iwW5d6/PmUnzQBrwBK8kLUagQzYDC1RH0M=", actualHash);
                Assert.Equal(test.Reader.BaseStream.Length, test.Reader.BaseStream.Position);
            }
        }
        public void ReadAndHashUntilPosition_WhenPositionBeforeCurrentReadPosition_Throws()
        {
            using (var test = new ReadHashTest())
            {
                test.Reader.BaseStream.Seek(offset: 1, origin: SeekOrigin.Begin);

                var exception = Assert.Throws <ArgumentOutOfRangeException>(
                    () => SignedPackageArchiveIOUtility.ReadAndHashUntilPosition(
                        test.Reader,
                        test.HashAlgorithm,
                        position: 0));

                Assert.Equal("position", exception.ParamName);
                Assert.Equal(1, test.Reader.BaseStream.Position);
            }
        }
        public void ReadAndHashUntilPosition_WhenPositionAtEnd_ReadsAndHashes()
        {
            using (var test = new ReadHashTest())
            {
                test.Reader.BaseStream.Seek(offset: 0, origin: SeekOrigin.End);

                SignedPackageArchiveIOUtility.ReadAndHashUntilPosition(
                    test.Reader,
                    test.HashAlgorithm,
                    test.Reader.BaseStream.Length);

                var actualHash = test.GetHash();

                Assert.Equal("47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=", actualHash);
                Assert.Equal(test.Reader.BaseStream.Length, test.Reader.BaseStream.Position);
            }
        }
        public void ReadAndHashUntilPosition_WhenPositionInMiddle_ReadsAndHashes()
        {
            using (var test = new ReadHashTest())
            {
                test.Reader.BaseStream.Seek(offset: 2, origin: SeekOrigin.Begin);

                SignedPackageArchiveIOUtility.ReadAndHashUntilPosition(
                    test.Reader,
                    test.HashAlgorithm,
                    position: 5);

                var actualHash = test.GetHash();

                Assert.Equal("H1KP/SiVY0wXZTfAVdqlwJcbeRVRmZkzeg41VBDY/Zg=", actualHash);
                Assert.Equal(5, test.Reader.BaseStream.Position);
            }
        }