-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UUID Ver7 in UUID Generator Tool. (#45)
* Add UUIDv7 in UUIDGenerator Tool. * Update Description. * Update unit test (UuidHelper). * Use RandomNumberGenerator. * Update unit test.
- Loading branch information
Showing
44 changed files
with
205 additions
and
21 deletions.
There are no files selected for viewing
31 changes: 19 additions & 12 deletions
31
src/DevToys.Tools.UnitTests/Tools/Helpers/UuidHelperTests.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 |
---|---|---|
@@ -1,34 +1,41 @@ | ||
using DevToys.Tools.Helpers; | ||
using System.Text.RegularExpressions; | ||
using DevToys.Tools.Helpers; | ||
using DevToys.Tools.Models; | ||
|
||
namespace DevToys.Tools.UnitTests.Tools.Helpers; | ||
|
||
public class UuidHelperTests | ||
{ | ||
[Theory] | ||
[InlineData(UuidVersion.One, true, true)] | ||
[InlineData(UuidVersion.One, false, true)] | ||
[InlineData(UuidVersion.One, true, false)] | ||
[InlineData(UuidVersion.One, false, false)] | ||
[InlineData(UuidVersion.Four, true, true)] | ||
[InlineData(UuidVersion.Four, false, true)] | ||
[InlineData(UuidVersion.Four, true, false)] | ||
[InlineData(UuidVersion.Four, false, false)] | ||
internal void GenerateUuid(UuidVersion uuidVersion, bool hyphens, bool uppercase) | ||
[InlineData(UuidVersion.One, true, true, 1)] | ||
[InlineData(UuidVersion.One, false, true, 1)] | ||
[InlineData(UuidVersion.One, true, false, 1)] | ||
[InlineData(UuidVersion.One, false, false, 1)] | ||
[InlineData(UuidVersion.Four, true, true, 4)] | ||
[InlineData(UuidVersion.Four, false, true, 4)] | ||
[InlineData(UuidVersion.Four, true, false, 4)] | ||
[InlineData(UuidVersion.Four, false, false, 4)] | ||
[InlineData(UuidVersion.Seven, true, true, 7)] | ||
[InlineData(UuidVersion.Seven, false, true, 7)] | ||
[InlineData(UuidVersion.Seven, true, false, 7)] | ||
[InlineData(UuidVersion.Seven, false, false, 7)] | ||
internal void GenerateUuid(UuidVersion uuidVersion, bool hyphens, bool uppercase, int version) | ||
{ | ||
string newUuid | ||
= UuidHelper.GenerateUuid( | ||
uuidVersion, | ||
hyphens, | ||
uppercase); | ||
TestUuid(newUuid, hyphens, uppercase); | ||
TestUuid(newUuid, hyphens, uppercase, version); | ||
} | ||
|
||
private static void TestUuid(string uuid, bool hyphens, bool uppercase) | ||
private static void TestUuid(string uuid, bool hyphens, bool uppercase, int version) | ||
{ | ||
Guid.TryParse(uuid, out _).Should().BeTrue(); | ||
uuid.Contains('-').Should().Be(hyphens); | ||
uuid.Length.Should().Be(hyphens ? 36 : 32); | ||
uuid.Should().Be(uppercase ? uuid.ToUpperInvariant() : uuid.ToLowerInvariant()); | ||
string pattern = "^[0-9a-f]{8}-?[0-9a-f]{4}-?" + version + "[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12}$"; | ||
Regex.IsMatch(uuid.ToLowerInvariant(), pattern).Should().BeTrue(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,5 +3,6 @@ | |
internal enum UuidVersion | ||
{ | ||
One, | ||
Four | ||
Four, | ||
Seven | ||
} |
13 changes: 12 additions & 1 deletion
13
src/DevToys.Tools/Tools/Generators/UUID/UUIDGenerator.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
Oops, something went wrong.