Skip to content

Commit

Permalink
- make it like a uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
KinNeko-De committed Feb 11, 2024
1 parent 00706c0 commit 793a8a1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Sample.HumanFriendlyId.UnitTest/HumanFriendlyIdTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void Id_IsGenerated()
var sut = new HumanFriendlyId(length);
var actualId = sut.Id;

Assert.That(actualId.Length, Is.EqualTo(16));
Assert.That(actualId, Has.Length.EqualTo(length));
Assert.That(actualId, Does.Match($"^[{allowedChars}]+$"));
}

Expand All @@ -31,7 +31,7 @@ public void DisplayId_IsGroupedBySpaces(int length, int expectedLength)

string regex = CreateRegex(length);

Assert.That(actualDisplayId.Length, Is.EqualTo(expectedLength));
Assert.That(actualDisplayId, Has.Length.EqualTo(expectedLength));
Assert.That(actualDisplayId, Does.Match(regex));
}

Expand Down
8 changes: 4 additions & 4 deletions Sample.HumanFriendlyId/HumanFriendlyId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

namespace Sample.HumanFriendlyId;

public class HumanFriendlyId
public readonly struct HumanFriendlyId
{
const string chars = "ABCDEFGHJKLMNPQRSTUVWXYZ123456789";

public HumanFriendlyId(int length) : this(RandomNumberGenerator.GetItems<char>(chars, length))
{
}

protected HumanFriendlyId(char[] humanFriendlyId)
private HumanFriendlyId(char[] humanFriendlyId)
{
Id = new string(humanFriendlyId);
DisplayId = new string(GroupBySpaces(humanFriendlyId).ToArray());
}

public string Id { get; private set; }
public readonly string Id { get; private init; }

public string DisplayId { get; private set; }
public readonly string DisplayId { get; private init; }

public static HumanFriendlyId Parse(string userInput)
{
Expand Down

0 comments on commit 793a8a1

Please sign in to comment.