Skip to content

Commit

Permalink
FEAT: File support components testing, cleanup and refactors. (#44)
Browse files Browse the repository at this point in the history
## Description
- Refactor FileService to remove remaining dependency on System.Drawing
- Fix BlobStorageService GetFileType() to use string.ToLower()
  - Add unit tests for GetFileType()
- Add unit tests to FileServiceTests
- Remove duplicate Trait declarations in test classes
- General tidy up
- Update packages

## Motivation and Context
#31 replaced System.Drawing implementation, however FileService still
had a dependency on System.Drawing for its Size class. As we are not
using any specific functionality from the Size class and are just using
it to represent data then we can replace it with a tuple.

Other changes in this PR are to:
- fix a bug with the GetFileType method that was not handling strings
with uppercase characters properly.
- correct some typos and apply consistent style in some areas
- add unit tests

## Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

## Checklist:
- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have read the **CONTRIBUTING** document.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
  • Loading branch information
matthewtoghill committed Mar 9, 2023
1 parent d963ea5 commit a8fa647
Show file tree
Hide file tree
Showing 46 changed files with 422 additions and 353 deletions.
4 changes: 3 additions & 1 deletion src/Content/Backend/Solution/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
"condition": "(!filesSupport)",
"exclude": [
"Monaco.Template.Backend.Common.BlobStorage/**/*",
"Monaco.Template.Backend.Common.BlobStorage.Tests/**/*",
"Monaco.Template.Backend.Api/Controllers/FilesController.cs",
"Monaco.Template.Backend.Api/Controllers/ImagesController.cs",
"Monaco.Template.Backend.Application/Features/File/**/*",
Expand Down Expand Up @@ -547,6 +548,7 @@
"5a3893d1-1e36-310c-7633-8f36ffa26315",
"a2689ae3-3643-6250-a748-8f055cc72da8",
"be447a08-0a85-5779-8c65-cf15c2c9a5a8",
"c776f397-182b-6d0d-09f2-4e440dc093d3"
"c776f397-182b-6d0d-09f2-4e440dc093d3",
"d8623b90-59c1-4753-a0e6-f2dbd4305c9b"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="6.0.3" />
<!--#if (massTransitIntegration)-->
<PackageReference Include="MassTransit.Azure.ServiceBus.Core" Version="8.0.12" />
<PackageReference Include="MassTransit.RabbitMQ" Version="8.0.12" />
<PackageReference Include="MassTransit.Azure.ServiceBus.Core" Version="8.0.13" />
<PackageReference Include="MassTransit.RabbitMQ" Version="8.0.13" />
<!--#endif-->
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
namespace Monaco.Template.Backend.Application.Tests.Features.Company.Commands;

[ExcludeFromCodeCoverage]
[Trait("Application Commands", "Company Commands")]
public class CompanyCommandsHandlersTests
{
[Trait("Application Commands", "Company Commands")]
[Theory(DisplayName = "Create new company succeeds")]
[AnonymousData]
public async Task CreateNewCompanySucceeds(Domain.Model.Country country)
Expand Down Expand Up @@ -48,7 +48,6 @@ public async Task CreateNewCompanySucceeds(Domain.Model.Country country)
result.ItemNotFound.Should().BeFalse();
}

[Trait("Application Commands", "Company Commands")]
[Theory(DisplayName = "Edit company succeeds")]
[AnonymousData]
public async Task EditCompanySucceeds(Domain.Model.Country country)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
namespace Monaco.Template.Backend.Application.Tests.Features.Company.Commands.Validators;

[ExcludeFromCodeCoverage]
[Trait("Application Validators", "Company Validators")]
public class CompanyCreateCommandValidatorTests
{
[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "Validator's rule level cascade mode is 'Stop'")]
public void ValidatorRuleLevelCascadeModeIsStop()
{
Expand All @@ -28,7 +28,6 @@ public void ValidatorRuleLevelCascadeModeIsStop()
sut.RuleLevelCascadeMode.Should().Be(CascadeMode.Stop);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "Name being valid does not generate validation error")]
public async Task NameDoesNotGenerateErrorWhenValid()
{
Expand All @@ -52,7 +51,6 @@ public async Task NameDoesNotGenerateErrorWhenValid()
validationResult.ShouldNotHaveValidationErrorFor(cmd => cmd.Name);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "Name with empty value generates validation error")]
public async Task NameIsEmptyGeneratesError()
{
Expand All @@ -74,7 +72,6 @@ public async Task NameIsEmptyGeneratesError()
.HaveCount(1);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "Name with long value generates validation error")]
public async Task NameWithLongValueGeneratesError()
{
Expand All @@ -97,7 +94,6 @@ public async Task NameWithLongValueGeneratesError()
.HaveCount(1);
}

[Trait("Application Validators", "Company Validators")]
[Theory(DisplayName = "Name which already exists generates validation error")]
[AnonymousData]
public async Task NameAlreadyExistsGeneratesError(Domain.Model.Company company)
Expand Down Expand Up @@ -125,7 +121,6 @@ public async Task NameAlreadyExistsGeneratesError(Domain.Model.Company company)
.HaveCount(1);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "Email being valid does not generate validation error")]
public async Task EmailIsValidDoesNotGenerateError()
{
Expand All @@ -149,7 +144,6 @@ public async Task EmailIsValidDoesNotGenerateError()
validationResult.ShouldNotHaveValidationErrorFor(cmd => cmd.Email);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "Email with empty value generates validation error")]
public async Task EmailIsEmptyGeneratesError()
{
Expand All @@ -171,7 +165,6 @@ public async Task EmailIsEmptyGeneratesError()
.HaveCount(1);
}

[Trait("Application Validators", "Company Validators")]
[Theory(DisplayName = "Email being invalid generates validation error")]
[AnonymousData]
public async Task EmailAddressIsInvalidGeneratesError(string email)
Expand All @@ -194,7 +187,6 @@ public async Task EmailAddressIsInvalidGeneratesError(string email)
.HaveCount(1);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "Website URL with long value generates validation error")]
public async Task WebsiteUrlWithLongValueGeneratesError()
{
Expand All @@ -217,7 +209,6 @@ public async Task WebsiteUrlWithLongValueGeneratesError()
.HaveCount(1);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "Website URL with empty value does not generate validation error")]
public async Task WebsiteUrlWithEmptyValueDoesNotGenerateError()
{
Expand All @@ -236,9 +227,8 @@ public async Task WebsiteUrlWithEmptyValueDoesNotGenerateError()
validationResult.ShouldNotHaveValidationErrorFor(cmd => cmd.WebSiteUrl);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "Street with long value generates validation error")]
public async Task AddressWithLongValueGeneratesError()
public async Task StreetWithLongValueGeneratesError()
{
var cmdMock = new Mock<CompanyCreateCommand>(It.IsAny<string>(), // Name
It.IsAny<string>(), // Email
Expand All @@ -259,9 +249,8 @@ public async Task AddressWithLongValueGeneratesError()
.HaveCount(1);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "Street with empty value does not generate validation error")]
public async Task AddressWithEmptyValueDoesNotGenerateError()
public async Task StreetWithEmptyValueDoesNotGenerateError()
{
var cmdMock = new Mock<CompanyCreateCommand>(It.IsAny<string>(), // Name
It.IsAny<string>(), // Email
Expand All @@ -278,7 +267,6 @@ public async Task AddressWithEmptyValueDoesNotGenerateError()
validationResult.ShouldNotHaveValidationErrorFor(cmd => cmd.Street);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "City with long value generates validation error")]
public async Task CityWithLongValueGeneratesError()
{
Expand All @@ -301,7 +289,6 @@ public async Task CityWithLongValueGeneratesError()
.HaveCount(1);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "City with empty value does not generate validation error")]
public async Task CityWithEmptyValueDoesNotGenerateError()
{
Expand All @@ -320,7 +307,6 @@ public async Task CityWithEmptyValueDoesNotGenerateError()
validationResult.ShouldNotHaveValidationErrorFor(cmd => cmd.City);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "County with long value generates validation error")]
public async Task CountyWithLongValueGeneratesError()
{
Expand All @@ -343,7 +329,6 @@ public async Task CountyWithLongValueGeneratesError()
.HaveCount(1);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "County with empty value does not generate validation error")]
public async Task CountyWithEmptyValueDoesNotGenerateError()
{
Expand All @@ -362,7 +347,6 @@ public async Task CountyWithEmptyValueDoesNotGenerateError()
validationResult.ShouldNotHaveValidationErrorFor(cmd => cmd.County);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "Postcode with long value generates validation error")]
public async Task PostcodeWithLongValueGeneratesError()
{
Expand All @@ -385,7 +369,6 @@ public async Task PostcodeWithLongValueGeneratesError()
.HaveCount(1);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "Postcode with empty value does not generate validation error")]
public async Task PostcodeWithEmptyValueDoesNotGenerateError()
{
Expand All @@ -404,7 +387,6 @@ public async Task PostcodeWithEmptyValueDoesNotGenerateError()
validationResult.ShouldNotHaveValidationErrorFor(cmd => cmd.PostCode);
}

[Trait("Application Validators", "Company Validators")]
[Theory(DisplayName = "Country being valid does not generate validation error")]
[AnonymousData(true)]
public async Task CountryIsValidDoesNotGenerateError(Domain.Model.Country country)
Expand Down Expand Up @@ -436,7 +418,6 @@ public async Task CountryIsValidDoesNotGenerateError(Domain.Model.Country countr
validationResult.ShouldNotHaveValidationErrorFor(cmd => cmd.CountryId);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "Country with null value does not generate validation error when Address fields null")]
public async Task CountryWithNullValueDoesNotGenerateErrorWhenAddressFieldsNull()
{
Expand All @@ -459,7 +440,6 @@ public async Task CountryWithNullValueDoesNotGenerateErrorWhenAddressFieldsNull(
validationResult.ShouldNotHaveValidationErrorFor(cmd => cmd.CountryId);
}

[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "Country with null value generates validation error when Address fields present")]
public async Task CountryWithNullValueGeneratesErrorWhenAddressFieldsPresent()
{
Expand All @@ -482,7 +462,6 @@ public async Task CountryWithNullValueGeneratesErrorWhenAddressFieldsPresent()
validationResult.ShouldHaveValidationErrorFor(cmd => cmd.CountryId);
}

[Trait("Application Validators", "Company Validators")]
[Theory(DisplayName = "Country that doesn't exist generates validation error")]
[AnonymousData]
public async Task CountryMustExistValidation(Domain.Model.Country country)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
namespace Monaco.Template.Backend.Application.Tests.Features.Company.Commands.Validators;

[ExcludeFromCodeCoverage]
[Trait("Application Validators", "Company Validators")]
public class CompanyDeleteCommandValidatorTests
{
[Trait("Application Validators", "Company Validators")]
[Fact(DisplayName = "Validator's rule level cascade mode is 'Stop'")]
public void ValidatorRuleLevelCascadeModeIsStop()
{
Expand All @@ -29,7 +29,6 @@ public void ValidatorRuleLevelCascadeModeIsStop()
sut.RuleLevelCascadeMode.Should().Be(CascadeMode.Stop);
}

[Trait("Application Validators", "Company Validators")]
[Theory(DisplayName = "Existing company passes validation correctly")]
[AnonymousData]
public async Task ExistingCompanyPassesValidationCorrectly(Domain.Model.Company company)
Expand All @@ -46,7 +45,6 @@ public async Task ExistingCompanyPassesValidationCorrectly(Domain.Model.Company
validationResult.ShouldNotHaveAnyValidationErrors();
}

[Trait("Application Validators", "Company Validators")]
[Theory(DisplayName = "Non existing company passes validation correctly")]
[AnonymousData]
public async Task NonExistingCompanyPassesValidationCorrectly(Domain.Model.Company company, Guid id)
Expand Down
Loading

0 comments on commit a8fa647

Please sign in to comment.