Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Switch to using Guid.CreateVersion7() instead of Guid.NewGuid(). #397

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Domain/Heroes/Hero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
namespace SSW.CleanArchitecture.Domain.Heroes;

// For strongly typed IDs, check out the rule: https://www.ssw.com.au/rules/do-you-use-strongly-typed-ids/
public readonly record struct HeroId(Guid Value);
public readonly record struct HeroId(Guid Value)
{
public HeroId() : this(Guid.CreateVersion7()) { }
}

public class Hero : AggregateRoot<HeroId>
{
Expand All @@ -20,7 +23,8 @@ private Hero() { }

public static Hero Create(string name, string alias)
{
var hero = new Hero { Id = new HeroId(Guid.NewGuid()) };
Guid.CreateVersion7();
var hero = new Hero { Id = new HeroId(Guid.CreateVersion7()) };
hero.UpdateName(name);
hero.UpdateAlias(alias);

Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Teams/Mission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static Mission Create(string description)
ThrowIfNullOrWhiteSpace(description);
return new Mission
{
Id = new MissionId(Guid.NewGuid()),
Id = new MissionId(Guid.CreateVersion7()),
Description = description,
Status = MissionStatus.InProgress
};
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Teams/Team.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static Team Create(string name)
{
ThrowIfNullOrWhiteSpace(name);

var team = new Team { Id = new TeamId(Guid.NewGuid()), Name = name, Status = TeamStatus.Available };
var team = new Team { Id = new TeamId(Guid.CreateVersion7()), Name = name, Status = TeamStatus.Available };

return team;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Domain.UnitTests/Heroes/HeroTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void AddPower_ShouldRaisePowerLevelUpdatedEvent()
{
// Act
var hero = Hero.Create("name", "alias");
hero.Id = new HeroId(Guid.NewGuid());
hero.Id = new HeroId();
hero.UpdatePowers([new Power("Super-strength", 10)]);

// Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class DatabaseContainer : IAsyncDisposable
{
private readonly MsSqlContainer _container = new MsSqlBuilder()
.WithImage("mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04")
.WithName($"CleanArchitecture-IntegrationTests-{Guid.NewGuid()}")
.WithName($"CleanArchitecture-IntegrationTests-{Guid.CreateVersion7()}")
.WithPassword("Password123")
.WithPortBinding(1433, true)
.WithAutoRemove(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task Command_ShouldUpdateHero()
public async Task Command_WhenHeroDoesNotExist_ShouldReturnNotFound()
{
// Arrange
var heroId = new HeroId(Guid.NewGuid());
var heroId = new HeroId();
var cmd = new UpdateHeroCommand(
"foo",
"bar",
Expand Down
Loading