From d11e76199f3d0e3e4586fdc83d7ec9516110b56a Mon Sep 17 00:00:00 2001 From: Maytham Fahmi <9260645+maythamfahmi@users.noreply.github.com> Date: Sun, 20 Oct 2024 09:43:57 +0200 Subject: [PATCH] #86 test UniqueKeyGenerator --- CryptoNet.UnitTests/ShareProjectTests.cs | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/CryptoNet.UnitTests/ShareProjectTests.cs b/CryptoNet.UnitTests/ShareProjectTests.cs index 8f0fe1f..31145c2 100644 --- a/CryptoNet.UnitTests/ShareProjectTests.cs +++ b/CryptoNet.UnitTests/ShareProjectTests.cs @@ -121,5 +121,48 @@ public void CheckContent_WhenContentsContainSpecialCharacters_ShouldReturnTrue() // Assert result.ShouldBeTrue("because both contents are identical even with special characters."); } + + [Test] + public void UniqueKeyGenerator_ShouldGenerateCorrectHash_ForGivenInput() + { + // Arrange + string input = "testInput"; + string expectedHash = "FB054EFB1303ABDFD6E954E83F41E7BD"; // Pre-calculated MD5 hash for "testInput" + + // Act + string result = Common.UniqueKeyGenerator(input); + + // Assert + result.ShouldBe(expectedHash, "The MD5 hash generated by UniqueKeyGenerator is incorrect."); + } + + [Test] + public void UniqueKeyGenerator_ShouldGenerateSameHash_ForSameInput() + { + // Arrange + string input = "sameInput"; + + // Act + string result1 = Common.UniqueKeyGenerator(input); + string result2 = Common.UniqueKeyGenerator(input); + + // Assert + result1.ShouldBe(result2, "UniqueKeyGenerator should return the same hash for the same input."); + } + + [Test] + public void UniqueKeyGenerator_ShouldGenerateDifferentHash_ForDifferentInputs() + { + // Arrange + string input1 = "input1"; + string input2 = "input2"; + + // Act + string result1 = Common.UniqueKeyGenerator(input1); + string result2 = Common.UniqueKeyGenerator(input2); + + // Assert + result1.ShouldNotBe(result2, "UniqueKeyGenerator should return different hashes for different inputs."); + } } }