Refactors for correct media contributor name

This commit is contained in:
BinaryAlley committed 2024-09-02 19:44:18 +03:00
1 parent 1ee12d74a4
commit cb14ad19a7
11 files changed
+135 -23

No files matched your search

@@ -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]
@@ -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>()
));
}