Replaces MVC with FastEndpoints in Lumina.Presentation.Api

This commit is contained in:
BinaryAlley committed 2024-10-23 21:34:10 +03:00
1 parent b1a20716df
commit c7b8bc2f1c
519 files changed
+15329 -8539

No files matched your search

@@ -0,0 +1,78 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.Entities.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
/// <summary>
/// Contains unit tests for the <see cref="GenreMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GenreMappingTests
{
[Fact]
public void ToRepositoryEntity_WhenMappingGenre_ShouldMapCorrectly()
{
// Arrange
ErrorOr<Genre> createResult = Genre.Create("Rock");
createResult.IsError.Should().BeFalse();
Genre genre = createResult.Value;
// Act
GenreEntity result = genre.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(genre.Name);
}
[Theory]
[InlineData("Rock")]
[InlineData("Jazz")]
[InlineData("Classical")]
[InlineData("Pop")]
public void ToRepositoryEntity_WhenMappingDifferentGenres_ShouldMapCorrectly(string name)
{
// Arrange
ErrorOr<Genre> createResult = Genre.Create(name);
createResult.IsError.Should().BeFalse();
Genre genre = createResult.Value;
// Act
GenreEntity result = genre.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(genre.Name);
}
[Fact]
public void ToRepositoryEntities_WhenMappingMultipleGenres_ShouldMapAllCorrectly()
{
// Arrange
List<Genre> genres =
[
Genre.Create("Rock").Value,
Genre.Create("Jazz").Value,
Genre.Create("Classical").Value,
Genre.Create("Pop").Value
];
// Act
IEnumerable<GenreEntity> results = genres.ToRepositoryEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(genres.Count);
List<GenreEntity> resultList = results.ToList();
for (int i = 0; i < genres.Count; i++)
resultList[i].Name.Should().Be(genres[i].Name);
}
}
@@ -0,0 +1,127 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.Entities.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
/// <summary>
/// Contains unit tests for the <see cref="GenreModelMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GenreModelMappingTests
{
[Fact]
public void ToDomainModel_WhenMappingValidGenreEntity_ShouldMapCorrectly()
{
// Arrange
GenreEntity genreEntity = new("Rock");
// Act
ErrorOr<Genre> result = genreEntity.ToDomainModel();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(genreEntity.Name);
}
[Theory]
[InlineData("Rock")]
[InlineData("Jazz")]
[InlineData("Classical")]
[InlineData("Pop")]
public void ToDomainModel_WhenMappingDifferentValidGenreEntities_ShouldMapCorrectly(string name)
{
// Arrange
GenreEntity genreEntity = new(name);
// Act
ErrorOr<Genre> result = genreEntity.ToDomainModel();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(genreEntity.Name);
}
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void ToDomainModel_WhenMappingInvalidGenreEntity_ShouldReturnError(string? invalidName)
{
// Arrange
GenreEntity genreEntity = new(invalidName);
// Act
ErrorOr<Genre> result = genreEntity.ToDomainModel();
// Assert
result.IsError.Should().BeTrue();
}
[Fact]
public void ToDomainModels_WhenMappingMultipleValidGenreEntities_ShouldMapAllCorrectly()
{
// Arrange
List<GenreEntity> genreEntities =
[
new GenreEntity("Rock"),
new GenreEntity("Jazz"),
new GenreEntity("Classical"),
new GenreEntity("Pop")
];
// Act
IEnumerable<ErrorOr<Genre>> results = genreEntities.ToDomainModels();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(genreEntities.Count);
List<ErrorOr<Genre>> resultList = results.ToList();
for (int i = 0; i < genreEntities.Count; i++)
{
resultList[i].IsError.Should().BeFalse();
resultList[i].Value.Name.Should().Be(genreEntities[i].Name);
}
}
[Fact]
public void ToDomainModels_WhenMappingMixedValidAndInvalidGenreEntities_ShouldReturnMixedResults()
{
// Arrange
List<GenreEntity> genreEntities =
[
new GenreEntity("Rock"),
new GenreEntity(""),
new GenreEntity("Jazz"),
new GenreEntity(" ")
];
// Act
IEnumerable<ErrorOr<Genre>> results = genreEntities.ToDomainModels();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(genreEntities.Count);
List<ErrorOr<Genre>> resultList = results.ToList();
resultList[0].IsError.Should().BeFalse();
resultList[0].Value.Name.Should().Be("Rock");
resultList[1].IsError.Should().BeTrue();
resultList[2].IsError.Should().BeFalse();
resultList[2].Value.Name.Should().Be("Jazz");
resultList[3].IsError.Should().BeTrue();
}
}
@@ -0,0 +1,80 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.Entities.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
/// <summary>
/// Contains unit tests for the <see cref="TagMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class TagMappingTests
{
[Fact]
public void ToRepositoryEntity_WhenMappingTag_ShouldMapCorrectly()
{
// Arrange
ErrorOr<Tag> createResult = Tag.Create("indie");
createResult.IsError.Should().BeFalse();
Tag tag = createResult.Value;
// Act
TagEntity result = tag.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(tag.Name);
}
[Theory]
[InlineData("indie")]
[InlineData("electronic")]
[InlineData("instrumental")]
[InlineData("live")]
[InlineData("acoustic")]
public void ToRepositoryEntity_WhenMappingDifferentTags_ShouldMapCorrectly(string name)
{
// Arrange
ErrorOr<Tag> createResult = Tag.Create(name);
createResult.IsError.Should().BeFalse();
Tag tag = createResult.Value;
// Act
TagEntity result = tag.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(tag.Name);
}
[Fact]
public void ToRepositoryEntities_WhenMappingMultipleTags_ShouldMapAllCorrectly()
{
// Arrange
List<Tag> tags =
[
Tag.Create("indie").Value,
Tag.Create("electronic").Value,
Tag.Create("instrumental").Value,
Tag.Create("live").Value,
Tag.Create("acoustic").Value
];
// Act
IEnumerable<TagEntity> results = tags.ToRepositoryEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(tags.Count);
List<TagEntity> resultList = results.ToList();
for (int i = 0; i < tags.Count; i++)
resultList[i].Name.Should().Be(tags[i].Name);
}
}
@@ -0,0 +1,128 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.Entities.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
/// <summary>
/// Contains unit tests for the <see cref="TagModelMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class TagModelMappingTests
{
[Fact]
public void ToDomainModel_WhenMappingValidTagEntity_ShouldMapCorrectly()
{
// Arrange
TagEntity tagEntity = new("indie");
// Act
ErrorOr<Tag> result = tagEntity.ToDomainModel();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(tagEntity.Name);
}
[Theory]
[InlineData("indie")]
[InlineData("electronic")]
[InlineData("instrumental")]
[InlineData("live")]
[InlineData("acoustic")]
public void ToDomainModel_WhenMappingDifferentValidTagEntities_ShouldMapCorrectly(string name)
{
// Arrange
TagEntity tagEntity = new(name);
// Act
ErrorOr<Tag> result = tagEntity.ToDomainModel();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(tagEntity.Name);
}
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void ToDomainModel_WhenMappingInvalidTagEntity_ShouldReturnError(string? invalidName)
{
// Arrange
TagEntity tagEntity = new(invalidName);
// Act
ErrorOr<Tag> result = tagEntity.ToDomainModel();
// Assert
result.IsError.Should().BeTrue();
}
[Fact]
public void ToDomainModels_WhenMappingMultipleValidTagEntities_ShouldMapAllCorrectly()
{
// Arrange
List<TagEntity> tagEntities =
[
new TagEntity("indie"),
new TagEntity("electronic"),
new TagEntity("instrumental"),
new TagEntity("live")
];
// Act
IEnumerable<ErrorOr<Tag>> results = tagEntities.ToDomainModels();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(tagEntities.Count);
List<ErrorOr<Tag>> resultList = results.ToList();
for (int i = 0; i < tagEntities.Count; i++)
{
resultList[i].IsError.Should().BeFalse();
resultList[i].Value.Name.Should().Be(tagEntities[i].Name);
}
}
[Fact]
public void ToDomainModels_WhenMappingMixedValidAndInvalidTagEntities_ShouldReturnMixedResults()
{
// Arrange
List<TagEntity> tagEntities =
[
new TagEntity("indie"),
new TagEntity(""),
new TagEntity("electronic"),
new TagEntity(" ")
];
// Act
IEnumerable<ErrorOr<Tag>> results = tagEntities.ToDomainModels();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(tagEntities.Count);
List<ErrorOr<Tag>> resultList = results.ToList();
resultList[0].IsError.Should().BeFalse();
resultList[0].Value.Name.Should().Be("indie");
resultList[1].IsError.Should().BeTrue();
resultList[2].IsError.Should().BeFalse();
resultList[2].Value.Name.Should().Be("electronic");
resultList[3].IsError.Should().BeTrue();
}
}