Skip to content

Commit d8192e4

Browse files
authored
Update Factory Tests
Signed-off-by: Xen <lordofxen@deskasoft.com>
1 parent 7f56ed2 commit d8192e4

1 file changed

Lines changed: 58 additions & 4 deletions

File tree

HashifyNet.UnitTests/Core/FactoryTests.cs

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727
// ******************************************************************************
2828
// *
2929

30+
using HashifyNet.Algorithms.Argon2id;
31+
using HashifyNet.Algorithms.BuzHash;
3032
using HashifyNet.Algorithms.CRC;
33+
using HashifyNet.Algorithms.FNV;
34+
using HashifyNet.Algorithms.Pearson;
35+
using HashifyNet.Core.HashAlgorithm;
36+
using HashifyNet.UnitTests.Utilities;
3137

3238
namespace HashifyNet.UnitTests.Core
3339
{
@@ -55,7 +61,7 @@ public void Factory_CreateInstance_Null_Throws()
5561
[Fact]
5662
public void Factory_GetAllHashAlgorithms_Works()
5763
{
58-
var all = HashFactory.Instance.GetAllHashAlgorithms();
64+
var all = HashFactory.GetHashAlgorithms(HashFunctionType.Cryptographic | HashFunctionType.Noncryptographic);
5965
Assert.NotNull(all);
6066
Assert.NotEmpty(all);
6167
Assert.All(all, item => Assert.NotNull(item));
@@ -65,7 +71,7 @@ public void Factory_GetAllHashAlgorithms_Works()
6571
[Fact]
6672
public void Factory_GetAllCryptographicHashAlgorithms_Works()
6773
{
68-
var all = HashFactory.Instance.GetAllCryptographicHashAlgorithms();
74+
var all = HashFactory.GetHashAlgorithms(HashFunctionType.Cryptographic);
6975
Assert.NotNull(all);
7076
Assert.NotEmpty(all);
7177
Assert.All(all, item => Assert.NotNull(item));
@@ -75,7 +81,7 @@ public void Factory_GetAllCryptographicHashAlgorithms_Works()
7581
[Fact]
7682
public void Factory_GetAllNonCryptographicHashAlgorithms_Works()
7783
{
78-
var all = HashFactory.Instance.GetAllNonCryptographicHashAlgorithms();
84+
var all = HashFactory.GetHashAlgorithms(HashFunctionType.Noncryptographic);
7985

8086
Assert.NotNull(all);
8187
Assert.NotEmpty(all);
@@ -84,6 +90,55 @@ public void Factory_GetAllNonCryptographicHashAlgorithms_Works()
8490
Assert.All(all, item => Assert.DoesNotContain(typeof(ICryptographicHashFunction<>), item.GetInterfaces().Where(t => t.IsGenericType).ToList().ConvertAll(t => t.GetGenericTypeDefinition())));
8591
}
8692

93+
[Fact]
94+
public void Factory_ComputeNonCryptographicHashes_Works()
95+
{
96+
IHashFunctionBase[] functions = HashFactory.Instance.GetHashFunctions(HashFunctionType.Noncryptographic, new Dictionary<Type, IHashConfigBase>()
97+
{
98+
{ typeof(ICRC), CRCConfig.CRC32 },
99+
{ typeof(IPearson), new WikipediaPearsonConfig() },
100+
{ typeof(IFNV1), FNVConfig.GetPredefinedConfig(32) },
101+
{ typeof(IFNV1a), FNVConfig.GetPredefinedConfig(32) },
102+
{ typeof(IBuzHash), new DefaultBuzHashConfig() },
103+
});
104+
105+
Assert.NotNull(functions);
106+
Assert.NotEmpty(functions);
107+
Assert.All(functions, item => Assert.NotNull(item));
108+
109+
foreach (IHashFunctionBase function in functions)
110+
{
111+
IHashValue hv = function.ComputeHash(TestConstants.FooBar);
112+
Assert.NotNull(hv);
113+
Assert.NotNull(hv.Hash);
114+
Assert.NotEmpty(hv.Hash);
115+
}
116+
}
117+
118+
119+
[Fact]
120+
public void Factory_ComputeCryptographicHashes_Works()
121+
{
122+
IHashFunctionBase[] functions = HashFactory.Instance.GetHashFunctions(HashFunctionType.Cryptographic, new Dictionary<Type, IHashConfigBase>()
123+
{
124+
{ typeof(IArgon2id), Argon2idConfig.OWASP_Standard }
125+
}, typeof(IHashAlgorithmWrapper));
126+
127+
Assert.NotNull(functions);
128+
Assert.NotEmpty(functions);
129+
Assert.All(functions, item => Assert.NotNull(item));
130+
131+
foreach (IHashFunctionBase function in functions)
132+
{
133+
IHashValue hv = function.ComputeHash(TestConstants.FooBar);
134+
Assert.NotNull(hv);
135+
Assert.NotNull(hv.Hash);
136+
Assert.NotEmpty(hv.Hash);
137+
138+
(function as ICryptographicHashFunctionBase).Dispose();
139+
}
140+
}
141+
87142
[Fact]
88143
public void Factory_GetWithType_Works()
89144
{
@@ -110,4 +165,3 @@ public void Factory_CreateInstance_WithConfig_Works()
110165
}
111166
}
112167
}
113-

0 commit comments

Comments
 (0)