mirror of
https://github.com/SabreTools/SabreTools.Hashing.git
synced 2026-11-17 09:50:31 +00:00
Convert HashType from enum to static class with constants
Because the ordering of the enum was not guaranteed, both because of variances in .NET version and even library version, any change could mean that invisible version bumps would misalign. This attempts to fix that by converting HashType from an enum to a static class with a set of constants instead. This allows logical groupings and orderings without it affecting the values of each item.
This commit is contained in:
@@ -15,13 +15,12 @@ namespace SabreTools.Hashing.Test
|
||||
/// <summary>
|
||||
/// Get an array of all hash types
|
||||
/// </summary>
|
||||
public static TheoryData<HashType> AllHashTypes
|
||||
public static TheoryData<string> AllHashTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
var values = Enum.GetValues<HashType>();
|
||||
var set = new TheoryData<HashType>();
|
||||
foreach (var value in values)
|
||||
var set = new TheoryData<string>();
|
||||
foreach (var value in HashType.AllHashes)
|
||||
{
|
||||
set.Add(value);
|
||||
}
|
||||
@@ -77,7 +76,7 @@ namespace SabreTools.Hashing.Test
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(AllHashTypes))]
|
||||
public void GetFileHashesSerialTest(HashType hashType)
|
||||
public void GetFileHashesSerialTest(string hashType)
|
||||
{
|
||||
var hashValue = HashTool.GetFileHash(_hashFilePath, hashType);
|
||||
TestHelper.ValidateHash(hashType, hashValue);
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace SabreTools.Hashing.Test
|
||||
|
||||
private const long _hashFileSize = 125;
|
||||
|
||||
private static readonly Dictionary<HashType, string> _knownHashes = new()
|
||||
private static readonly Dictionary<string, string> _knownHashes = new()
|
||||
{
|
||||
{HashType.Adler32, "08562d95"},
|
||||
|
||||
@@ -224,7 +224,7 @@ namespace SabreTools.Hashing.Test
|
||||
/// <summary>
|
||||
/// Validate the hashes in a hash dictionary
|
||||
/// </summary>
|
||||
public static void ValidateHashes(Dictionary<HashType, string?>? hashDict)
|
||||
public static void ValidateHashes(Dictionary<string, string?>? hashDict)
|
||||
{
|
||||
Assert.NotNull(hashDict);
|
||||
foreach (var hashType in _knownHashes.Keys)
|
||||
@@ -236,7 +236,7 @@ namespace SabreTools.Hashing.Test
|
||||
/// <summary>
|
||||
/// Validate a single hash
|
||||
/// </summary>
|
||||
public static void ValidateHash(HashType hashType, string? hashValue)
|
||||
public static void ValidateHash(string hashType, string? hashValue)
|
||||
=> Assert.Equal(_knownHashes[hashType], hashValue);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -9,13 +9,12 @@ namespace SabreTools.Hashing.Test
|
||||
/// <summary>
|
||||
/// Get an array of all hash types
|
||||
/// </summary>
|
||||
public static TheoryData<HashType> AllHashTypes
|
||||
public static TheoryData<string> AllHashTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
var values = Enum.GetValues<HashType>();
|
||||
var set = new TheoryData<HashType>();
|
||||
foreach (var value in values)
|
||||
var set = new TheoryData<string>();
|
||||
foreach (var value in HashType.AllHashes)
|
||||
{
|
||||
set.Add(value);
|
||||
}
|
||||
@@ -26,7 +25,7 @@ namespace SabreTools.Hashing.Test
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(AllHashTypes))]
|
||||
public void GetZeroByteHashes(HashType hashType)
|
||||
public void GetZeroByteHashes(string hashType)
|
||||
{
|
||||
var expected = ZeroHash.GetBytes(hashType);
|
||||
var actual = HashTool.GetByteArrayHashArray([], hashType);
|
||||
@@ -38,7 +37,7 @@ namespace SabreTools.Hashing.Test
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(AllHashTypes))]
|
||||
public void GetZeroStringHashes(HashType hashType)
|
||||
public void GetZeroStringHashes(string hashType)
|
||||
{
|
||||
var expected = ZeroHash.GetString(hashType);
|
||||
var actual = HashTool.GetByteArrayHash([], hashType);
|
||||
|
||||
Reference in New Issue
Block a user