mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
75 lines
2.3 KiB
C#
75 lines
2.3 KiB
C#
#region ========================================================================= USING =====================================================================================
|
|
using Lumina.Contracts.DTO.Common;
|
|
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
|
using System;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Text.Json;
|
|
#endregion
|
|
|
|
namespace Lumina.Contracts.UnitTests.DTO.Common;
|
|
|
|
/// <summary>
|
|
/// Contains unit tests for the <see cref="ReleaseInfoDto"/> record.
|
|
/// </summary>
|
|
[ExcludeFromCodeCoverage]
|
|
public class ReleaseInfoDtoTests
|
|
{
|
|
private readonly JsonSerializerOptions _jsonOptions = new()
|
|
{
|
|
PropertyNameCaseInsensitive = true
|
|
};
|
|
|
|
[Fact]
|
|
public void RoundTrip_WhenSerializingFullyPopulatedReleaseInfo_ShouldPreserveValues()
|
|
{
|
|
// Arrange
|
|
DateOnly originalReleaseDate = new(2005, 6, 15);
|
|
DateOnly reReleaseDate = new(2015, 9, 1);
|
|
ReleaseInfoDto expected = new(
|
|
originalReleaseDate,
|
|
2005,
|
|
reReleaseDate,
|
|
2015,
|
|
ReleaseCountry.US,
|
|
"Revised Edition"
|
|
);
|
|
|
|
// Act
|
|
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
|
ReleaseInfoDto? actual = JsonSerializer.Deserialize<ReleaseInfoDto>(json, _jsonOptions);
|
|
|
|
// Assert
|
|
Assert.NotNull(actual);
|
|
Assert.Equal(expected, actual);
|
|
}
|
|
|
|
[Fact]
|
|
public void RoundTrip_WhenSerializingEmptyReleaseInfo_ShouldPreserveNullValues()
|
|
{
|
|
// Arrange
|
|
ReleaseInfoDto expected = new(null, null, null, null, null, null);
|
|
|
|
// Act
|
|
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
|
ReleaseInfoDto? actual = JsonSerializer.Deserialize<ReleaseInfoDto>(json, _jsonOptions);
|
|
|
|
// Assert
|
|
Assert.NotNull(actual);
|
|
Assert.Equal(expected, actual);
|
|
}
|
|
|
|
[Fact]
|
|
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
|
{
|
|
// Arrange
|
|
ReleaseInfoDto first = new(new DateOnly(2005, 6, 15), 2005, null, null, ReleaseCountry.US, null);
|
|
ReleaseInfoDto second = new(new DateOnly(2005, 6, 15), 2005, null, null, ReleaseCountry.US, null);
|
|
|
|
// Act
|
|
bool areEqual = first == second;
|
|
|
|
// Assert
|
|
Assert.True(areEqual);
|
|
}
|
|
}
|