mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 17:11:10 +00:00
Aligns the book metadata contract and consolidates metadata conversion and merging
This commit is contained in:
1 parent
590e49c9de
commit
e2d8e62908
43 files changed
+1076
-849
No files matched your search
@@ -0,0 +1,96 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user