Centralizes the unique name generation of the shared fixtures

This commit is contained in:
BinaryAlley committed 2026-09-26 17:56:32 +03:00
1 parent 236ed0b488
commit 4dce426b38
3 files changed
+18 -2

No files matched your search

@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Fixtures.Common.Setup;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -26,7 +27,7 @@ public class GenreEntityFixture
string? name = null,
bool includeName = true)
{
return new GenreEntity(includeName ? name ?? _faker.Lorem.Word() : null);
return new GenreEntity(includeName ? name ?? _faker.UniqueName() : null);
}
/// <summary>
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Fixtures.Common.Setup;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -26,7 +27,7 @@ public class TagEntityFixture
string? name = null,
bool includeName = true)
{
return new TagEntity(includeName ? name ?? _faker.Lorem.Word() : null);
return new TagEntity(includeName ? name ?? _faker.UniqueName() : null);
}
/// <summary>
@@ -35,4 +35,18 @@ public static class BogusExtensions
DateTime endDateTime = end.ToDateTime(TimeOnly.MinValue);
return System.DateOnly.FromDateTime(faker.Date.Between(startDateTime, endDateTime));
}
/// <summary>
/// Adds unique name generation support to the <see cref="Faker"/> class, so that shared lookup tables never receive duplicate primary keys.
/// </summary>
/// <param name="faker">The faker instance to extend.</param>
/// <returns>A unique name of at most 50 characters.</returns>
public static string UniqueName(this Faker faker)
{
string uniqueSuffix = Guid.NewGuid().ToString("N")[..12];
int maximumWordLength = 50 - uniqueSuffix.Length - 1;
string word = faker.Lorem.Word();
string truncatedWord = word.Length > maximumWordLength ? word[..maximumWordLength] : word;
return $"{truncatedWord}-{uniqueSuffix}";
}
}