mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 17:11:10 +00:00
Implements tests for commit eaca69bf2a
This commit is contained in:
1 parent
94a67aded4
commit
d185c77999
15 files changed
+527
-128
No files matched your search
@@ -4,6 +4,7 @@ using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Fixtures.Common.ValueObjects.Metadata;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Common.ValueObjects.Metadata;
|
||||
@@ -27,6 +28,47 @@ public class GenreTests
|
||||
Assert.Equal("science fiction", result.Value.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(" Science FICTION ", "science fiction")] // ASCII mixed case with surrounding whitespace
|
||||
[InlineData("ÉLECTRO", "électro")] // non-ASCII Latin uppercase
|
||||
[InlineData("ЖАНР", "жанр")] // non-Latin uppercase
|
||||
[InlineData(" indie ", "indie")] // surrounding whitespace
|
||||
public void Create_WhenNameHasMixedCaseOrSurroundingWhitespace_ShouldNormalizeIt(string name, string expectedName)
|
||||
{
|
||||
// Act
|
||||
Result<Genre> result = Genre.Create(name);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(expectedName, result.Value.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCurrentCultureIsTurkish_ShouldLowercaseWithTheInvariantCulture()
|
||||
{
|
||||
CultureInfo originalCulture = CultureInfo.CurrentCulture;
|
||||
CultureInfo originalUiCulture = CultureInfo.CurrentUICulture;
|
||||
try
|
||||
{
|
||||
// Arrange
|
||||
CultureInfo.CurrentCulture = new CultureInfo("tr-TR");
|
||||
CultureInfo.CurrentUICulture = new CultureInfo("tr-TR");
|
||||
|
||||
// Act
|
||||
Result<Genre> result = Genre.Create("INDIE");
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
// The Turkish culture maps an uppercase I to a dotless lowercase i, so this proves the invariant culture is used.
|
||||
Assert.Equal("indie", result.Value.Name);
|
||||
}
|
||||
finally
|
||||
{
|
||||
CultureInfo.CurrentCulture = originalCulture;
|
||||
CultureInfo.CurrentUICulture = originalUiCulture;
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // null name
|
||||
[InlineData("")] // empty name
|
||||
|
||||
@@ -4,6 +4,7 @@ using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Fixtures.Common.ValueObjects.Metadata;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Common.ValueObjects.Metadata;
|
||||
@@ -27,6 +28,47 @@ public class TagTests
|
||||
Assert.Equal("bestseller", result.Value.Name);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(" BeStSeLLeR ", "bestseller")] // ASCII mixed case with surrounding whitespace
|
||||
[InlineData("ÉLECTRO", "électro")] // non-ASCII Latin uppercase
|
||||
[InlineData("ЖАНР", "жанр")] // non-Latin uppercase
|
||||
[InlineData(" indie ", "indie")] // surrounding whitespace
|
||||
public void Create_WhenNameHasMixedCaseOrSurroundingWhitespace_ShouldNormalizeIt(string name, string expectedName)
|
||||
{
|
||||
// Act
|
||||
Result<Tag> result = Tag.Create(name);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(expectedName, result.Value.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCurrentCultureIsTurkish_ShouldLowercaseWithTheInvariantCulture()
|
||||
{
|
||||
CultureInfo originalCulture = CultureInfo.CurrentCulture;
|
||||
CultureInfo originalUiCulture = CultureInfo.CurrentUICulture;
|
||||
try
|
||||
{
|
||||
// Arrange
|
||||
CultureInfo.CurrentCulture = new CultureInfo("tr-TR");
|
||||
CultureInfo.CurrentUICulture = new CultureInfo("tr-TR");
|
||||
|
||||
// Act
|
||||
Result<Tag> result = Tag.Create("INDIE");
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
// The Turkish culture maps an uppercase I to a dotless lowercase i, so this proves the invariant culture is used.
|
||||
Assert.Equal("indie", result.Value.Name);
|
||||
}
|
||||
finally
|
||||
{
|
||||
CultureInfo.CurrentCulture = originalCulture;
|
||||
CultureInfo.CurrentUICulture = originalUiCulture;
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // null name
|
||||
[InlineData("")] // empty name
|
||||
|
||||
Reference in new issue
Block a user