mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 20:01:10 +00:00
51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
#region ========================================================================= USING =====================================================================================
|
|
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
|
using System;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
#endregion
|
|
|
|
namespace Lumina.Domain.SharedKernel.UnitTests.Common.Enums.BookLibrary;
|
|
|
|
/// <summary>
|
|
/// Contains unit tests for the <see cref="BookFormat"/> enumeration.
|
|
/// </summary>
|
|
[ExcludeFromCodeCoverage]
|
|
public class BookFormatTests
|
|
{
|
|
private readonly JsonSerializerOptions _jsonOptions = new()
|
|
{
|
|
PropertyNameCaseInsensitive = true,
|
|
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
|
};
|
|
|
|
[Fact]
|
|
public void BookFormat_WhenEnumeratingValues_ShouldHaveNoDuplicateValues()
|
|
{
|
|
// Act
|
|
BookFormat[] values = Enum.GetValues<BookFormat>();
|
|
|
|
// Assert
|
|
Assert.Equal(values.Length, values.Distinct().Count());
|
|
Assert.All(values, value => Assert.True(Enum.IsDefined(value)));
|
|
}
|
|
|
|
[Fact]
|
|
public void RoundTrip_WhenSerializingWithCamelCaseConverter_ShouldPreserveEnumValue()
|
|
{
|
|
// Arrange
|
|
foreach (BookFormat value in Enum.GetValues<BookFormat>())
|
|
{
|
|
// Act
|
|
string json = JsonSerializer.Serialize(value, _jsonOptions);
|
|
BookFormat deserialized = JsonSerializer.Deserialize<BookFormat>(json, _jsonOptions);
|
|
|
|
// Assert
|
|
Assert.Equal(value, deserialized);
|
|
Assert.StartsWith("\"", json, StringComparison.Ordinal);
|
|
}
|
|
}
|
|
}
|