-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added uuid4 pseudonym generator (#62)
- Loading branch information
Showing
5 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Vfps.Tests/PseudonymGeneratorTests/Uuid4GeneratorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Vfps.PseudonymGenerators; | ||
|
||
namespace Vfps.Tests.PseudonymGeneratorTests; | ||
|
||
public class Uuid4GeneratorTests | ||
{ | ||
private readonly Uuid4Generator sut = new(); | ||
|
||
[Theory] | ||
[InlineData("test")] | ||
[InlineData("longer Value with an Emoji 👷♂️")] | ||
public void GeneratePseudonym_WithGivenInput_ShouldGenerateExpectedPseudonyms(string input) | ||
{ | ||
var generated = sut.GeneratePseudonym(input); | ||
generated.Should().HaveLength(36); | ||
} | ||
|
||
[Fact] | ||
public void GeneratePseudonym_WithLengthOtherThan36_ShouldThrowException() | ||
{ | ||
sut.Invoking(s => s.GeneratePseudonym("test", 64)).Should().Throw<ArgumentException>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Vfps.PseudonymGenerators; | ||
|
||
public class Uuid4Generator : IPseudonymGenerator | ||
{ | ||
public string GeneratePseudonym(string originalValue, uint pseudonymLength = 36) | ||
{ | ||
if (pseudonymLength != 36) | ||
{ | ||
throw new ArgumentOutOfRangeException( | ||
nameof(pseudonymLength), | ||
$"When using the {nameof(Uuid4Generator)}, the pseudonym length must be set to 36." | ||
); | ||
} | ||
|
||
return Guid.NewGuid().ToString(); | ||
} | ||
} |