Пример #1
0
        public void CannotWriteForWriteMode()
        {
            // Arrange
            var hashing = new HashingStream(new MemoryStream(), SHA1.Create(), false);

            // Act, Assert
            Action action = () => hashing.Read(new byte[1], 0, 1);

            action.ShouldThrow <NotSupportedException>().Which.Message.Should().Be("The hashing stream is configured to write, not read.");
        }
Пример #2
0
        public void HasHashAfterFinishedReadingInReadMode()
        {
            // Arrange
            var hashing = new HashingStream(new MemoryStream(new byte[0]), SHA1.Create(), true);

            // Act
            var read = hashing.Read(new byte[1], 0, 1);

            // Assert
            read.Should().Be(0);
            hashing.Hash.Should().NotBeNull();
            GetHash(hashing.Hash).Should().Be("DA39A3EE5E6B4B0D3255BFEF95601890AFD80709");
        }
Пример #3
0
        public void HashesPartialReadInReadMode()
        {
            // Arrange
            var inner   = new MemoryStream(Encoding.ASCII.GetBytes("foobar"));
            var hashing = new HashingStream(inner, SHA1.Create(), true);
            var buffer  = new byte[3];

            // Act
            var read = hashing.Read(buffer, 0, 3);

            hashing.Close();

            // Assert
            read.Should().Be(3);
            GetHash(hashing.Hash).Should().Be("0BEEC7B5EA3F0FDBC95D0DD47F3C5BC275DA8A33");
        }