public async Task SignatureBuilderAsyncXXHash_BuildsSignature()
        {
            // Arrange
            const int dataLength = 1037;
            var       data       = new byte[dataLength];

            new Random(RandomSeed).NextBytes(data);
            var dataStream      = new MemoryStream(data);
            var signatureStream = new MemoryStream();

            var progressReporter = Substitute.For <IProgress <ProgressReport> >();

            // Act
            var target = new SignatureBuilder
            {
                ProgressReport = progressReporter
            };
            await target.BuildAsync(dataStream, new SignatureWriter(signatureStream)).ConfigureAwait(false);

            // Assert
            CollectionAssert.AreEqual(xxhash1037TestSignature, signatureStream.ToArray());

            CommonAsserts.ValidateSignature(signatureStream, new XxHashAlgorithm(), Utils.GetMd5(data), new Adler32RollingChecksum());

            progressReporter.Received().Report(Arg.Any <ProgressReport>());
        }
        public void SignatureBuilderSha1_ForRandomData_BuildsSignature(int numberOfBytes, short chunkSize)
        {
            // Arrange
            var data = new byte[numberOfBytes];

            new Random().NextBytes(data);
            var dataStream      = new MemoryStream(data);
            var signatureStream = new MemoryStream();

            var progressReporter = Substitute.For <IProgress <ProgressReport> >();

            // Act
            var target = new SignatureBuilder(SupportedAlgorithms.Hashing.Sha1(), SupportedAlgorithms.Checksum.Adler32Rolling())
            {
                ChunkSize      = chunkSize,
                ProgressReport = progressReporter
            };

            target.Build(dataStream, new SignatureWriter(signatureStream));

            // Assert
            CommonAsserts.ValidateSignature(signatureStream, new HashAlgorithmWrapper("SHA1", SHA1.Create()), Utils.GetMd5(data), new Adler32RollingChecksum());

            progressReporter.Received().Report(Arg.Any <ProgressReport>());
        }
        public async Task SignatureBuilderAsyncXXHash_ForEmptyStream_BuildsSignature()
        {
            // Arrange
            var dataStream      = new MemoryStream();
            var signatureStream = new MemoryStream();

            var progressReporter = Substitute.For <IProgress <ProgressReport> >();

            // Act
            var target = new SignatureBuilder
            {
                ProgressReport = progressReporter
            };
            await target.BuildAsync(dataStream, new SignatureWriter(signatureStream)).ConfigureAwait(false);

            // Assert
            CommonAsserts.ValidateSignature(signatureStream, new XxHashAlgorithm(), Utils.GetMd5(dataStream.ToArray()), new Adler32RollingChecksum());

            progressReporter.Received().Report(Arg.Any <ProgressReport>());
        }
Exemple #4
0
        public async Task SignatureBuilderAsyncXXHashAdlerV2_ForRandomData_BuildsSignature(int numberOfBytes, short chunkSize)
        {
            // Arrange
            var data = new byte[numberOfBytes];

            new Random().NextBytes(data);
            var dataStream      = new MemoryStream(data);
            var signatureStream = new MemoryStream();

            var progressReporter = Substitute.For <IProgress <ProgressReport> >();

            // Act
            var target = new SignatureBuilder(SupportedAlgorithms.Hashing.XxHash(), SupportedAlgorithms.Checksum.Adler32RollingV2())
            {
                ChunkSize      = chunkSize,
                ProgressReport = progressReporter
            };
            await target.BuildAsync(dataStream, new SignatureWriter(signatureStream)).ConfigureAwait(false);

            // Assert
            CommonAsserts.ValidateSignature(signatureStream, new XxHashAlgorithm(), Utils.GetMd5(data), new Adler32RollingChecksumV2());

            progressReporter.Received().Report(Arg.Any <ProgressReport>());
        }