Skip to content
Merged
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
16 changes: 15 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="ConfirmSteps.Net" Version="0.1.2" />
<PackageVersion Include="CSharpGuidelinesAnalyzer" Version="3.8.5" />
<PackageVersion Include="FastEndpoints" Version="7.1.1" />
<PackageVersion Include="Meziantou.Analyzer" Version="2.0.253" />
<PackageVersion Include="Microsoft.Build" Version="18.0.2" />
<PackageVersion Include="Microsoft.Build.Tasks.Core" Version="18.0.2" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="18.0.2" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="10.1.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="10.1.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="NSubstitute.Analyzers.CSharp" Version="1.0.17" />
<PackageVersion Include="Nuke.Common" Version="9.0.4" />
<PackageVersion Include="NUnit" Version="4.4.0" />
<PackageVersion Include="NUnit.Analyzers" Version="4.11.2" />
<PackageVersion Include="NUnit3TestAdapter" Version="5.2.0" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.14.0" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.14.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.14.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.14.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.14.0" />
<PackageVersion Include="PolySharp" Version="1.15.0" />
<PackageVersion Include="Roslynator.Analyzers" Version="4.14.1" />
<PackageVersion Include="SharpGrip.FluentValidation.AutoValidation.Endpoints" Version="1.5.0" />
Expand All @@ -25,15 +32,22 @@
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageVersion Include="FastEndpoints" Version="5.35.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageVersion Include="Aspire.Hosting.Testing" Version="13.0.2" />
<PackageVersion Include="FastEndpoints" Version="7.1.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageVersion Include="Aspire.Hosting.Testing" Version="13.0.2" />
<PackageVersion Include="FastEndpoints" Version="7.1.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageVersion Include="Aspire.Hosting.Testing" Version="13.0.2" />
<PackageVersion Include="FastEndpoints" Version="7.1.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
</ItemGroup>
</Project>
70 changes: 69 additions & 1 deletion ProtectedNumbers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "03-samples", "03-samples",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtectedNumbers.Samples", "samples\ProtectedNumbers.Samples\ProtectedNumbers.Samples.csproj", "{49437ECB-B026-4059-B235-C828D7578A40}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "01-unit", "01-unit", "{07399998-14DD-4670-BB5D-7DE7A0F5CAD9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "02-end-to-end", "02-end-to-end", "{CF69D319-F7B4-4A0F-8931-7C926716CE53}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtectedNumbers.Tests.EndToEnd.Shared", "tst\ProtectedNumbers.Tests.EndToEnd.Shared\ProtectedNumbers.Tests.EndToEnd.Shared.csproj", "{3A5781BC-DF65-4933-BA11-3C5EEC7D06E6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtectedNumbers.Tests.EndToEnd.WebApi.Net6", "tst\ProtectedNumbers.Tests.EndToEnd.WebApi.Net6\ProtectedNumbers.Tests.EndToEnd.WebApi.Net6.csproj", "{16A25C6F-4AA6-4CAA-9A3A-A7C08DB98450}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtectedNumbers.Tests.EndToEnd.WebApi.Net8", "tst\ProtectedNumbers.Tests.EndToEnd.WebApi.Net8\ProtectedNumbers.Tests.EndToEnd.WebApi.Net8.csproj", "{4AE35AEB-0668-4DD7-B8EF-72CFB62C3F33}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtectedNumbers.Tests.EndToEnd.WebApi.Net9", "tst\ProtectedNumbers.Tests.EndToEnd.WebApi.Net9\ProtectedNumbers.Tests.EndToEnd.WebApi.Net9.csproj", "{3F156108-2C1B-4840-868E-BB927A9EBBDC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtectedNumbers.Tests.EndToEnd.WebApi.Net10", "tst\ProtectedNumbers.Tests.EndToEnd.WebApi.Net10\ProtectedNumbers.Tests.EndToEnd.WebApi.Net10.csproj", "{6597682B-5D0E-430D-A317-E63961443F89}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtectedNumbers.Tests.EndToEnd.AppHost", "tst\ProtectedNumbers.Tests.EndToEnd.AppHost\ProtectedNumbers.Tests.EndToEnd.AppHost.csproj", "{B7F72066-5054-44DA-8839-D01A89844381}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtectedNumbers.Tests.EndToEnd.ServiceDefaults", "tst\ProtectedNumbers.Tests.EndToEnd.ServiceDefaults\ProtectedNumbers.Tests.EndToEnd.ServiceDefaults.csproj", "{AA7C47F8-5F0C-4440-A829-C7767E528BBD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtectedNumbers.Tests.EndToEnd", "tst\ProtectedNumbers.Tests.EndToEnd\ProtectedNumbers.Tests.EndToEnd.csproj", "{E5CFD612-400B-46C4-90EE-2318C43BAB8F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "01-aspire", "01-aspire", "{8B2CB553-CF4A-41DB-BFB2-6438150CBB16}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "02-webapi", "02-webapi", "{DC5DF0BA-2F47-432B-941B-6A1DC0921E24}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -59,6 +83,38 @@ Global
{49437ECB-B026-4059-B235-C828D7578A40}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49437ECB-B026-4059-B235-C828D7578A40}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49437ECB-B026-4059-B235-C828D7578A40}.Release|Any CPU.Build.0 = Release|Any CPU
{3A5781BC-DF65-4933-BA11-3C5EEC7D06E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A5781BC-DF65-4933-BA11-3C5EEC7D06E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A5781BC-DF65-4933-BA11-3C5EEC7D06E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A5781BC-DF65-4933-BA11-3C5EEC7D06E6}.Release|Any CPU.Build.0 = Release|Any CPU
{16A25C6F-4AA6-4CAA-9A3A-A7C08DB98450}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16A25C6F-4AA6-4CAA-9A3A-A7C08DB98450}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16A25C6F-4AA6-4CAA-9A3A-A7C08DB98450}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16A25C6F-4AA6-4CAA-9A3A-A7C08DB98450}.Release|Any CPU.Build.0 = Release|Any CPU
{4AE35AEB-0668-4DD7-B8EF-72CFB62C3F33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4AE35AEB-0668-4DD7-B8EF-72CFB62C3F33}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4AE35AEB-0668-4DD7-B8EF-72CFB62C3F33}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4AE35AEB-0668-4DD7-B8EF-72CFB62C3F33}.Release|Any CPU.Build.0 = Release|Any CPU
{3F156108-2C1B-4840-868E-BB927A9EBBDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3F156108-2C1B-4840-868E-BB927A9EBBDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F156108-2C1B-4840-868E-BB927A9EBBDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F156108-2C1B-4840-868E-BB927A9EBBDC}.Release|Any CPU.Build.0 = Release|Any CPU
{6597682B-5D0E-430D-A317-E63961443F89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6597682B-5D0E-430D-A317-E63961443F89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6597682B-5D0E-430D-A317-E63961443F89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6597682B-5D0E-430D-A317-E63961443F89}.Release|Any CPU.Build.0 = Release|Any CPU
{B7F72066-5054-44DA-8839-D01A89844381}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B7F72066-5054-44DA-8839-D01A89844381}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7F72066-5054-44DA-8839-D01A89844381}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7F72066-5054-44DA-8839-D01A89844381}.Release|Any CPU.Build.0 = Release|Any CPU
{AA7C47F8-5F0C-4440-A829-C7767E528BBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA7C47F8-5F0C-4440-A829-C7767E528BBD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA7C47F8-5F0C-4440-A829-C7767E528BBD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA7C47F8-5F0C-4440-A829-C7767E528BBD}.Release|Any CPU.Build.0 = Release|Any CPU
{E5CFD612-400B-46C4-90EE-2318C43BAB8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5CFD612-400B-46C4-90EE-2318C43BAB8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5CFD612-400B-46C4-90EE-2318C43BAB8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5CFD612-400B-46C4-90EE-2318C43BAB8F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -68,7 +124,19 @@ Global
{54E9DA71-884C-47CB-8234-397722D49CBA} = {28E1E0C8-E214-4118-B592-AE443DB7DFD9}
{DF741A65-666B-4814-9FF1-361E29BDCC75} = {CFD2F704-18DC-4F75-9F91-DD4A58559AAA}
{66B0C8CE-E238-470F-ABF5-0896D5367564} = {499B92F7-0036-4B5C-AE09-BA6DE023EC76}
{029D532A-57A2-4E35-803E-A2071598C043} = {3A3D618C-D90D-4050-BF3D-68A67B0A75D7}
{49437ECB-B026-4059-B235-C828D7578A40} = {FCDBD854-E336-4DAD-9893-0DCD353FCA21}
{07399998-14DD-4670-BB5D-7DE7A0F5CAD9} = {3A3D618C-D90D-4050-BF3D-68A67B0A75D7}
{029D532A-57A2-4E35-803E-A2071598C043} = {07399998-14DD-4670-BB5D-7DE7A0F5CAD9}
{CF69D319-F7B4-4A0F-8931-7C926716CE53} = {3A3D618C-D90D-4050-BF3D-68A67B0A75D7}
{E5CFD612-400B-46C4-90EE-2318C43BAB8F} = {CF69D319-F7B4-4A0F-8931-7C926716CE53}
{8B2CB553-CF4A-41DB-BFB2-6438150CBB16} = {CF69D319-F7B4-4A0F-8931-7C926716CE53}
{B7F72066-5054-44DA-8839-D01A89844381} = {8B2CB553-CF4A-41DB-BFB2-6438150CBB16}
{AA7C47F8-5F0C-4440-A829-C7767E528BBD} = {8B2CB553-CF4A-41DB-BFB2-6438150CBB16}
{DC5DF0BA-2F47-432B-941B-6A1DC0921E24} = {CF69D319-F7B4-4A0F-8931-7C926716CE53}
{16A25C6F-4AA6-4CAA-9A3A-A7C08DB98450} = {DC5DF0BA-2F47-432B-941B-6A1DC0921E24}
{4AE35AEB-0668-4DD7-B8EF-72CFB62C3F33} = {DC5DF0BA-2F47-432B-941B-6A1DC0921E24}
{3F156108-2C1B-4840-868E-BB927A9EBBDC} = {DC5DF0BA-2F47-432B-941B-6A1DC0921E24}
{6597682B-5D0E-430D-A317-E63961443F89} = {DC5DF0BA-2F47-432B-941B-6A1DC0921E24}
{3A5781BC-DF65-4933-BA11-3C5EEC7D06E6} = {DC5DF0BA-2F47-432B-941B-6A1DC0921E24}
EndGlobalSection
EndGlobal
27 changes: 15 additions & 12 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,21 @@ class Build : NukeBuild
.OnlyWhenDynamic(() => !SkipTests)
.Executes(() =>
{
string dataCollector = EnableCoverage ? "Code Coverage;Format=cobertura" : null;

DotNetTest(_ => _
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.EnableNoRestore()
.EnableNoBuild()
.When(TestResultsDirectory.DirectoryExists(), _ => _
.SetResultsDirectory(TestResultsDirectory)
)
.When(!string.IsNullOrEmpty(dataCollector), _ => _
.SetDataCollector(dataCollector)
string dataCollector = EnableCoverage ? "XPlat Code Coverage" : null; // coverlet.collector

DotNetTest(_ => _
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.EnableNoRestore()
.EnableNoBuild()
.When(TestResultsDirectory.DirectoryExists(), _ => _.SetResultsDirectory(TestResultsDirectory))
.When(!string.IsNullOrEmpty(dataCollector), t => t
.SetDataCollector(dataCollector)
.SetProcessAdditionalArguments(
"-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura",
"-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Include=\"[ProtectedNumbers]*\"",
"-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Exclude=\"[*.Tests]*\""
)
)
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Grégory Célet. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
#if NET6_0
namespace ProtectedNumbers.Internal;

using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;

using ProtectedNumbers;

/// <summary>
/// Disables child validation for the <see cref="ProtectedNumber"/> value object on .NET 6 MVC,
/// preventing the validator from invoking its getters during traversal.
/// </summary>
internal sealed class DisableChildValidationForProtectedNumber : IValidationMetadataProvider
{
public void CreateValidationMetadata(ValidationMetadataProviderContext context)
{
if (context.Key.ModelType == typeof(ProtectedNumber))
{
context.ValidationMetadata.ValidateChildren = false;
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,11 @@ public void Configure(Microsoft.AspNetCore.Mvc.MvcOptions options)
{
options.ModelBinderProviders.Add(new ProtectedNumberModelBinderProvider());
}

#if NET6_0
// Workaround for .NET 6 MVC validation eagerly traversing value objects and invoking getters.
// Suppress child validation for ProtectedNumber so MVC doesn't access Value/ProtectedValue during validation.
options.ModelMetadataDetailsProviders.Add(new DisableChildValidationForProtectedNumber());
#endif
}
}
10 changes: 10 additions & 0 deletions tst/ProtectedNumbers.Tests.EndToEnd.AppHost/AppHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Grégory Célet. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
IDistributedApplicationBuilder builder = DistributedApplication.CreateBuilder(args);

builder.AddProject<Projects.ProtectedNumbers_Tests_EndToEnd_WebApi_Net6>("webapi-dotnet6");
builder.AddProject<Projects.ProtectedNumbers_Tests_EndToEnd_WebApi_Net8>("webapi-dotnet8");
builder.AddProject<Projects.ProtectedNumbers_Tests_EndToEnd_WebApi_Net9>("webapi-dotnet9");
builder.AddProject<Projects.ProtectedNumbers_Tests_EndToEnd_WebApi_Net10>("webapi-dotnet10");

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17241;http://localhost:15273",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21076",
"ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "https://localhost:23075",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22080"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15273",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19014",
"ASPIRE_DASHBOARD_MCP_ENDPOINT_URL": "http://localhost:18058",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20043"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Aspire.AppHost.Sdk/13.0.2">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<UserSecretsId>ProtectedNumbers.Tests.EndToEnd</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ProtectedNumbers.Tests.EndToEnd.WebApi.Net10\ProtectedNumbers.Tests.EndToEnd.WebApi.Net10.csproj" />
<ProjectReference Include="..\ProtectedNumbers.Tests.EndToEnd.WebApi.Net6\ProtectedNumbers.Tests.EndToEnd.WebApi.Net6.csproj" />
<ProjectReference Include="..\ProtectedNumbers.Tests.EndToEnd.WebApi.Net8\ProtectedNumbers.Tests.EndToEnd.WebApi.Net8.csproj" />
<ProjectReference Include="..\ProtectedNumbers.Tests.EndToEnd.WebApi.Net9\ProtectedNumbers.Tests.EndToEnd.WebApi.Net9.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions tst/ProtectedNumbers.Tests.EndToEnd.AppHost/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
Loading
Loading