From cc18e331a7fdf9476a4a11f60fc8a66bdc7d7f38 Mon Sep 17 00:00:00 2001 From: Brandon Dahler Date: Thu, 19 Jul 2018 00:00:58 -0400 Subject: [PATCH 1/2] Initial implementation of inputStream/outptStream on ComputeHash{,Async} --- .../HashFunctionAsyncBase.cs | 74 +++++++-- .../HashFunctionBase.cs | 68 ++++++-- .../System.Data.HashFunction.Core.csproj | 1 + .../Utilities/UnifiedData/StreamData.cs | 156 ++++++++++++------ .../HashAlgorithmWrapper_Implementation.cs | 31 ++++ .../IHashFunction.cs | 51 ++++-- .../IHashFunctionAsync.cs | 59 +++++-- ...System.Data.HashFunction.Interfaces.csproj | 1 + .../Core/HashFunctionAsyncBase_Tests.cs | 4 +- .../Core/HashFunctionBase_Tests.cs | 4 +- .../Utilities/UnifiedData/StreamData_Tests.cs | 21 +-- 11 files changed, 351 insertions(+), 119 deletions(-) diff --git a/src/System.Data.HashFunction.Core/HashFunctionAsyncBase.cs b/src/System.Data.HashFunction.Core/HashFunctionAsyncBase.cs index 2d6ddb8..146b00f 100644 --- a/src/System.Data.HashFunction.Core/HashFunctionAsyncBase.cs +++ b/src/System.Data.HashFunction.Core/HashFunctionAsyncBase.cs @@ -22,22 +22,22 @@ public abstract class HashFunctionAsyncBase /// /// Computes hash value for given stream asynchronously. /// - /// Stream of data to hash. + /// Stream of data to hash. /// /// Hash value of the data. /// /// /// All stream IO is done via ReadAsync. /// - /// ; - /// Stream must be readable.; - /// Stream must be seekable for this type of hash function.; - public Task ComputeHashAsync(Stream data) => ComputeHashAsync(data, CancellationToken.None); + /// ; + /// Stream must be readable.; + /// Stream must be seekable for this type of hash function.; + public Task ComputeHashAsync(Stream inputStream) => ComputeHashAsync(inputStream, null); /// /// Computes hash value for given stream asynchronously. /// - /// Stream of data to hash. + /// Stream of data to hash. /// A cancellation token to observe while calculating the hash value. /// /// Hash value of the data. @@ -45,27 +45,71 @@ public abstract class HashFunctionAsyncBase /// /// All stream IO is done via ReadAsync. /// - /// ; - /// Stream must be readable.; - /// Stream must be seekable for this type of hash function.; + /// ; + /// Stream must be readable.; + /// Stream must be seekable for this type of hash function.; /// The was canceled. - public async Task ComputeHashAsync(Stream data, CancellationToken cancellationToken) + public Task ComputeHashAsync(Stream inputStream, CancellationToken cancellationToken) => ComputeHashAsync(inputStream, null, cancellationToken); + + /// + /// Computes hash value for given stream asynchronously. + /// + /// Stream of data to hash. + /// Stream to write the read data to. + /// + /// Hash value of the data. + /// + /// + /// All stream IO is done via ReadAsync. + /// All outputStream IO is done via WriteAsync. + /// + /// ; + /// Stream must be readable.; + /// Stream must be writable.; + /// Stream must be seekable for this type of hash function.; + public Task ComputeHashAsync(Stream inputStream, Stream outputStream) => ComputeHashAsync(inputStream, outputStream, CancellationToken.None); + + /// + /// Computes hash value for given stream asynchronously while outputting the read bytes to the second stream asynchronously. + /// + /// Stream of data to hash. + /// Stream to write the read data to. + /// A cancellation token to observe while calculating the hash value. + /// + /// Hash value of the data. + /// + /// + /// All inputStream IO is done via ReadAsync. + /// All outputStream IO is done via WriteAsync. + /// + /// ; + /// Stream must be readable.; + /// Stream must be writable.; + /// Stream must be seekable for this type of hash function.; + /// The was canceled. + public async Task ComputeHashAsync(Stream inputStream, Stream outputStream, CancellationToken cancellationToken) { - if (data == null) - throw new ArgumentNullException(nameof(data)); + if (inputStream == null) + throw new ArgumentNullException(nameof(inputStream)); + + if (!inputStream.CanRead) + throw new ArgumentException("Stream must be readable.", nameof(inputStream)); + + if (outputStream != null && !outputStream.CanWrite) + throw new ArgumentException("Stream must be writable.", nameof(outputStream)); - if (!data.CanRead) - throw new ArgumentException("Stream \"data\" must be readable.", "data"); cancellationToken.ThrowIfCancellationRequested(); return new HashValue( - await ComputeHashAsyncInternal(new StreamData(data), cancellationToken) + await ComputeHashAsyncInternal(new StreamData(inputStream, outputStream), cancellationToken) .ConfigureAwait(false), HashSizeInBits); } + + /// /// Computes hash value for given stream asynchronously. /// diff --git a/src/System.Data.HashFunction.Core/HashFunctionBase.cs b/src/System.Data.HashFunction.Core/HashFunctionBase.cs index 7e58bfc..4d29fb2 100644 --- a/src/System.Data.HashFunction.Core/HashFunctionBase.cs +++ b/src/System.Data.HashFunction.Core/HashFunctionBase.cs @@ -65,36 +65,72 @@ public IHashValue ComputeHash(byte[] data, CancellationToken cancellationToken) /// /// Computes hash value for given stream. /// - /// Stream of data to hash. + /// Stream of data to hash. /// /// Hash value of the data. /// - /// ; - /// Stream must be readable.; - /// Stream must be seekable for this type of hash function.; + /// ; + /// Stream must be readable.; + /// Stream must be seekable for this type of hash function.; /// - public IHashValue ComputeHash(Stream data) => ComputeHash(data, CancellationToken.None); + public IHashValue ComputeHash(Stream inputStream) => ComputeHash(inputStream, null, CancellationToken.None); /// /// Computes hash value for given stream. /// - /// Stream of data to hash. + /// Stream of data to hash. /// A cancellation token to observe while calculating the hash value. /// /// Hash value of the data. /// - /// ; - /// Stream must be readable.; - /// Stream must be seekable for this type of hash function.; + /// ; + /// Stream must be readable.; + /// Stream must be seekable for this type of hash function.; + /// The was canceled. + public IHashValue ComputeHash(Stream inputStream, CancellationToken cancellationToken) => ComputeHash(inputStream, null, cancellationToken); + + + /// + /// Computes hash value for given stream while outputting the read bytes to the second stream. + /// + /// Stream of data to hash. + /// Stream to write the read data to. + /// + /// Hash value of the data. + /// + /// ; + /// ; + /// Stream must be readable.; + /// Stream must be writable.; + /// Stream must be seekable for this type of hash function.; + public IHashValue ComputeHash(Stream inputStream, Stream outputStream) => ComputeHash(inputStream, outputStream, CancellationToken.None); + + /// + /// Computes hash value for given stream while outputting the read bytes to the second stream. + /// + /// Stream of data to hash. + /// Stream to write the read data to. + /// A cancellation token to observe while calculating the hash value. + /// + /// Hash value of the data. + /// + /// ; + /// Stream must be readable.; + /// Stream must be writable.; + /// Stream must be seekable for this type of hash function.; /// The was canceled. - public IHashValue ComputeHash(Stream data, CancellationToken cancellationToken) + public IHashValue ComputeHash(Stream inputStream, Stream outputStream, CancellationToken cancellationToken) { - if (data == null) - throw new ArgumentNullException(nameof(data)); - - if (!data.CanRead) - throw new ArgumentException("Stream must be readable.", nameof(data)); + if (inputStream == null) + throw new ArgumentNullException(nameof(inputStream)); + + if (!inputStream.CanRead) + throw new ArgumentException("Stream must be readable.", nameof(inputStream)); + + if (outputStream != null && !outputStream.CanWrite) + throw new ArgumentException("Stream must be writable.", nameof(outputStream)); + cancellationToken.ThrowIfCancellationRequested(); @@ -102,7 +138,7 @@ public IHashValue ComputeHash(Stream data, CancellationToken cancellationToken) return new HashValue( ComputeHashInternal( - new StreamData(data), + new StreamData(inputStream, outputStream), cancellationToken), HashSizeInBits); } diff --git a/src/System.Data.HashFunction.Core/System.Data.HashFunction.Core.csproj b/src/System.Data.HashFunction.Core/System.Data.HashFunction.Core.csproj index cb82eb7..f93bf53 100644 --- a/src/System.Data.HashFunction.Core/System.Data.HashFunction.Core.csproj +++ b/src/System.Data.HashFunction.Core/System.Data.HashFunction.Core.csproj @@ -20,6 +20,7 @@ https://github.com/brandondahler/Data.HashFunction/ false false + 2.1.0 diff --git a/src/System.Data.HashFunction.Core/Utilities/UnifiedData/StreamData.cs b/src/System.Data.HashFunction.Core/Utilities/UnifiedData/StreamData.cs index 7405805..6d1d0d3 100644 --- a/src/System.Data.HashFunction.Core/Utilities/UnifiedData/StreamData.cs +++ b/src/System.Data.HashFunction.Core/Utilities/UnifiedData/StreamData.cs @@ -9,8 +9,7 @@ namespace System.Data.HashFunction.Core.Utilities.UnifiedData { internal sealed class StreamData - : UnifiedDataAsyncBase, - IDisposable + : UnifiedDataAsyncBase { /// /// Length of data provided. @@ -19,35 +18,30 @@ internal sealed class StreamData /// Implementors are allowed throw an exception if it is not possible to resolve the length of the data. /// /// - public override long Length { get { return _data.Length; } } + public override long Length => _inputStream.Length; - private readonly Stream _data; - - private bool _disposed = false; + private readonly Stream _inputStream; + private readonly Stream _outputStream; /// /// Initializes a new instance of the class. /// - /// The stream to represent. - /// - public StreamData(Stream data) + /// The stream to represent. + /// + public StreamData(Stream inputStream) + : this(inputStream, null) { - _data = data ?? throw new ArgumentNullException(nameof(data)); - } + } - /// - /// Disposes underlying stream. - /// - public void Dispose() + public StreamData(Stream inputStream, Stream outputStream) { - if (!_disposed) - { - _data.Dispose(); - } + _inputStream = inputStream ?? throw new ArgumentNullException(nameof(inputStream)); + _outputStream = outputStream; } + /// @@ -67,11 +61,20 @@ public override void ForEachRead(Action action, CancellationTo var buffer = new byte[BufferSize]; int bytesRead; - while ((bytesRead = _data.Read(buffer, 0, buffer.Length)) > 0) + while ((bytesRead = _inputStream.Read(buffer, 0, buffer.Length)) > 0) { cancellationToken.ThrowIfCancellationRequested(); action(buffer, 0, bytesRead); + + if (_outputStream != null) + { + cancellationToken.ThrowIfCancellationRequested(); + + _outputStream.Write(buffer, 0, bytesRead); + } + + cancellationToken.ThrowIfCancellationRequested(); } } @@ -93,11 +96,21 @@ public override async Task ForEachReadAsync(Action action, Can var buffer = new byte[BufferSize]; int bytesRead; - while ((bytesRead = await _data.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false)) > 0) + while ((bytesRead = await _inputStream.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false)) > 0) { cancellationToken.ThrowIfCancellationRequested(); action(buffer, 0, bytesRead); + + if (_outputStream != null) + { + cancellationToken.ThrowIfCancellationRequested(); + + await _outputStream.WriteAsync(buffer, 0, bytesRead, cancellationToken) + .ConfigureAwait(false); + } + + cancellationToken.ThrowIfCancellationRequested(); } } @@ -130,24 +143,30 @@ public override void ForEachGroup(int groupSize, Action action byte[] buffer = new byte[groupSize < bufferSize ? bufferSize : groupSize]; int position = 0; - int currentLength; + int bytesRead; - while ((currentLength = _data.Read(buffer, position, buffer.Length - position)) > 0) + while ((bytesRead = _inputStream.Read(buffer, position, buffer.Length - position)) > 0) { cancellationToken.ThrowIfCancellationRequested(); - - position += currentLength; + position += bytesRead; // If we can fulfill a group if (position >= groupSize) { var extraBytesLength = position % groupSize; - + var invocationLength = position - extraBytesLength; // Fulfill the group - action(buffer, 0, position - extraBytesLength); + action(buffer, 0, invocationLength); + + if (_outputStream != null) + { + cancellationToken.ThrowIfCancellationRequested(); + + _outputStream.Write(buffer, 0, invocationLength); + } // Move extra bytes to beginning of array or reset position @@ -161,16 +180,25 @@ public override void ForEachGroup(int groupSize, Action action } } - cancellationToken.ThrowIfCancellationRequested(); } - if (remainderAction != null && position > 0) + if (position > 0) { - cancellationToken.ThrowIfCancellationRequested(); + if (remainderAction != null) + { + cancellationToken.ThrowIfCancellationRequested(); + + remainderAction(buffer, 0, position); + } - remainderAction(buffer, 0, position); + if (_outputStream != null) + { + cancellationToken.ThrowIfCancellationRequested(); + + _outputStream.Write(buffer, 0, position); + } } } @@ -204,24 +232,31 @@ public override async Task ForEachGroupAsync(int groupSize, Action 0) + while ((bytesRead = await _inputStream.ReadAsync(buffer, position, buffer.Length - position, cancellationToken).ConfigureAwait(false)) > 0) { cancellationToken.ThrowIfCancellationRequested(); - - - position += currentLength; + + position += bytesRead; // If we can fulfill a group if (position >= groupSize) { var extraBytesLength = position % groupSize; - + var invocationLength = position - extraBytesLength; // Fulfill the group - action(buffer, 0, position - extraBytesLength); + action(buffer, 0, invocationLength); + + if (_outputStream != null) + { + cancellationToken.ThrowIfCancellationRequested(); + + await _outputStream.WriteAsync(buffer, 0, invocationLength, cancellationToken) + .ConfigureAwait(false); + } // Move extra bytes to beginning of array or reset position @@ -234,17 +269,27 @@ public override async Task ForEachGroupAsync(int groupSize, Action 0) + if (position > 0) { - cancellationToken.ThrowIfCancellationRequested(); + if (remainderAction != null && position > 0) + { + cancellationToken.ThrowIfCancellationRequested(); + + remainderAction(buffer, 0, position); + } - remainderAction(buffer, 0, position); + if (_outputStream != null) + { + cancellationToken.ThrowIfCancellationRequested(); + + await _outputStream.WriteAsync(buffer, 0, position, cancellationToken) + .ConfigureAwait(false); + } } } @@ -264,12 +309,21 @@ public override byte[] ToArray(CancellationToken cancellationToken) var buffer = new byte[BufferSize]; int bytesRead; - while ((bytesRead = _data.Read(buffer, 0, buffer.Length)) > 0) + while ((bytesRead = _inputStream.Read(buffer, 0, buffer.Length)) > 0) { cancellationToken.ThrowIfCancellationRequested(); + ms.Write(buffer, 0, bytesRead); + if (_outputStream != null) + { + cancellationToken.ThrowIfCancellationRequested(); + + _outputStream.Write(buffer, 0, bytesRead); + } + + cancellationToken.ThrowIfCancellationRequested(); } @@ -286,10 +340,20 @@ public override async Task ToArrayAsync(CancellationToken cancellationTo { using (var ms = new MemoryStream()) { - await _data.CopyToAsync(ms, BufferSize, cancellationToken) + await _inputStream.CopyToAsync(ms, BufferSize, cancellationToken) .ConfigureAwait(false); + + var buffer = ms.ToArray(); - return ms.ToArray(); + if (_outputStream != null) + { + cancellationToken.ThrowIfCancellationRequested(); + + await _outputStream.WriteAsync(buffer, 0, buffer.Length, cancellationToken) + .ConfigureAwait(false); + } + + return buffer; } } } diff --git a/src/System.Data.HashFunction.HashAlgorithm/HashAlgorithmWrapper_Implementation.cs b/src/System.Data.HashFunction.HashAlgorithm/HashAlgorithmWrapper_Implementation.cs index 23aa60b..ba4af93 100644 --- a/src/System.Data.HashFunction.HashAlgorithm/HashAlgorithmWrapper_Implementation.cs +++ b/src/System.Data.HashFunction.HashAlgorithm/HashAlgorithmWrapper_Implementation.cs @@ -94,5 +94,36 @@ public IHashValue ComputeHash(Stream data, CancellationToken cancellationToken) HashSizeInBits); } } + + + /// + /// Computes hash value for given stream while outputting the read bytes to the second stream. + /// + /// Stream of data to hash. + /// Stream to write the read data to. + /// + /// Hash value of the data. + /// + /// ; + /// Stream must be readable.; + /// Stream must be writable.; + /// Stream must be seekable for this type of hash function.; + public IHashValue ComputeHash(Stream inputStream, Stream outputStream) => throw new NotImplementedException(); + + /// + /// Computes hash value for given stream while outputting the read bytes to the second stream. + /// + /// Stream of data to hash. + /// Stream to write the read data to. + /// A cancellation token to observe while calculating the hash value. + /// + /// Hash value of the data. + /// + /// ; + /// Stream must be readable.; + /// Stream must be writable.; + /// Stream must be seekable for this type of hash function.; + /// The was canceled. + public IHashValue ComputeHash(Stream inputStream, Stream outputStream, CancellationToken cancellationToken) => throw new NotImplementedException(); } } diff --git a/src/System.Data.HashFunction.Interfaces/IHashFunction.cs b/src/System.Data.HashFunction.Interfaces/IHashFunction.cs index 7d54a19..40a2c21 100644 --- a/src/System.Data.HashFunction.Interfaces/IHashFunction.cs +++ b/src/System.Data.HashFunction.Interfaces/IHashFunction.cs @@ -44,27 +44,58 @@ public interface IHashFunction /// /// Computes hash value for given stream. /// - /// Stream of data to hash. + /// Stream of data to hash. /// /// Hash value of the data. /// - /// ; - /// Stream must be readable.; - /// Stream must be seekable for this type of hash function.; - IHashValue ComputeHash(Stream data); + /// ; + /// Stream must be readable.; + /// Stream must be seekable for this type of hash function.; + IHashValue ComputeHash(Stream inputStream); /// /// Computes hash value for given stream. /// - /// Stream of data to hash. + /// Stream of data to hash. /// A cancellation token to observe while calculating the hash value. /// /// Hash value of the data. /// - /// ; - /// Stream must be readable.; - /// Stream must be seekable for this type of hash function.; + /// ; + /// Stream must be readable.; + /// Stream must be seekable for this type of hash function.; + /// The was canceled. + IHashValue ComputeHash(Stream inputStream, CancellationToken cancellationToken); + + + /// + /// Computes hash value for given stream while outputting the read bytes to the second stream. + /// + /// Stream of data to hash. + /// Stream to write the read data to. + /// + /// Hash value of the data. + /// + /// ; + /// Stream must be readable.; + /// Stream must be writable.; + /// Stream must be seekable for this type of hash function.; + IHashValue ComputeHash(Stream inputStream, Stream outputStream); + + /// + /// Computes hash value for given stream while outputting the read bytes to the second stream. + /// + /// Stream of data to hash. + /// Stream to write the read data to. + /// A cancellation token to observe while calculating the hash value. + /// + /// Hash value of the data. + /// + /// ; + /// Stream must be readable.; + /// Stream must be writable.; + /// Stream must be seekable for this type of hash function.; /// The was canceled. - IHashValue ComputeHash(Stream data, CancellationToken cancellationToken); + IHashValue ComputeHash(Stream inputStream, Stream outputStream, CancellationToken cancellationToken); } } diff --git a/src/System.Data.HashFunction.Interfaces/IHashFunctionAsync.cs b/src/System.Data.HashFunction.Interfaces/IHashFunctionAsync.cs index 4432d75..7cdd2f4 100644 --- a/src/System.Data.HashFunction.Interfaces/IHashFunctionAsync.cs +++ b/src/System.Data.HashFunction.Interfaces/IHashFunctionAsync.cs @@ -14,22 +14,22 @@ public interface IHashFunctionAsync /// /// Computes hash value for given stream asynchronously. /// - /// Stream of data to hash. + /// Stream of data to hash. /// /// Hash value of the data. /// /// /// All stream IO is done via ReadAsync. /// - /// ; - /// Stream must be readable.; - /// Stream must be seekable for this type of hash function.; - Task ComputeHashAsync(Stream data); + /// ; + /// Stream must be readable.; + /// Stream must be seekable for this type of hash function.; + Task ComputeHashAsync(Stream inputStream); /// /// Computes hash value for given stream asynchronously. /// - /// Stream of data to hash. + /// Stream of data to hash. /// A cancellation token to observe while calculating the hash value. /// /// Hash value of the data. @@ -37,10 +37,49 @@ public interface IHashFunctionAsync /// /// All stream IO is done via ReadAsync. /// - /// ; - /// Stream must be readable.; - /// Stream must be seekable for this type of hash function.; + /// ; + /// Stream must be readable.; + /// Stream must be seekable for this type of hash function.; /// The was canceled. - Task ComputeHashAsync(Stream data, CancellationToken cancellationToken); + Task ComputeHashAsync(Stream inputStream, CancellationToken cancellationToken); + + + /// + /// Computes hash value for given stream asynchronously. + /// + /// Stream of data to hash. + /// Stream to write the read data to. + /// + /// Hash value of the data. + /// + /// + /// All stream IO is done via ReadAsync. + /// All outputStream IO is done via WriteAsync. + /// + /// ; + /// Stream must be readable.; + /// Stream must be writable.; + /// Stream must be seekable for this type of hash function.; + Task ComputeHashAsync(Stream inputStream, Stream outputStream); + + /// + /// Computes hash value for given stream asynchronously while outputting the read bytes to the second stream asynchronously. + /// + /// Stream of data to hash. + /// Stream to write the read data to. + /// A cancellation token to observe while calculating the hash value. + /// + /// Hash value of the data. + /// + /// + /// All inputStream IO is done via ReadAsync. + /// All outputStream IO is done via WriteAsync. + /// + /// ; + /// Stream must be readable.; + /// Stream must be writable.; + /// Stream must be seekable for this type of hash function.; + /// The was canceled. + Task ComputeHashAsync(Stream inputStream, Stream outputStream, CancellationToken cancellationToken); } } diff --git a/src/System.Data.HashFunction.Interfaces/System.Data.HashFunction.Interfaces.csproj b/src/System.Data.HashFunction.Interfaces/System.Data.HashFunction.Interfaces.csproj index 3321468..1211343 100644 --- a/src/System.Data.HashFunction.Interfaces/System.Data.HashFunction.Interfaces.csproj +++ b/src/System.Data.HashFunction.Interfaces/System.Data.HashFunction.Interfaces.csproj @@ -21,6 +21,7 @@ false false System.Data.HashFunction + 2.1.0 diff --git a/src/System.Data.HashFunction.Test/Core/HashFunctionAsyncBase_Tests.cs b/src/System.Data.HashFunction.Test/Core/HashFunctionAsyncBase_Tests.cs index 6de8fae..b02a2ce 100644 --- a/src/System.Data.HashFunction.Test/Core/HashFunctionAsyncBase_Tests.cs +++ b/src/System.Data.HashFunction.Test/Core/HashFunctionAsyncBase_Tests.cs @@ -17,7 +17,7 @@ public async Task HashFunctionBase_ComputeHashAsync_Stream_IsNull_Throws() { var hashFunction = new HashFunctionImpl(); - Assert.Equal("data", + Assert.Equal("inputStream", (await Assert.ThrowsAsync(async () => await hashFunction.ComputeHashAsync(null))) .ParamName); @@ -34,7 +34,7 @@ public async Task HashFunctionAsyncBase_ComputeHashAsync_Stream_NotReadable_Thro var hashFunction = new HashFunctionImpl(); - Assert.Equal("data", + Assert.Equal("inputStream", (await Assert.ThrowsAsync(async () => await hashFunction.ComputeHashAsync(memoryStreamMock.Object))) .ParamName); diff --git a/src/System.Data.HashFunction.Test/Core/HashFunctionBase_Tests.cs b/src/System.Data.HashFunction.Test/Core/HashFunctionBase_Tests.cs index 376c4f0..df59f8b 100644 --- a/src/System.Data.HashFunction.Test/Core/HashFunctionBase_Tests.cs +++ b/src/System.Data.HashFunction.Test/Core/HashFunctionBase_Tests.cs @@ -28,7 +28,7 @@ public void HashFunctionBase_ComputeHash_Stream_IsNull_Throws() { var hashFunction = new HashFunctionImpl(); - Assert.Equal("data", + Assert.Equal("inputStream", Assert.Throws(() => hashFunction.ComputeHash((Stream) null)) .ParamName); @@ -44,7 +44,7 @@ public void HashFunctionBase_ComputeHash_Stream_NotReadable_Throws() var hashFunction = new HashFunctionImpl(); - Assert.Equal("data", + Assert.Equal("inputStream", Assert.Throws(() => hashFunction.ComputeHash(memoryStreamMock.Object)) .ParamName); diff --git a/src/System.Data.HashFunction.Test/Core/Utilities/UnifiedData/StreamData_Tests.cs b/src/System.Data.HashFunction.Test/Core/Utilities/UnifiedData/StreamData_Tests.cs index 2adc4a2..7191502 100644 --- a/src/System.Data.HashFunction.Test/Core/Utilities/UnifiedData/StreamData_Tests.cs +++ b/src/System.Data.HashFunction.Test/Core/Utilities/UnifiedData/StreamData_Tests.cs @@ -14,10 +14,10 @@ public class StreamData_Tests #region Constructor [Fact] - public void StreamData_Constructor_Data_IsNull_Throws() + public void StreamData_Constructor_InputStream_IsNull_Throws() { Assert.Equal( - "data", + "inputStream", Assert.Throws( () => new StreamData(null)) .ParamName); @@ -25,22 +25,7 @@ public void StreamData_Constructor_Data_IsNull_Throws() #endregion - - [Fact] - public void StreamData_Dispose_Works() - { - var memoryStream = new MemoryStream(); - var streamData = new StreamData(memoryStream); - - - Assert.True(memoryStream.CanRead); - - streamData.Dispose(); - - Assert.False(memoryStream.CanRead); - } - - + public class UnifiedDataAsyncTests_StreamData : UnifiedDataAsyncBase_Tests { From 63f13f98a618cb13dd4aa5508c1ac0f4f151e8dd Mon Sep 17 00:00:00 2001 From: Brandon Dahler Date: Thu, 19 Jul 2018 00:36:42 -0400 Subject: [PATCH 2/2] Nits, missing version bumps, and build script typo. --- build/build-configuration.ps1 | 4 +- .../System.Data.HashFunction.Core.csproj | 98 +++++++++---------- ...tem.Data.HashFunction.HashAlgorithm.csproj | 89 ++++++++--------- ...System.Data.HashFunction.Interfaces.csproj | 85 ++++++++-------- 4 files changed, 140 insertions(+), 136 deletions(-) diff --git a/build/build-configuration.ps1 b/build/build-configuration.ps1 index 95e5ff2..d40f16e 100644 --- a/build/build-configuration.ps1 +++ b/build/build-configuration.ps1 @@ -138,7 +138,9 @@ Task Validate-Versions -depends Resolve-Production-Versions { $packageRevision = $project.Production.VcsRevision - if ($project.Versions.Production.Version -ne $null -and $project.Versions.Production.SemanticVersion.Version -gt $project.SemanticVersion.Version) + + + if ($project.Versions.Production.SemanticVersion -ne $null -and $project.Versions.Production.SemanticVersion.Version -gt $project.SemanticVersion.Version) { Write-Host "Newer production version already exists, version bump required." -ForegroundColor Red $anyVersionBumpRequired = $true; diff --git a/src/System.Data.HashFunction.Core/System.Data.HashFunction.Core.csproj b/src/System.Data.HashFunction.Core/System.Data.HashFunction.Core.csproj index f93bf53..f8291c8 100644 --- a/src/System.Data.HashFunction.Core/System.Data.HashFunction.Core.csproj +++ b/src/System.Data.HashFunction.Core/System.Data.HashFunction.Core.csproj @@ -1,50 +1,50 @@ - - - - C# library to create a common interface to non-cryptographic hash functions (http://en.wikipedia.org/wiki/List_of_hash_functions#Non-cryptographic_hash_functions) and provide implementations of public hash functions. Includes wrapper for HashAlgorithm-based hash functions. - Copyright 2014 - Data.HashFunction.Core - 2.0.0 - Data.HashFunction Developers - netstandard1.1;net45 - true - System.Data.HashFunction.Core - ../Data.HashFunction.Production.snk - true - true - System.Data.HashFunction.Core - hash;function - https://github.com/brandondahler/Data.HashFunction/wiki/Release-Notes - https://raw.githubusercontent.com/brandondahler/Data.HashFunction/master/LICENSE - git - https://github.com/brandondahler/Data.HashFunction/ - false - false - 2.1.0 - - - + + + + C# library to create a common interface to non-cryptographic hash functions (http://en.wikipedia.org/wiki/List_of_hash_functions#Non-cryptographic_hash_functions) and provide implementations of public hash functions. Includes wrapper for HashAlgorithm-based hash functions. + Copyright 2014 + Data.HashFunction.Core + 2.1.0 + Data.HashFunction Developers + netstandard1.1;net45 + true + System.Data.HashFunction.Core + ../Data.HashFunction.Production.snk + true + true + System.Data.HashFunction.Core + hash;function + https://github.com/brandondahler/Data.HashFunction/wiki/Release-Notes + https://raw.githubusercontent.com/brandondahler/Data.HashFunction/master/LICENSE + git + https://github.com/brandondahler/Data.HashFunction/ + false + false + + + $(PackageReleaseNotes) - vcs-revision: $(VcsRevision) - - - - - - full - True - - - - - - - - - - - - - - - + +vcs-revision: $(VcsRevision) + + + + + + full + True + + + + + + + + + + + + + + + diff --git a/src/System.Data.HashFunction.HashAlgorithm/System.Data.HashFunction.HashAlgorithm.csproj b/src/System.Data.HashFunction.HashAlgorithm/System.Data.HashFunction.HashAlgorithm.csproj index e2185c4..2c95601 100644 --- a/src/System.Data.HashFunction.HashAlgorithm/System.Data.HashFunction.HashAlgorithm.csproj +++ b/src/System.Data.HashFunction.HashAlgorithm/System.Data.HashFunction.HashAlgorithm.csproj @@ -1,45 +1,46 @@ - - - - Data.HashFunction implementation of a wrapper for System.Security.Cryptography.HashAlgorithm. - Copyright 2016 - Data.HashFunction.HashAlgorithm - 2.0.0 - Data.HashFunction Developers - netstandard1.3;net45 - true - System.Data.HashFunction.HashAlgorithm - ../Data.HashFunction.Production.snk - true - true - System.Data.HashFunction.HashAlgorithm - HashAlgorithm;hash;function;algorithm - https://github.com/brandondahler/Data.HashFunction/wiki/Release-Notes - https://raw.githubusercontent.com/brandondahler/Data.HashFunction/master/LICENSE - git - https://github.com/brandondahler/Data.HashFunction/ - false - false - - - + + + + Data.HashFunction implementation of a wrapper for System.Security.Cryptography.HashAlgorithm. + Copyright 2016 + Data.HashFunction.HashAlgorithm + 2.1.0 + Data.HashFunction Developers + netstandard1.3;net45 + true + System.Data.HashFunction.HashAlgorithm + ../Data.HashFunction.Production.snk + true + true + System.Data.HashFunction.HashAlgorithm + HashAlgorithm;hash;function;algorithm + https://github.com/brandondahler/Data.HashFunction/wiki/Release-Notes + https://raw.githubusercontent.com/brandondahler/Data.HashFunction/master/LICENSE + git + https://github.com/brandondahler/Data.HashFunction/ + false + false + + + $(PackageReleaseNotes) - vcs-revision: $(VcsRevision) - - - - - full - True - - - - - - - - - - - - + +vcs-revision: $(VcsRevision) + + + + + full + True + + + + + + + + + + + + diff --git a/src/System.Data.HashFunction.Interfaces/System.Data.HashFunction.Interfaces.csproj b/src/System.Data.HashFunction.Interfaces/System.Data.HashFunction.Interfaces.csproj index 1211343..a2b7349 100644 --- a/src/System.Data.HashFunction.Interfaces/System.Data.HashFunction.Interfaces.csproj +++ b/src/System.Data.HashFunction.Interfaces/System.Data.HashFunction.Interfaces.csproj @@ -1,43 +1,44 @@ - - - - C# library to create a common interface to non-cryptographic hash functions (http://en.wikipedia.org/wiki/List_of_hash_functions#Non-cryptographic_hash_functions). - Copyright 2015 - Data.HashFunction.Interfaces - 2.0.0 - Data.HashFunction Developers - netstandard1.1;net45 - true - System.Data.HashFunction.Interfaces - ../Data.HashFunction.Production.snk - true - true - System.Data.HashFunction.Interfaces - hash;function - https://github.com/brandondahler/Data.HashFunction/wiki/Release-Notes - https://raw.githubusercontent.com/brandondahler/Data.HashFunction/master/LICENSE - git - https://github.com/brandondahler/Data.HashFunction/ - false - false - System.Data.HashFunction - 2.1.0 - - - + + + + C# library to create a common interface to non-cryptographic hash functions (http://en.wikipedia.org/wiki/List_of_hash_functions#Non-cryptographic_hash_functions). + Copyright 2015 + Data.HashFunction.Interfaces + 2.1.0 + Data.HashFunction Developers + netstandard1.1;net45 + true + System.Data.HashFunction.Interfaces + ../Data.HashFunction.Production.snk + true + true + System.Data.HashFunction.Interfaces + hash;function + https://github.com/brandondahler/Data.HashFunction/wiki/Release-Notes + https://raw.githubusercontent.com/brandondahler/Data.HashFunction/master/LICENSE + git + https://github.com/brandondahler/Data.HashFunction/ + false + false + System.Data.HashFunction + 2.1.0 + + + $(PackageReleaseNotes) - vcs-revision: $(VcsRevision) - - - - - full - True - - - - - - - - + +vcs-revision: $(VcsRevision) + + + + + full + True + + + + + + + +