mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
97 lines
2.8 KiB
C#
97 lines
2.8 KiB
C#
#region ========================================================================= USING =====================================================================================
|
|
using Nemera.Contracts.DTO.Common;
|
|
using Nemera.Contracts.Fixtures.Core.DTO.Common;
|
|
using Nemera.Infrastructure.Common.Metadata;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
#endregion
|
|
|
|
namespace Nemera.Infrastructure.UnitTests.Common.Metadata;
|
|
|
|
/// <summary>
|
|
/// Contains unit tests for the <see cref="MetadataMerge"/> class.
|
|
/// </summary>
|
|
[ExcludeFromCodeCoverage]
|
|
public class MetadataMergeTests
|
|
{
|
|
private readonly ReleaseInfoDtoFixture _releaseInfoDtoFixture = new();
|
|
|
|
[Fact]
|
|
public void First_WhenFirstIsNull_ShouldReturnSecond()
|
|
{
|
|
// Act
|
|
string? result = MetadataMerge.First<string>(null, "second");
|
|
|
|
// Assert
|
|
Assert.Equal("second", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void First_WhenFirstIsWhiteSpace_ShouldReturnSecond()
|
|
{
|
|
// Act
|
|
string? result = MetadataMerge.First(" ", "second");
|
|
|
|
// Assert
|
|
Assert.Equal("second", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void First_WhenFirstHasValue_ShouldReturnFirst()
|
|
{
|
|
// Act
|
|
string? result = MetadataMerge.First("first", "second");
|
|
|
|
// Assert
|
|
Assert.Equal("first", result);
|
|
}
|
|
|
|
[Fact]
|
|
public void Union_WhenBothCollectionsAreNull_ShouldReturnNull()
|
|
{
|
|
// Act
|
|
List<string>? result = MetadataMerge.Union<string>(null, null, value => value);
|
|
|
|
// Assert
|
|
Assert.Null(result);
|
|
}
|
|
|
|
[Fact]
|
|
public void Union_WhenBothCollectionsHaveItems_ShouldDeDuplicateByKey()
|
|
{
|
|
// Act
|
|
List<string>? result = MetadataMerge.Union(["first", "shared"], ["shared", "second"], value => value);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(new[] { "first", "shared", "second" }, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void MergeReleaseInfo_WhenBothAreNull_ShouldReturnNull()
|
|
{
|
|
// Act
|
|
ReleaseInfoDto? result = MetadataMerge.MergeReleaseInfo(null, null);
|
|
|
|
// Assert
|
|
Assert.Null(result);
|
|
}
|
|
|
|
[Fact]
|
|
public void MergeReleaseInfo_WhenFirstHasOnlyAYearAndSecondHasADate_ShouldDeriveTheYearFromTheDate()
|
|
{
|
|
// Arrange
|
|
ReleaseInfoDto first = _releaseInfoDtoFixture.Create(originalReleaseYear: 1981, includeOriginalReleaseDate: false);
|
|
ReleaseInfoDto second = _releaseInfoDtoFixture.Create(originalReleaseDate: new DateOnly(1980, 3, 1), includeOriginalReleaseYear: false);
|
|
|
|
// Act
|
|
ReleaseInfoDto? result = MetadataMerge.MergeReleaseInfo(first, second);
|
|
|
|
// Assert
|
|
Assert.NotNull(result);
|
|
Assert.Equal(new DateOnly(1980, 3, 1), result.OriginalReleaseDate);
|
|
Assert.Equal(1980, result.OriginalReleaseYear);
|
|
}
|
|
}
|