Skip to content

Commit f51f277

Browse files
committed
fix: Using the same seed for idempotent guid returns the same sequence of guids instead of changing based off of the entity type
1 parent b7a7251 commit f51f277

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/FluentSeeding/Idempotency/Idempotent.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public static Guid Guid<T>(int index, string? seed = null) =>
3939
/// <returns>A stable UUID v5 GUID uniquely identifying this type/index/seed combination.</returns>
4040
public static Guid Guid(Type entityType, int index, string? seed = null)
4141
{
42-
var key = $"{entityType.Name}:{seed ?? entityType.Name}:{index}";
42+
var key = seed != null
43+
? $"{seed}:{index}"
44+
: $"{entityType.Name}:{index}";
4345
return V5Uuid(Namespace, key);
4446
}
4547

tests/FluentSeeding.Tests/Idempotency/IdempotentGuidTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,28 @@ public void Guid_WhenCalledWithDifferentSeed_ReturnsDifferentValue()
4141
withDefaultSeed.Should().NotBe(withCustomSeed);
4242
}
4343

44+
[Test]
45+
public void Guid_WhenCalledWithSameSeedAndDifferentTypes_ReturnsSameValue()
46+
{
47+
// Arrange / Act
48+
var user = Idempotent.Guid<User>(0, "shared-seed");
49+
var product = Idempotent.Guid<Product>(0, "shared-seed");
50+
51+
// Assert
52+
user.Should().Be(product);
53+
}
54+
55+
[Test]
56+
public void Guid_WhenCalledWithNoSeedAndDifferentTypes_ReturnsDifferentValue()
57+
{
58+
// Arrange / Act
59+
var user = Idempotent.Guid<User>(0);
60+
var product = Idempotent.Guid<Product>(0);
61+
62+
// Assert
63+
user.Should().NotBe(product);
64+
}
65+
4466
[Test]
4567
public void Guid_WhenCalledWithNullSeed_BehavesSameAsOmittingSeed()
4668
{

0 commit comments

Comments
 (0)