mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Refactors for correct media contributor name
This commit is contained in:
1 parent
1ee12d74a4
commit
cb14ad19a7
11 files changed
+135
-23
No files matched your search
@@ -4,6 +4,6 @@ namespace Lumina.Application.Common.Models.Contributors;
|
||||
/// Represents a media contributor.
|
||||
/// </summary>
|
||||
public record MediaContributorDto(
|
||||
string? Name,
|
||||
MediaContributorNameDto? Name,
|
||||
MediaContributorRoleDto? Role
|
||||
);
|
||||
@@ -4,6 +4,6 @@ namespace Lumina.Application.Common.Models.Contributors;
|
||||
/// Represents a media contributor name.
|
||||
/// </summary>
|
||||
public record MediaContributorNameDto(
|
||||
string DisplayName,
|
||||
string? DisplayName,
|
||||
string? LegalName
|
||||
);
|
||||
+11
-2
@@ -174,8 +174,17 @@ public class AddBookCommandValidator : AbstractValidator<AddBookCommand>
|
||||
.ChildRules(contributor =>
|
||||
{
|
||||
contributor.RuleFor(c => c.Name)
|
||||
.NotEmpty().WithMessage(Errors.MediaContributor.ContributorNameCannotBeEmpty.Code)
|
||||
.MaximumLength(100).WithMessage(Errors.MediaContributor.ContributorNameMustBeMaximum100CharactersLong.Code);
|
||||
.NotNull().WithMessage(Errors.MediaContributor.ContributorNameCannotBeEmpty.Code)
|
||||
.ChildRules(name =>
|
||||
{
|
||||
name.RuleFor(n => n!.DisplayName)
|
||||
.NotNull().WithMessage(Errors.MediaContributor.ContributorDisplayNameCannotBeEmpty.Code)
|
||||
.NotEmpty().WithMessage(Errors.MediaContributor.ContributorDisplayNameCannotBeEmpty.Code)
|
||||
.MaximumLength(100).WithMessage(Errors.MediaContributor.ContributorDisplayNameMustBeMaximum100CharactersLong.Code);
|
||||
name.RuleFor(n => n!.LegalName)
|
||||
.MaximumLength(100).When(n => n!.LegalName is not null)
|
||||
.WithMessage(Errors.MediaContributor.ContributorLegalNameMustBeMaximum100CharactersLong.Code);
|
||||
});
|
||||
contributor.RuleFor(c => c.Role)
|
||||
.NotNull().WithMessage(Errors.MediaContributor.ContributorRoleCannotBeNull.Code)
|
||||
.ChildRules(role =>
|
||||
|
||||
@@ -15,7 +15,9 @@ public static partial class Errors
|
||||
|
||||
public static Error ContributorsListCannotBeNull => Error.Validation(nameof(ContributorsListCannotBeNull));
|
||||
public static Error ContributorNameCannotBeEmpty => Error.Validation(nameof(ContributorNameCannotBeEmpty));
|
||||
public static Error ContributorNameMustBeMaximum100CharactersLong => Error.Validation(nameof(ContributorNameMustBeMaximum100CharactersLong));
|
||||
public static Error ContributorDisplayNameCannotBeEmpty => Error.Validation(nameof(ContributorDisplayNameCannotBeEmpty));
|
||||
public static Error ContributorDisplayNameMustBeMaximum100CharactersLong => Error.Validation(nameof(ContributorDisplayNameMustBeMaximum100CharactersLong));
|
||||
public static Error ContributorLegalNameMustBeMaximum100CharactersLong => Error.Validation(nameof(ContributorLegalNameMustBeMaximum100CharactersLong));
|
||||
public static Error RoleNameCannotBeEmpty => Error.Validation(nameof(RoleNameCannotBeEmpty));
|
||||
public static Error RoleNameMustBeMaximum50CharactersLong => Error.Validation(nameof(RoleNameMustBeMaximum50CharactersLong));
|
||||
public static Error RoleCategoryCannotBeEmpty => Error.Validation(nameof(RoleCategoryCannotBeEmpty));
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ using Mediator;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Controllers.Books;
|
||||
namespace Lumina.Presentation.Api.Core.Controllers.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for managing books.
|
||||
@@ -16,7 +16,7 @@ public class Program
|
||||
/// <summary>
|
||||
/// Application entry point.
|
||||
/// </summary>
|
||||
/// <param name="args">Optional command line arguments</param>
|
||||
/// <param name="args">Optional command line arguments.</param>
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
+56
-5
@@ -1314,13 +1314,13 @@ public class BooksControllerTests : IClassFixture<LuminaApiFactory>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddBook_WhenCalledWithEmptyContributorName_ShouldReturnBadRequest()
|
||||
public async Task AddBook_WhenCalledWithNullContributorName_ShouldReturnBadRequest()
|
||||
{
|
||||
// Arrange
|
||||
var bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = null } : contributor).ToList()
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = null! } : contributor).ToList()
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -1331,20 +1331,71 @@ public class BooksControllerTests : IClassFixture<LuminaApiFactory>
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthContributorName_ShouldReturnBadRequest()
|
||||
public async Task AddBook_WhenCalledWithEmptyContributorDisplayName_ShouldReturnBadRequest()
|
||||
{
|
||||
// Arrange
|
||||
var bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = new Faker().Random.String2(150) } : contributor).ToList()
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = string.Empty } } : contributor).ToList()
|
||||
};
|
||||
|
||||
// Act
|
||||
var response = await _client.PostAsJsonAsync("api/v1/books", bookRequest);
|
||||
|
||||
// Assert
|
||||
await AssertBadRequestWithValidationErrors(response, Errors.MediaContributor.ContributorNameMustBeMaximum100CharactersLong.Code);
|
||||
await AssertBadRequestWithValidationErrors(response, Errors.MediaContributor.ContributorDisplayNameCannotBeEmpty.Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddBook_WhenCalledWithNullContributorDisplayName_ShouldReturnBadRequest()
|
||||
{
|
||||
// Arrange
|
||||
var bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = null! } } : contributor).ToList()
|
||||
};
|
||||
|
||||
// Act
|
||||
var response = await _client.PostAsJsonAsync("api/v1/books", bookRequest);
|
||||
|
||||
// Assert
|
||||
await AssertBadRequestWithValidationErrors(response, Errors.MediaContributor.ContributorDisplayNameCannotBeEmpty.Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthContributorDisplayName_ShouldReturnBadRequest()
|
||||
{
|
||||
// Arrange
|
||||
var bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = new Faker().Random.String2(150) } } : contributor).ToList()
|
||||
};
|
||||
|
||||
// Act
|
||||
var response = await _client.PostAsJsonAsync("api/v1/books", bookRequest);
|
||||
|
||||
// Assert
|
||||
await AssertBadRequestWithValidationErrors(response, Errors.MediaContributor.ContributorDisplayNameMustBeMaximum100CharactersLong.Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddBook_WhenCalledWithInvalidLengthContributorLegalName_ShouldReturnBadRequest()
|
||||
{
|
||||
// Arrange
|
||||
var bookRequest = _requestBookFixture.CreateRequestBook();
|
||||
bookRequest = bookRequest with
|
||||
{
|
||||
Contributors = bookRequest.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { LegalName = new Faker().Random.String2(150) } } : contributor).ToList()
|
||||
};
|
||||
|
||||
// Act
|
||||
var response = await _client.PostAsJsonAsync("api/v1/books", bookRequest);
|
||||
|
||||
// Assert
|
||||
await AssertBadRequestWithValidationErrors(response, Errors.MediaContributor.ContributorLegalNameMustBeMaximum100CharactersLong.Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+14
-2
@@ -84,12 +84,20 @@ public class AddBookRequestFixture
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.Category, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
var mediaContributorName = new Faker<MediaContributorNameDto>()
|
||||
.CustomInstantiator(f => new MediaContributorNameDto(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.DisplayName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.LegalName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
var mediaContributor = new Faker<MediaContributorDto>()
|
||||
.CustomInstantiator(f => new MediaContributorDto(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.Name, mediaContributorName)
|
||||
.RuleFor(e => e.Role, mediaContributorRole);
|
||||
|
||||
var rating = new Faker<BookRatingDto>()
|
||||
@@ -319,8 +327,12 @@ public class AddBookRequestFixture
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<string>()
|
||||
));
|
||||
_fixture.Register(() => new MediaContributorDto(
|
||||
_fixture.Register(() => new MediaContributorNameDto(
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<string?>()
|
||||
));
|
||||
_fixture.Register(() => new MediaContributorDto(
|
||||
_fixture.Create<MediaContributorNameDto>(),
|
||||
_fixture.Create<MediaContributorRoleDto>()
|
||||
));
|
||||
}
|
||||
|
||||
+32
-4
@@ -1659,7 +1659,7 @@ public class AddBookCommandValidatorTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenCalledWithEmptyContributorName_ShouldHaveValidationError()
|
||||
public void Validate_WhenCalledWithNullContributorName_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
var bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
@@ -1673,17 +1673,45 @@ public class AddBookCommandValidatorTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenCalledWithInvalidLengthContributorName_ShouldHaveValidationError()
|
||||
public void Validate_WhenCalledWithInvalidLengthContributorDisplayName_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
var bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = new Faker().Random.String2(101) } : contributor).ToList() };
|
||||
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = new Faker().Random.String2(101) } } : contributor).ToList() };
|
||||
|
||||
// Act
|
||||
var result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Name").WithErrorMessage(Errors.MediaContributor.ContributorNameMustBeMaximum100CharactersLong.Code);
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Name.DisplayName").WithErrorMessage(Errors.MediaContributor.ContributorDisplayNameMustBeMaximum100CharactersLong.Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenCalledWithEmptyContributorDisplayName_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
var bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { DisplayName = null! } } : contributor).ToList() };
|
||||
|
||||
// Act
|
||||
var result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Name.DisplayName").WithErrorMessage(Errors.MediaContributor.ContributorDisplayNameCannotBeEmpty.Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenCalledWithInvalidLengthContributorLegalName_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
var bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
bookCommand = bookCommand with { Contributors = bookCommand.Contributors!.Select((contributor, index) => index == 0 ? contributor with { Name = contributor.Name! with { LegalName = new Faker().Random.String2(101) } } : contributor).ToList() };
|
||||
|
||||
// Act
|
||||
var result = _validator.TestValidate(bookCommand);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Contributors[0].Name.LegalName").WithErrorMessage(Errors.MediaContributor.ContributorLegalNameMustBeMaximum100CharactersLong.Code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+13
-3
@@ -83,13 +83,19 @@ public class AddBookCommandFixture
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.Category, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
var mediaContributorName = new Faker<MediaContributorNameDto>()
|
||||
.CustomInstantiator(f => new MediaContributorNameDto(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.DisplayName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.LegalName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
var mediaContributor = new Faker<MediaContributorDto>()
|
||||
.CustomInstantiator(f => new MediaContributorDto(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.Name, mediaContributorName)
|
||||
.RuleFor(e => e.Role, mediaContributorRole);
|
||||
|
||||
var rating = new Faker<BookRatingDto>()
|
||||
@@ -319,8 +325,12 @@ public class AddBookCommandFixture
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<string>()
|
||||
));
|
||||
_fixture.Register(() => new MediaContributorDto(
|
||||
_fixture.Register(() => new MediaContributorNameDto(
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<string?>()
|
||||
));
|
||||
_fixture.Register(() => new MediaContributorDto(
|
||||
_fixture.Create<MediaContributorNameDto>(),
|
||||
_fixture.Create<MediaContributorRoleDto>()
|
||||
));
|
||||
}
|
||||
|
||||
+2
-2
@@ -132,7 +132,7 @@ public class BookRepositoryTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllAsync_ShouldReturnAllBooks()
|
||||
public async Task GetAllAsync_WhenCalled_ShouldReturnAllBooks()
|
||||
{
|
||||
// Arrange
|
||||
var books = new List<BookDto>
|
||||
@@ -167,7 +167,7 @@ public class BookRepositoryTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllAsync_ShouldIncludeRelatedEntities()
|
||||
public async Task GetAllAsync_WhenCalled_ShouldIncludeRelatedEntities()
|
||||
{
|
||||
// Arrange
|
||||
var book = _bookDtoFixture.CreateBookDto();
|
||||
|
||||
Reference in new issue
Block a user