Skip to content

Commit

Permalink
ProfileLinkService Validation (#63)
Browse files Browse the repository at this point in the history
+ Add and Remove validation improvement
+ Unit tests for API added
+ Global package versions and source mapping
+ Bumped StyleCop to beta to support new C# syntax as per
DotNetAnalyzers/StyleCopAnalyzers#3871
+ Restructured Solution

---------

Co-authored-by: Ivan Lieckens <[email protected]>
  • Loading branch information
sc-ivanlieckens and IvanLieckens authored Jul 4, 2024
1 parent 89ef462 commit 15d7dbf
Show file tree
Hide file tree
Showing 120 changed files with 1,385 additions and 743 deletions.
117 changes: 117 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Auto detect text files and perform LF normalization
* text=auto

# Common
*.bibtex text diff=bibtex
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
*.md text diff=markdown
*.mdx text diff=markdown
*.tex text diff=tex
*.adoc text
*.textile text
*.mustache text
*.csv text eol=crlf
*.tab text
*.tsv text
*.txt text
*.sql text
*.epub diff=astextplain

*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.tif binary
*.tiff binary
*.ico binary
*.svg text
*.eps binary

*.bash text eol=lf
*.fish text eol=lf
*.ksh text eol=lf
*.sh text eol=lf
*.zsh text eol=lf
*.bat text eol=crlf
*.cmd text eol=crlf

*.json text
*.toml text
*.xml text
*.yaml text
*.yml text

*.7z binary
*.bz binary
*.bz2 binary
*.bzip2 binary
*.gz binary
*.lz binary
*.lzma binary
*.rar binary
*.tar binary
*.taz binary
*.tbz binary
*.tbz2 binary
*.tgz binary
*.tlz binary
*.txz binary
*.xz binary
*.Z binary
*.zip binary
*.zst binary

*.patch -text

.gitattributes export-ignore
.gitignore export-ignore
.gitkeep export-ignore

# CSharp
*.cs text diff=csharp
*.cshtml text diff=html
*.csx text diff=csharp

# VisualStudio
*.sln text eol=crlf
*.csproj text eol=crlf
*.vbproj text eol=crlf
*.vcxproj text eol=crlf
*.vcproj text eol=crlf
*.dbproj text eol=crlf
*.fsproj text eol=crlf
*.lsproj text eol=crlf
*.wixproj text eol=crlf
*.modelproj text eol=crlf
*.sqlproj text eol=crlf
*.wwaproj text eol=crlf

*.xproj text eol=crlf
*.props text eol=crlf
*.filters text eol=crlf
*.vcxitems text eol=crlf

# VSCode
.vscode/*.json linguist-language=JSON-with-Comments

# MarkDown
*.md linguist-detectable

# PowerShell
*.ps1 text eol=crlf
*.ps1x text eol=crlf
*.psm1 text eol=crlf
*.psd1 text eol=crlf
*.ps1xml text eol=crlf
*.pssc text eol=crlf
*.psrc text eol=crlf
*.cdxml text eol=crlf
44 changes: 44 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<!-- Further info https://learn.microsoft.com/en-us/nuget/consume-packages/Central-Package-Management -->
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup Label="Primary Package References">
<PackageVersion Include="LinqKit.Microsoft.EntityFrameworkCore" Version="8.1.5" />
<PackageVersion Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker" Version="1.22.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.3.2" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.2" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.2.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup Label="Test Package References">
<PackageVersion Include="AutoFixture.AutoNSubstitute" Version="4.18.1" />
<PackageVersion Include="AutoFixture.Xunit2" Version="4.18.1" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="FluentAssertions.Analyzers" Version="0.32.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
<PackageVersion Include="NSubstitute.Analyzers.CSharp" Version="1.0.17" />
<PackageVersion Include="xunit" Version="2.8.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.1" />
</ItemGroup>

<ItemGroup Label="Global Project Tooling">
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</GlobalPackageReference>
</ItemGroup>
</Project>
44 changes: 42 additions & 2 deletions Mvp.Selections.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,38 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mvp.Selections.Data", "src\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mvp.Selections.Client", "src\Mvp.Selections.Client\Mvp.Selections.Client.csproj", "{6F2CA521-59C0-4C32-BD75-84872141B041}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mvp.Selections.Client.Tests", "src\Mvp.Selections.Client.Tests\Mvp.Selections.Client.Tests.csproj", "{2E61EE99-219F-4244-BF74-471432C290D2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mvp.Selections.Client.Tests", "tests\Mvp.Selections.Client.Tests\Mvp.Selections.Client.Tests.csproj", "{2E61EE99-219F-4244-BF74-471432C290D2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{44AD4EFD-07A6-4019-BD62-15AB92B8EE27}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mvp.Selections.Api.Tests", "tests\Mvp.Selections.Api.Tests\Mvp.Selections.Api.Tests.csproj", "{F99BD677-34A3-4581-B170-BEFC39F6EB4D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D94E8EAB-0B65-4DF5-98FA-DEDA6632748D}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
azure-pipelines.yml = azure-pipelines.yml
CODEOWNERS = CODEOWNERS
CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md
CONTRIBUTING.md = CONTRIBUTING.md
Directory.Packages.props = Directory.Packages.props
LICENSE = LICENSE
Mvp.Selections.sln.DotSettings = Mvp.Selections.sln.DotSettings
nuget.config = nuget.config
README.MD = README.MD
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{810BB955-EF99-40E4-8B33-C5763DB5C2BA}"
ProjectSection(SolutionItems) = preProject
src\Directory.Build.props = src\Directory.Build.props
src\GlobalSuppressions.cs = src\GlobalSuppressions.cs
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{46CA5BC3-AB6D-4A7F-A9E7-5C05575326C3}"
ProjectSection(SolutionItems) = preProject
tests\Directory.Build.props = tests\Directory.Build.props
tests\Tests.GlobalSuppressions.cs = tests\Tests.GlobalSuppressions.cs
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mvp.Selections.Tests", "tests\Mvp.Selections.Tests\Mvp.Selections.Tests.csproj", "{81F18073-C2DC-408A-B0DE-C1553D1A0572}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -46,10 +69,27 @@ Global
{2E61EE99-219F-4244-BF74-471432C290D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E61EE99-219F-4244-BF74-471432C290D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E61EE99-219F-4244-BF74-471432C290D2}.Release|Any CPU.Build.0 = Release|Any CPU
{F99BD677-34A3-4581-B170-BEFC39F6EB4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F99BD677-34A3-4581-B170-BEFC39F6EB4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F99BD677-34A3-4581-B170-BEFC39F6EB4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F99BD677-34A3-4581-B170-BEFC39F6EB4D}.Release|Any CPU.Build.0 = Release|Any CPU
{81F18073-C2DC-408A-B0DE-C1553D1A0572}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{81F18073-C2DC-408A-B0DE-C1553D1A0572}.Debug|Any CPU.Build.0 = Debug|Any CPU
{81F18073-C2DC-408A-B0DE-C1553D1A0572}.Release|Any CPU.ActiveCfg = Release|Any CPU
{81F18073-C2DC-408A-B0DE-C1553D1A0572}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{C5523733-D713-4E1B-A39E-740173E5B254} = {810BB955-EF99-40E4-8B33-C5763DB5C2BA}
{A9C3A0C5-DE71-4C34-9690-2C4BBFD18422} = {810BB955-EF99-40E4-8B33-C5763DB5C2BA}
{EFFE2B80-B96F-45AC-83E1-82C5FBAFE8BE} = {810BB955-EF99-40E4-8B33-C5763DB5C2BA}
{6F2CA521-59C0-4C32-BD75-84872141B041} = {810BB955-EF99-40E4-8B33-C5763DB5C2BA}
{2E61EE99-219F-4244-BF74-471432C290D2} = {46CA5BC3-AB6D-4A7F-A9E7-5C05575326C3}
{F99BD677-34A3-4581-B170-BEFC39F6EB4D} = {46CA5BC3-AB6D-4A7F-A9E7-5C05575326C3}
{81F18073-C2DC-408A-B0DE-C1553D1A0572} = {46CA5BC3-AB6D-4A7F-A9E7-5C05575326C3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A4289E92-B572-42B5-AD90-A1620E797AC5}
EndGlobalSection
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.14.2$(Rev:.r)
name: 4.15.0$(Rev:.r)

trigger:
- main
Expand Down
9 changes: 9 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>

<packageSourceMapping>
<packageSource key="Nuget">
<package pattern="*" />
</packageSource>
<packageSource key="Sitecore">
<package pattern="Sitecore.*" />
</packageSource>
</packageSourceMapping>
</configuration>
18 changes: 18 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project>

<!--<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />-->

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup Label="Shared Assets">
<Compile Include="$(MSBuildThisFileDirectory)GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1010:Opening square brackets should be spaced correctly", Justification = "New collection expression.")]
[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1011:Closing square brackets should be spaced correctly", Justification = "Nullability information.")]
[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this", Justification = "This creates code clutter.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:Using directives should be placed correctly", Justification = "Not required.")]
[assembly: SuppressMessage("StyleCop.CSharp.NamingRules", "SA1309:Field names should not begin with underscore", Justification = "Private field names should start with underscore.")]
[assembly: SuppressMessage("StyleCop.CSharp.NamingRules", "SA1312:Variable names must begin with lower case letter", Justification = "Discard variable is single _ and private variables can start with _.")]
[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1010:Opening square brackets should be spaced correctly", Justification = "New collection notation.")]
[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1011:Closing square brackets should be spaced correctly", Justification = "New collection notation.")]
[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this", Justification = "Not required.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:Using directives should be placed correctly", Justification = "Type confusion should not occur.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1206:Declaration keywords should follow order", Justification = "ReSharper ordering rules used.")]
[assembly: SuppressMessage("StyleCop.CSharp.NamingRules", "SA1309:Field names should not begin with underscore", Justification = "Underscores are used for private class variables.")]
[assembly: SuppressMessage("StyleCop.CSharp.NamingRules", "SA1312:Variable names must begin with lower case letter", Justification = "Underscores are used as discard variables.")]
[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1413:Use trailing comma in multi-line initializers", Justification = "Not required.")]
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "Not required.")]
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "Not required.")]
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1602:Enumeration items should be documented", Justification = "Enum values should be clear.")]
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1602:Enumeration items should be documented", Justification = "Not required.")]
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "No headers required.")]
2 changes: 1 addition & 1 deletion src/Mvp.Selections.Api/Applicants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Task<IActionResult> GetAll(
{
return ExecuteSafeSecurityValidatedAsync(req, [Right.Admin, Right.Review], async authResult =>
{
ListParameters lp = new (req);
ListParameters lp = new(req);
IList<Applicant> applicants = await applicantService.GetApplicantsAsync(authResult.User!, selectionId, lp.Page, lp.PageSize);
return ContentResult(applicants, ApplicantsContractResolver.Instance);
});
Expand Down
8 changes: 4 additions & 4 deletions src/Mvp.Selections.Api/Applications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Task<IActionResult> GetAll(
{
return ExecuteSafeSecurityValidatedAsync(req, [Right.Admin, Right.Apply, Right.Review], async authResult =>
{
ListParameters lp = new (req);
ListParameters lp = new(req);
Guid? userId = req.Query.GetFirstValueOrDefault<Guid?>(UserIdQueryStringKey);
string? userName = req.Query.GetFirstValueOrDefault<string>(ApplicantNameQueryStringKey);
Guid? selectionId = req.Query.GetFirstValueOrDefault<Guid?>(SelectionIdQueryStringKey);
Expand All @@ -70,7 +70,7 @@ public Task<IActionResult> GetAllForSelection(
{
return ExecuteSafeSecurityValidatedAsync(req, [Right.Admin, Right.Apply, Right.Review], async authResult =>
{
ListParameters lp = new (req);
ListParameters lp = new(req);
Guid? userId = req.Query.GetFirstValueOrDefault<Guid?>(UserIdQueryStringKey);
string? userName = req.Query.GetFirstValueOrDefault<string>(ApplicantNameQueryStringKey);
short? countryId = req.Query.GetFirstValueOrDefault<short?>(CountryIdQueryStringKey);
Expand All @@ -89,7 +89,7 @@ public Task<IActionResult> GetAllForCountry(
{
return ExecuteSafeSecurityValidatedAsync(req, [Right.Admin, Right.Review], async authResult =>
{
ListParameters lp = new (req);
ListParameters lp = new(req);
Guid? userId = req.Query.GetFirstValueOrDefault<Guid?>(UserIdQueryStringKey);
string? userName = req.Query.GetFirstValueOrDefault<string>(ApplicantNameQueryStringKey);
ApplicationStatus? status = req.Query.GetFirstValueOrDefault<ApplicationStatus?>(StatusQueryStringKey);
Expand All @@ -106,7 +106,7 @@ public Task<IActionResult> GetAllForUser(
{
return ExecuteSafeSecurityValidatedAsync(req, [Right.Admin, Right.Apply, Right.Review], async authResult =>
{
ListParameters lp = new (req);
ListParameters lp = new(req);
ApplicationStatus? status = req.Query.GetFirstValueOrDefault<ApplicationStatus?>("status");
IList<Application> applications = await applicationService.GetAllAsync(authResult.User!, userId, null, null, null, status, lp.Page, lp.PageSize);
return ContentResult(applications, ApplicationsContractResolver.Instance);
Expand Down
5 changes: 3 additions & 2 deletions src/Mvp.Selections.Api/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ protected async Task<IActionResult> ExecuteSafeSecurityValidatedAsync(HttpReques
? await anonymousOperation(authResult)
: new ContentResult
{
Content = authResult.Message, ContentType = PlainTextContentType,
Content = authResult.Message,
ContentType = PlainTextContentType,
StatusCode = (int)authResult.StatusCode
};
}
catch (Exception e)
{
Logger.LogError(e, e.Message);
Logger.LogError(e, "{Message}", e.Message);
result = new ContentResult { Content = e.Message, ContentType = PlainTextContentType, StatusCode = (int)HttpStatusCode.InternalServerError };
}

Expand Down
6 changes: 3 additions & 3 deletions src/Mvp.Selections.Api/Cache/CacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class CacheManager(IOptions<Configuration.CacheOptions> options, IMemoryC
: ICacheManager
{
private readonly Dictionary<CacheCollection, CacheInvalidationToken> _tokens =
new ()
new()
{
{ CacheCollection.MvpProfileSearchResults, new CacheInvalidationToken() }
};

private readonly Dictionary<CacheCollection, TimeSpan> _expirations =
new ()
new()
{
{ CacheCollection.MvpProfileSearchResults, TimeSpan.FromSeconds(options.Value.MvpProfilesCacheDurationInSeconds) }
};
Expand Down Expand Up @@ -66,7 +66,7 @@ public string GetMvpProfileSearchResultsKey(
private class CacheInvalidationToken
: IChangeToken
{
private CancellationTokenSource _cts = new ();
private CancellationTokenSource _cts = new();

public bool HasChanged => _cts.Token.IsCancellationRequested;

Expand Down
2 changes: 1 addition & 1 deletion src/Mvp.Selections.Api/Clients/CommunityClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CommunityClient(HttpClient client, IOptions<CommunityClientOptions>
public Task<Response<Profile>> GetProfile(string userId)
{
HttpRequestMessage req =
new (HttpMethod.Get, $"api/sn_communities/v1/community/profiles/{userId}");
new(HttpMethod.Get, $"api/sn_communities/v1/community/profiles/{userId}");
return SendAsync<Profile>(req);
}

Expand Down
Loading

0 comments on commit 15d7dbf

Please sign in to comment.