mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 06:11:10 +00:00
Hardens test assertions and adds missing test coverage.
This commit is contained in:
1 parent
6b86fd5805
commit
1189bbaf36
489 files changed
+39982
-512
No files matched your search
+60
@@ -0,0 +1,60 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
|
||||
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.PhotoLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ImageType"/> enumeration.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ImageTypeTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void ImageType_WhenEnumeratingValues_ShouldHaveNoDuplicateValues()
|
||||
{
|
||||
// Act
|
||||
ImageType[] values = Enum.GetValues<ImageType>();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(values.Length, values.Distinct().Count());
|
||||
Assert.All(values, value => Assert.True(Enum.IsDefined(value)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void None_WhenCastingToInteger_ShouldBeZero()
|
||||
{
|
||||
// Act
|
||||
int value = (int)ImageType.None;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(0, value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingWithCamelCaseConverter_ShouldPreserveEnumValue()
|
||||
{
|
||||
// Arrange
|
||||
foreach (ImageType value in Enum.GetValues<ImageType>())
|
||||
{
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(value, _jsonOptions);
|
||||
ImageType deserialized = JsonSerializer.Deserialize<ImageType>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(value, deserialized);
|
||||
Assert.StartsWith("\"", json, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
|
||||
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.PhotoLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="VisualContentType"/> enumeration.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class VisualContentTypeTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void VisualContentType_WhenEnumeratingValues_ShouldHaveNoDuplicateValues()
|
||||
{
|
||||
// Act
|
||||
VisualContentType[] values = Enum.GetValues<VisualContentType>();
|
||||
|
||||
// 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 (VisualContentType value in Enum.GetValues<VisualContentType>())
|
||||
{
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(value, _jsonOptions);
|
||||
VisualContentType deserialized = JsonSerializer.Deserialize<VisualContentType>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(value, deserialized);
|
||||
Assert.StartsWith("\"", json, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user