Skip to content

Commit 5f4e725

Browse files
authored
Add .ToImmutableArray()
Signed-off-by: Xen <lordofxen@deskasoft.com>
1 parent 4ac53da commit 5f4e725

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

HashifyNet.UnitTests/Utilities/HashValue_Tests.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
using HashifyNet.Core.Utilities;
3131
using Moq;
32+
using System.Collections.Immutable;
3233
using System.Text;
3334

3435
namespace HashifyNet.UnitTests.Utilities
@@ -64,11 +65,11 @@ public void HashValue_Constructor_CoerceToArray_WorksAsExpected()
6465
foreach (var underlyingHashValue in underlyingHashValues)
6566
{
6667
var hashValues = new[] {
67-
new HashValue(underlyingHashValue, 8),
68-
new HashValue(underlyingHashValue, 9),
69-
new HashValue(underlyingHashValue, 10),
70-
new HashValue(underlyingHashValue, 16),
71-
new HashValue(underlyingHashValue, 24)
68+
new HashValue(ArrayHelpers.CoerceToArray(underlyingHashValue, 8), 8),
69+
new HashValue(ArrayHelpers.CoerceToArray(underlyingHashValue, 9), 9),
70+
new HashValue(ArrayHelpers.CoerceToArray(underlyingHashValue, 10), 10),
71+
new HashValue(ArrayHelpers.CoerceToArray(underlyingHashValue, 16), 16),
72+
new HashValue(ArrayHelpers.CoerceToArray(underlyingHashValue, 24), 24)
7273
};
7374

7475
Assert.Equal(new byte[] { 1 }, hashValues[0].Hash);
@@ -125,8 +126,8 @@ public void HashValue_Hash_IsCopyOfConstructorValue()
125126

126127
var hashValue = new HashValue(enumerableValue, 8);
127128

128-
Assert.NotStrictEqual(enumerableValue, hashValue.Hash);
129-
Assert.Equal(enumerableValue, hashValue.Hash);
129+
Assert.NotStrictEqual(enumerableValue, hashValue.AsByteArray());
130+
Assert.Equal(enumerableValue, hashValue.AsByteArray());
130131
}
131132

132133
// Underlying Array
@@ -135,8 +136,8 @@ public void HashValue_Hash_IsCopyOfConstructorValue()
135136

136137
var hashValue = new HashValue(arrayValue, 8);
137138

138-
Assert.NotStrictEqual(arrayValue, hashValue.Hash);
139-
Assert.Equal(arrayValue, hashValue.Hash);
139+
Assert.NotStrictEqual(arrayValue, hashValue.AsByteArray());
140+
Assert.Equal(arrayValue, hashValue.AsByteArray());
140141
}
141142
}
142143

@@ -151,7 +152,9 @@ public void HashValue_BitLength_IsSameAsConstructorValue()
151152

152153
foreach (var validBitLength in validBitLengths)
153154
{
154-
var hashValue = new HashValue(new byte[2], validBitLength);
155+
byte[] orig = new byte[2];
156+
byte[] coerced = ArrayHelpers.CoerceToArray(orig, validBitLength);
157+
var hashValue = new HashValue(coerced, validBitLength);
155158

156159
Assert.Equal(validBitLength, hashValue.BitLength);
157160
}
@@ -258,34 +261,35 @@ public void HashValue_Equals_Works()
258261
Assert.False(hashValue.Equals((object)null));
259262
Assert.False(hashValue.Equals("abc"));
260263

261-
var mockValue = Mock.Of<IHashValue>(hv => hv.BitLength == 24 && hv.Hash == new byte[] { 173, 0, 255 });
264+
var mockValue = Mock.Of<IHashValue>(hv => hv.BitLength == 24 && hv.Hash == new byte[] { 173, 0, 255 }.ToImmutableArray());
262265

263266
Assert.True(hashValue.Equals(mockValue));
264267
Assert.True(hashValue.Equals((object)mockValue));
265268
}
266269

267270
{
268271
var hashValue = new HashValue(new byte[] { 173, 0, 254 }, 24);
269-
var mockValue = Mock.Of<IHashValue>(hv => hv.BitLength == 24 && hv.Hash == new byte[] { 173, 0, 255 });
272+
var mockValue = Mock.Of<IHashValue>(hv => hv.BitLength == 24 && hv.Hash == new byte[] { 173, 0, 255 }.ToImmutableArray());
270273

271274
Assert.False(hashValue.Equals(mockValue));
272275
}
273276

274277
{
275278
var hashValue = new HashValue(new byte[] { 173, 0, 254 }, 23);
276-
var mockValue = Mock.Of<IHashValue>(hv => hv.BitLength == 24 && hv.Hash == new byte[] { 173, 0, 254 });
279+
var mockValue = Mock.Of<IHashValue>(hv => hv.BitLength == 24 && hv.Hash == new byte[] { 173, 0, 254 }.ToImmutableArray());
277280

278281
Assert.False(hashValue.Equals(mockValue));
279282
}
280283

281284
{
282285
var hashValue = new HashValue(new byte[] { 173, 0, 255 }, 24);
283-
var mockValue = Mock.Of<IHashValue>(hv => hv.BitLength == 23 && hv.Hash == new byte[] { 173, 0, 127 });
286+
var mockValue = Mock.Of<IHashValue>(hv => hv.BitLength == 23 && hv.Hash == new byte[] { 173, 0, 127 }.ToImmutableArray());
284287

285288
Assert.False(hashValue.Equals(mockValue));
286289
}
287290
}
288291

289292
#endregion
290293
}
291-
}
294+
295+
}

0 commit comments

Comments
 (0)