diff --git a/src/Domain/Heroes/Hero.cs b/src/Domain/Heroes/Hero.cs index c955afb3..e97b77e3 100644 --- a/src/Domain/Heroes/Hero.cs +++ b/src/Domain/Heroes/Hero.cs @@ -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 { @@ -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); diff --git a/src/Domain/Teams/Mission.cs b/src/Domain/Teams/Mission.cs index e3487910..2cf574e0 100644 --- a/src/Domain/Teams/Mission.cs +++ b/src/Domain/Teams/Mission.cs @@ -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 }; diff --git a/src/Domain/Teams/Team.cs b/src/Domain/Teams/Team.cs index c0d24550..cca467aa 100644 --- a/src/Domain/Teams/Team.cs +++ b/src/Domain/Teams/Team.cs @@ -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; } diff --git a/tests/Domain.UnitTests/Heroes/HeroTests.cs b/tests/Domain.UnitTests/Heroes/HeroTests.cs index 598d1075..a6c0288c 100644 --- a/tests/Domain.UnitTests/Heroes/HeroTests.cs +++ b/tests/Domain.UnitTests/Heroes/HeroTests.cs @@ -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 diff --git a/tests/WebApi.IntegrationTests/Common/Fixtures/DatabaseContainer.cs b/tests/WebApi.IntegrationTests/Common/Fixtures/DatabaseContainer.cs index edaa62de..2db2d3c4 100644 --- a/tests/WebApi.IntegrationTests/Common/Fixtures/DatabaseContainer.cs +++ b/tests/WebApi.IntegrationTests/Common/Fixtures/DatabaseContainer.cs @@ -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) diff --git a/tests/WebApi.IntegrationTests/Endpoints/Heroes/Commands/UpdateHeroCommandTests.cs b/tests/WebApi.IntegrationTests/Endpoints/Heroes/Commands/UpdateHeroCommandTests.cs index 90600342..082e5221 100644 --- a/tests/WebApi.IntegrationTests/Endpoints/Heroes/Commands/UpdateHeroCommandTests.cs +++ b/tests/WebApi.IntegrationTests/Endpoints/Heroes/Commands/UpdateHeroCommandTests.cs @@ -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",