diff --git a/Directory.Packages.props b/Directory.Packages.props index 5ed6913..faacb81 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -11,12 +11,12 @@ - + - - + + - + @@ -27,12 +27,12 @@ - + - - + + diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5a458e2..af81d23 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -3,7 +3,7 @@ # Add steps that publish symbols, save build artifacts, deploy, and more: # https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4 -name: 4.15.0$(Rev:.r) +name: 4.15.1$(Rev:.r) trigger: - main diff --git a/src/Directory.Build.props b/src/Directory.Build.props index b063a85..2363903 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -3,7 +3,6 @@ - net8.0 enable enable true diff --git a/src/Mvp.Selections.Api/Mvp.Selections.Api.csproj b/src/Mvp.Selections.Api/Mvp.Selections.Api.csproj index 203e1f7..196d337 100644 --- a/src/Mvp.Selections.Api/Mvp.Selections.Api.csproj +++ b/src/Mvp.Selections.Api/Mvp.Selections.Api.csproj @@ -1,5 +1,6 @@  + net8.0 v4 Exe $(NoWarn);1591 diff --git a/src/Mvp.Selections.Api/Services/Interfaces/IMvpProfileService.cs b/src/Mvp.Selections.Api/Services/Interfaces/IMvpProfileService.cs index 3cbf3ff..65b93aa 100644 --- a/src/Mvp.Selections.Api/Services/Interfaces/IMvpProfileService.cs +++ b/src/Mvp.Selections.Api/Services/Interfaces/IMvpProfileService.cs @@ -8,6 +8,12 @@ namespace Mvp.Selections.Api.Services.Interfaces { public interface IMvpProfileService { + public const string TypeFacetIdentifier = "type"; + + public const string YearFacetIdentifier = "year"; + + public const string CountryFacetIdentifier = "country"; + Task> GetMvpProfileAsync(Guid id); Task> SearchMvpProfileAsync( diff --git a/src/Mvp.Selections.Api/Services/UserService.cs b/src/Mvp.Selections.Api/Services/UserService.cs index 02d5b0c..c6fdbca 100644 --- a/src/Mvp.Selections.Api/Services/UserService.cs +++ b/src/Mvp.Selections.Api/Services/UserService.cs @@ -378,7 +378,7 @@ public async Task> ClearIndexAsync() private static SearchFacet CalculateYearFacet(IEnumerable profiles) { - SearchFacet result = new() { Identifier = "year" }; + SearchFacet result = new() { Identifier = IMvpProfileService.YearFacetIdentifier }; foreach (Title title in profiles.SelectMany(p => p.Titles)) { string key = title.Application.Selection.Year.ToString(); @@ -393,7 +393,7 @@ private static SearchFacet CalculateYearFacet(IEnumerable profiles) private static SearchFacet CalculateTypeFacet(IReadOnlyCollection profiles) { - SearchFacet result = new() { Identifier = "type" }; + SearchFacet result = new() { Identifier = IMvpProfileService.TypeFacetIdentifier }; List distinctTypes = profiles .SelectMany(p => p.Titles.Select(t => t.MvpType)) .Distinct(new IdEqualityComparer()) @@ -414,7 +414,7 @@ from _ in profiles private static SearchFacet CalculateCountryFacet(IEnumerable profiles) { - SearchFacet result = new() { Identifier = "country" }; + SearchFacet result = new() { Identifier = IMvpProfileService.CountryFacetIdentifier }; foreach (Country? country in profiles.Select(p => p.Country)) { if (country != null && !result.Options.TryAdd(country.Id.ToString(), new SearchFacetOption { Identifier = country.Id.ToString(), Display = country.Name, Count = 1 }, o => o.Identifier)) diff --git a/src/Mvp.Selections.Client/Mvp.Selections.Client.csproj b/src/Mvp.Selections.Client/Mvp.Selections.Client.csproj index 1ed0b40..a8de9b9 100644 --- a/src/Mvp.Selections.Client/Mvp.Selections.Client.csproj +++ b/src/Mvp.Selections.Client/Mvp.Selections.Client.csproj @@ -1,6 +1,7 @@  + net8.0 MVP Selections API Client sc-ivanlieckens Sitecore diff --git a/src/Mvp.Selections.Data/Mvp.Selections.Data.csproj b/src/Mvp.Selections.Data/Mvp.Selections.Data.csproj index 0042028..5391d65 100644 --- a/src/Mvp.Selections.Data/Mvp.Selections.Data.csproj +++ b/src/Mvp.Selections.Data/Mvp.Selections.Data.csproj @@ -1,6 +1,7 @@  + net8.0 $(NoWarn);1591 diff --git a/src/Mvp.Selections.Data/Repositories/UserRepository.cs b/src/Mvp.Selections.Data/Repositories/UserRepository.cs index 36e9ffb..c6b87a7 100644 --- a/src/Mvp.Selections.Data/Repositories/UserRepository.cs +++ b/src/Mvp.Selections.Data/Repositories/UserRepository.cs @@ -193,7 +193,7 @@ private IQueryable GetWithTitleQuery( if (countryIds != null) { - query = countryIds.Aggregate(query, (current, id) => current.Where(u => u.Applications.Where(a => a.Title != null).Any(a => a.Country.Id == id))); + query = countryIds.Aggregate(query, (current, id) => current.Where(u => u.Applications.Where(a => a.Title != null).Any(a => a.Country.Id == id) || u.Country!.Id == id)); } return query diff --git a/src/Mvp.Selections.Domain/Mvp.Selections.Domain.csproj b/src/Mvp.Selections.Domain/Mvp.Selections.Domain.csproj index bd26e52..1f415c3 100644 --- a/src/Mvp.Selections.Domain/Mvp.Selections.Domain.csproj +++ b/src/Mvp.Selections.Domain/Mvp.Selections.Domain.csproj @@ -1,6 +1,7 @@  + net8.0 $(NoWarn);1591 diff --git a/tests/Mvp.Selections.Api.Tests/Services/UserServiceTests.cs b/tests/Mvp.Selections.Api.Tests/Services/UserServiceTests.cs new file mode 100644 index 0000000..463441d --- /dev/null +++ b/tests/Mvp.Selections.Api.Tests/Services/UserServiceTests.cs @@ -0,0 +1,65 @@ +using AutoFixture.Xunit2; +using FluentAssertions; +using Mvp.Selections.Api.Cache; +using Mvp.Selections.Api.Model; +using Mvp.Selections.Api.Model.Request; +using Mvp.Selections.Api.Services; +using Mvp.Selections.Api.Services.Interfaces; +using Mvp.Selections.Domain; +using Mvp.Selections.Tests.Utilities; +using NSubstitute; +using Xunit; + +namespace Mvp.Selections.Api.Tests.Services +{ + public class UserServiceTests + { + [Theory] + [AutoNSubstituteData] + public async Task SearchMvpProfileAsync_FacetCountValidation([Frozen] ICacheManager cache, UserService sut, MvpProfile mvp1, MvpProfile mvp2, MvpProfile mvp3, Country country1, Country country2, MvpType type1) + { + // Arrange + mvp1.Country = country1; + mvp1.Titles.Clear(); + mvp1.Titles.Add(new Title(Guid.NewGuid()) + { + MvpType = type1, + Application = new Application(Guid.NewGuid()) + { Selection = new Selection(Guid.NewGuid()) { Year = 1800 } } + }); + + mvp2.Country = country1; + mvp2.Titles.Clear(); + mvp2.Titles.Add(new Title(Guid.NewGuid()) + { + MvpType = type1, + Application = new Application(Guid.NewGuid()) + { Selection = new Selection(Guid.NewGuid()) { Year = 1801 } } + }); + + mvp3.Country = country2; + mvp3.Titles.Clear(); + mvp3.Titles.Add(new Title(Guid.NewGuid()) + { + MvpType = type1, + Application = new Application(Guid.NewGuid()) + { Selection = new Selection(Guid.NewGuid()) { Year = 1803 } } + }); + + cache.TryGet(Arg.Any(), out Arg.Any?>()).Returns(x => + { + x[1] = new List { mvp1, mvp2, mvp3 }; + return true; + }); + + // Act + SearchOperationResult result = await sut.SearchMvpProfileAsync(); + + // Assert + result.Result.TotalResults.Should().Be(3); + result.Result.Facets.Single(f => f.Identifier == IMvpProfileService.CountryFacetIdentifier).Options.Should().HaveCount(2); + result.Result.Facets.Single(f => f.Identifier == IMvpProfileService.TypeFacetIdentifier).Options.Should().HaveCount(1); + result.Result.Facets.Single(f => f.Identifier == IMvpProfileService.YearFacetIdentifier).Options.Should().HaveCount(3); + } + } +}