Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public IEndpointRouteBuilder AddCompanies(ApiVersionSet versionSet)
"Companies");

companies.MapGet("",
Task<Results<Ok<Page<CompanyDto>>, NotFound>> ([FromServices] ISender sender,
HttpRequest request,
CancellationToken cancellationToken) =>
sender.ExecuteQueryAsync(new GetCompanyPage.Query(request.Query),
cancellationToken),
Task<Results<Ok<Page<CompanyDto>>, NotFound, ValidationProblem>> ([FromServices] ISender sender,
HttpRequest request,
CancellationToken cancellationToken) =>
sender.ExecutePagedQueryAsync(new GetCompanyPage.Query(request.Query),
cancellationToken),
"GetCompanies",
#if (!auth)
"Gets a page of companies");
Expand All @@ -39,9 +39,9 @@ public IEndpointRouteBuilder AddCompanies(ApiVersionSet versionSet)
#endif

companies.MapGet("{id:guid}",
Task<Results<Ok<CompanyDto?>, NotFound>> ([FromServices] ISender sender,
[FromRoute] Guid id,
CancellationToken cancellationToken) =>
Task<Results<Ok<CompanyDto>, NotFound, ValidationProblem>> ([FromServices] ISender sender,
[FromRoute] Guid id,
CancellationToken cancellationToken) =>
sender.ExecuteQueryAsync(new GetCompanyById.Query(id),
cancellationToken),
"GetCompany",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public IEndpointRouteBuilder AddCountries(ApiVersionSet versionSet)
var countries = builder.CreateApiGroupBuilder(versionSet, "Countries");

countries.MapGet("",
Task<Results<Ok<List<CountryDto>>, NotFound>> ([FromServices] ISender sender,
HttpRequest request) =>
Task<Results<Ok<List<CountryDto>>, NotFound, ValidationProblem>> ([FromServices] ISender sender,
HttpRequest request) =>
sender.ExecuteQueryAsync(new GetCountryList.Query(request.Query)),
"GetCountries",
"Gets a list of countries");

countries.MapGet("{id:guid}",
Task<Results<Ok<CountryDto?>, NotFound>> ([FromServices] ISender sender,
[FromRoute] Guid id) =>
Task<Results<Ok<CountryDto>, NotFound, ValidationProblem>> ([FromServices] ISender sender,
[FromRoute] Guid id) =>
sender.ExecuteQueryAsync(new GetCountryById.Query(id)),
"GetCountry",
"Gets a country by Id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public IEndpointRouteBuilder AddProducts(ApiVersionSet versionSet)
"Products");

products.MapGet("",
Task<Results<Ok<Page<ProductDto>>, NotFound>> ([FromServices] ISender sender,
HttpRequest request,
CancellationToken cancellationToken) =>
Task<Results<Ok<Page<ProductDto>>, NotFound, ValidationProblem>> ([FromServices] ISender sender,
HttpRequest request,
CancellationToken cancellationToken) =>
sender.ExecuteQueryAsync(new GetProductPage.Query(request.Query),
cancellationToken),
"GetProducts",
Expand All @@ -39,9 +39,9 @@ public IEndpointRouteBuilder AddProducts(ApiVersionSet versionSet)
#endif

products.MapGet("{id:guid}",
Task<Results<Ok<ProductDto?>, NotFound>> ([FromServices] ISender sender,
[FromRoute] Guid id,
CancellationToken cancellationToken) =>
Task<Results<Ok<ProductDto>, NotFound, ValidationProblem>> ([FromServices] ISender sender,
[FromRoute] Guid id,
CancellationToken cancellationToken) =>
sender.ExecuteQueryAsync(new GetProductById.Query(id),
cancellationToken),
"GetProduct",
Expand Down Expand Up @@ -99,11 +99,11 @@ public IEndpointRouteBuilder AddProducts(ApiVersionSet versionSet)
#endif

products.MapGet("{productId:guid}/Pictures/{pictureId:guid}",
Task<Results<FileStreamHttpResult, NotFound>> ([FromServices] ISender sender,
[FromRoute] Guid productId,
[FromRoute] Guid pictureId,
HttpRequest request,
CancellationToken cancellationToken) =>
Task<Results<FileStreamHttpResult, NotFound, ValidationProblem>> ([FromServices] ISender sender,
[FromRoute] Guid productId,
[FromRoute] Guid pictureId,
HttpRequest request,
CancellationToken cancellationToken) =>
sender.ExecuteFileDownloadAsync(new DownloadProductPicture.Query(productId,
pictureId,
request.Query),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Monaco.Template.Backend.Domain.Tests.Factories.Entities;
using Moq;
using System.Diagnostics.CodeAnalysis;
using Monaco.Template.Backend.Application.Features.Company.DTOs;
using Monaco.Template.Backend.Common.Application.Queries;
using Xunit;

namespace Monaco.Template.Backend.Application.Tests.Features.Company;
Expand All @@ -27,9 +29,11 @@ public async Task GetExistingCompanyByIdSucceeds()
var sut = new GetCompanyById.Handler(_dbContextMock.Object);
var result = await sut.Handle(query, CancellationToken.None);

result.Should()
.NotBeNull();
result!.Name
var success = result.Should()
.BeOfType<Success<CompanyDto>>();
success.Subject
.Result
.Name
.Should()
.Be(company.Name);
}
Expand All @@ -45,6 +49,6 @@ public async Task GetNonExistingCompanyByIdFails()
var result = await sut.Handle(query, CancellationToken.None);

result.Should()
.BeNull();
.BeOfType<NotFound<CompanyDto>>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Monaco.Template.Backend.Application.Features.Company;
using Monaco.Template.Backend.Application.Features.Company.DTOs;
using Monaco.Template.Backend.Application.Persistence;
using Monaco.Template.Backend.Common.Application.Queries;
using Monaco.Template.Backend.Common.Domain.Model;
using Monaco.Template.Backend.Common.Tests;
using Monaco.Template.Backend.Domain.Tests.Factories;
using Moq;
Expand All @@ -23,22 +25,28 @@ public async Task GetCompanyPageWithoutParamsSucceeds(List<Domain.Model.Entities
{
_dbContextMock.CreateAndSetupDbSetMock(companies);

var query = new GetCompanyPage.Query(new List<KeyValuePair<string, StringValues>>());
var query = new GetCompanyPage.Query([]);

var sut = new GetCompanyPage.Handler(_dbContextMock.Object);
var result = await sut.Handle(query, CancellationToken.None);

result.Should()
.NotBeNull();
result!.Pager
var success = result.Should()
.BeOfType<Success<Page<CompanyDto>>>();

success.Subject
.Result
.Pager
.Count
.Should()
.Be(companies.Count);
result.Items
.Should()
.HaveCount(companies.Count).And
.Contain(x => companies.Any(c => c.Name == x.Name)).And
.BeInAscendingOrder(x => x.Name);

success.Subject
.Result
.Items
.Should()
.HaveCount(companies.Count).And
.Contain(x => companies.Any(c => c.Name == x.Name)).And
.BeInAscendingOrder(x => x.Name);
}

[Theory(DisplayName = "Get company page with params succeeds")]
Expand All @@ -50,8 +58,7 @@ public async Task GetCompanyPageWithParamsSucceeds(List<Domain.Model.Entities.Co
var queryString = new List<KeyValuePair<string, StringValues>>
{
new(nameof(CompanyDto.Name),
new(companiesSet.Select(x => x.Name)
.ToArray())),
new([..companiesSet.Select(x => x.Name)])),
new("expand", nameof(CompanyDto.Country)),
new("sort", $"-{nameof(CompanyDto.Name)}")
};
Expand All @@ -61,16 +68,22 @@ public async Task GetCompanyPageWithParamsSucceeds(List<Domain.Model.Entities.Co
var sut = new GetCompanyPage.Handler(_dbContextMock.Object);
var result = await sut.Handle(query, CancellationToken.None);

result.Should()
.NotBeNull();
result!.Pager
var success = result.Should()
.BeOfType<Success<Page<CompanyDto>>>();

success.Subject
.Result
.Pager
.Count
.Should()
.Be(companiesSet.Count);
result.Items
.Should()
.HaveCount(companiesSet.Count).And
.Contain(x => companiesSet.Any(c => c.Name == x.Name)).And
.BeInDescendingOrder(x => x.Name);

success.Subject
.Result
.Items
.Should()
.HaveCount(companiesSet.Count).And
.Contain(x => companiesSet.Any(c => c.Name == x.Name)).And
.BeInDescendingOrder(x => x.Name);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using AwesomeAssertions;
using Monaco.Template.Backend.Application.Features.Country;
using Monaco.Template.Backend.Application.Features.Country.DTOs;
using Monaco.Template.Backend.Application.Persistence;
using Monaco.Template.Backend.Common.Application.Queries;
using Monaco.Template.Backend.Common.Tests;
using Monaco.Template.Backend.Domain.Tests.Factories.Entities;
using Moq;
Expand All @@ -27,9 +29,12 @@ public async Task GetExistingCountryByIdSucceeds()
var sut = new GetCountryById.Handler(_dbContextMock.Object);
var result = await sut.Handle(query, CancellationToken.None);

result.Should()
.NotBeNull();
result!.Name
var success = result.Should()
.BeOfType<Success<CountryDto>>();

success.Subject
.Result
.Name
.Should()
.Be(country.Name);
}
Expand All @@ -44,6 +49,6 @@ public async Task GetNonExistingCountryByIdFails()
var result = await sut.Handle(query, CancellationToken.None);

result.Should()
.BeNull();
.BeOfType<NotFound<CountryDto>>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Monaco.Template.Backend.Application.Features.Country;
using Monaco.Template.Backend.Application.Features.Country.DTOs;
using Monaco.Template.Backend.Application.Persistence;
using Monaco.Template.Backend.Common.Application.Queries;
using Monaco.Template.Backend.Common.Tests;
using Monaco.Template.Backend.Domain.Tests.Factories;
using Moq;
Expand All @@ -23,15 +24,20 @@ public async Task GetCountryListWithoutParamsSucceeds(List<Domain.Model.Entities
{
_dbContextMock.CreateAndSetupDbSetMock(countries);

var query = new GetCountryList.Query(new List<KeyValuePair<string, StringValues>>());
var query = new GetCountryList.Query([]);

var sut = new GetCountryList.Handler(_dbContextMock.Object);
var result = await sut.Handle(query, CancellationToken.None);

result.Should()
.HaveCount(countries.Count).And
.Contain(x => countries.Any(c => c.Name == x.Name)).And
.BeInAscendingOrder(x => x.Name);
var success = result.Should()
.BeOfType<Success<List<CountryDto>>>();

success.Subject
.Result
.Should()
.HaveCount(countries.Count).And
.Contain(x => countries.Any(c => c.Name == x.Name)).And
.BeInAscendingOrder(x => x.Name);
}

[Theory(DisplayName = "Get country list with params succeeds")]
Expand All @@ -44,7 +50,7 @@ public async Task GetCountryListWithParamsSucceeds(List<Domain.Model.Entities.Co
var queryString = new List<KeyValuePair<string, StringValues>>
{
new(nameof(CountryDto.Name),
new(countriesSet.Select(x => x.Name).ToArray())),
new([..countriesSet.Select(x => x.Name)])),
new("sort", $"-{nameof(CountryDto.Name)}")
};

Expand All @@ -54,9 +60,14 @@ public async Task GetCountryListWithParamsSucceeds(List<Domain.Model.Entities.Co

var result = await sut.Handle(query, CancellationToken.None);

result.Should()
.HaveCount(countriesSet.Count).And
.Contain(x => countriesSet.Any(c => c.Name == x.Name)).And
.BeInDescendingOrder(x => x.Name);
var success = result.Should()
.BeOfType<Success<List<CountryDto>>>();

success.Subject
.Result
.Should()
.HaveCount(countriesSet.Count).And
.Contain(x => countriesSet.Any(c => c.Name == x.Name)).And
.BeInDescendingOrder(x => x.Name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Monaco.Template.Backend.Application.Persistence;
using Monaco.Template.Backend.Application.Services.Contracts;
using Monaco.Template.Backend.Common.Application.DTOs;
using Monaco.Template.Backend.Common.Application.Queries;
using Monaco.Template.Backend.Common.Tests;
using Monaco.Template.Backend.Domain.Tests.Factories;
using Moq;
Expand All @@ -25,7 +26,7 @@ public async Task GetExistingProductPictureSucceeds(List<Domain.Model.Entities.P
_dbContextMock.CreateAndSetupDbSetMock(products);

var product = products.First();
var picture = product.Pictures.First();
var picture = product.Pictures[0];
var pictureFileName = $"{picture.Name}{picture.Extension}";

_fileServiceMock.Setup(x => x.DownloadFileAsync(It.IsAny<Domain.Model.Entities.File>(),
Expand All @@ -41,9 +42,12 @@ public async Task GetExistingProductPictureSucceeds(List<Domain.Model.Entities.P
var sut = new DownloadProductPicture.Handler(_dbContextMock.Object, _fileServiceMock.Object);
var result = await sut.Handle(query, CancellationToken.None);

result.Should()
.NotBeNull();
result!.FileName
var success = result.Should()
.BeOfType<Success<FileDownloadDto>>();

success.Subject
.Result
.FileName
.Should()
.Be(pictureFileName);
}
Expand All @@ -55,7 +59,7 @@ public async Task GetExistingProductPictureThumbnailSucceeds(Domain.Model.Entiti
_dbContextMock.CreateAndSetupDbSetMock(products);

var product = products.First();
var picture = product.Pictures.First();
var picture = product.Pictures[0];
var pictureFileName = $"{picture.Name}{picture.Extension}";

_fileServiceMock.Setup(x => x.DownloadFileAsync(It.IsAny<Domain.Model.Entities.File>(), It.IsAny<CancellationToken>()))
Expand All @@ -70,9 +74,12 @@ public async Task GetExistingProductPictureThumbnailSucceeds(Domain.Model.Entiti
var sut = new DownloadProductPicture.Handler(_dbContextMock.Object, _fileServiceMock.Object);
var result = await sut.Handle(query, CancellationToken.None);

result.Should()
.NotBeNull();
result!.FileName
var success = result.Should()
.BeOfType<Success<FileDownloadDto>>();

success.Subject
.Result
.FileName
.Should()
.Be(pictureFileName);
}
Expand All @@ -90,6 +97,6 @@ public async Task GetNonExistingProductByIdFails(List<Domain.Model.Entities.Prod
var result = await sut.Handle(query, CancellationToken.None);

result.Should()
.BeNull();
.BeOfType<NotFound<FileDownloadDto>>();
}
}
Loading