From e69bb6033ca9421b5c8ce6e3a1af7e699b17b24e Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Thu, 3 Dec 2026 21:28:16 -0500 Subject: [PATCH] Validation: the SDK adds the integration packages, and a docs page A project that references Rocket.Surgery.LaunchPad.Validation itself gets the Validation.* integration package of each partner it has: ASP.NET Core, a gRPC server, HotChocolate, Blazor. LaunchPadEnableValidation=false opts out. The SDK never adds Validation itself, as it never adds Primitives. The docs site gets a page for LaunchPad's validation as it stands. Part of #3380. The rest of that ticket (porting the samples, removing ZeroAlloc.Validation and the ZeroAlloc integration packages) waits for the mediator switch: the samples validate through the mediator's pipeline. Co-Authored-By: Claude Fable 5.2 --- AGENTS.md | 2 +- .../docs/concepts/integration-packages.md | 26 ++-- docs/src/content/docs/concepts/validation.md | 125 ++++++++++++++++++ ...ery.LaunchPad.Detection.Validation.targets | 37 ++++++ ...Rocket.Surgery.LaunchPad.Detection.targets | 7 + test/Sdk.Tests/SdkValidationTests.cs | 60 ++++++++- ...hould_Ship_Only_Msbuild_Files.verified.txt | 1 + ...hould_Ship_Only_Msbuild_Files.verified.txt | 1 + ...hould_Ship_Only_Msbuild_Files.verified.txt | 1 + ...ary_No_Validation_Integration.verified.txt | 7 + ...ication_Validation_For_Blazor.verified.txt | 16 +++ ...tions_partner=Grpc.AspNetCore.verified.txt | 24 ++++ ...grations_partner=HotChocolate.verified.txt | 24 ++++ ...ion_Integrations_partner=none.verified.txt | 21 +++ ...n_Integrations_When_Opted_Out.verified.txt | 20 +++ 15 files changed, 358 insertions(+), 14 deletions(-) create mode 100644 docs/src/content/docs/concepts/validation.md create mode 100644 src/Sdks/LaunchPad/Sdk/Rocket.Surgery.LaunchPad.Detection.Validation.targets create mode 100644 test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_A_Library_No_Validation_Integration.verified.txt create mode 100644 test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_A_WebAssembly_Application_Validation_For_Blazor.verified.txt create mode 100644 test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_An_AspNetCore_Application_The_Validation_Integrations_partner=Grpc.AspNetCore.verified.txt create mode 100644 test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_An_AspNetCore_Application_The_Validation_Integrations_partner=HotChocolate.verified.txt create mode 100644 test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_An_AspNetCore_Application_The_Validation_Integrations_partner=none.verified.txt create mode 100644 test/Sdk.Tests/snapshots/SdkValidationTests.Should_Not_Add_Validation_Integrations_When_Opted_Out.verified.txt diff --git a/AGENTS.md b/AGENTS.md index 16d6748f261..6dbf4edd98b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -46,7 +46,7 @@ The conversion is done: no project references `Rocket.Surgery.Conventions` or th - The integrations are packages of their own ([#3379](https://github.com/RocketSurgeonsGuild/LaunchPad/issues/3379)), each a joint that runs after its host package's and whose types live in that package's namespaces: `src/Validation.AspNetCore` (422 `ValidationFailedProblemDetails`, the `Validation-Notices` response header, and `ValidationOpenApiSchemaTransformer`, which states the rules of the manifests), `src/Validation.Grpc` (`InvalidArgument`, with the failures in the `validation-failures-bin` trailer and the notices in `validation-notices-bin`), `src/Validation.HotChocolate` (one `VALIDATION` error for each failure, and the notices as the `validationNotices` extension) and `src/Validation.Blazor` (`LaunchPadValidator`, on .NET 11's asynchronous form validation). Each turns a `ValidationFailedException` into its transport's error shape; none validates by itself. `src/Analyzers/Api/Core/SchemaRules.cs` reads LaunchPad's rule attributes as it reads ZeroAlloc.Validation's. - Not written yet: validators for generic types (LPAD3101), and validation in the mediator pipeline, which waits for the mediator switch to land ([#3379](https://github.com/RocketSurgeonsGuild/LaunchPad/issues/3379)): until then nothing throws `ValidationFailedException` but an application's own code. The `src/ZeroAlloc.*` packages, the SDK's detection of them and `[Mutable]`'s ZeroAlloc.Validation validator stay until that library is removed ([#3380](https://github.com/RocketSurgeonsGuild/LaunchPad/issues/3380)). - `test/Validation.Tests` runs the generator as an application does and proves what the validators do (`test/Validation.Tests.Contracts` is the library it reads rules from across an assembly boundary, and `SdkValidationTests` in `test/Sdk.Tests` does the same from packed packages); `test/Validation.Analyzers.Tests` has the snapshots of what the generator writes and reports; `test/Validation.{AspNetCore,Grpc,HotChocolate,Blazor}.Tests` prove the integrations. -- `src/Sdks/LaunchPad` is the **LaunchPad SDK** (`Rocket.Surgery.LaunchPad.Sdk`), an MSBuild SDK an application applies with an `` element in each project (`#:sdk` in a file-based app) or once in its `Directory.Build.props`. It chains `Joinery.Dovetail.Sdk` (the version `Directory.Packages.props` pins for it) and adds LaunchPad packages from what Dovetail's host detection finds and from the project's direct `PackageReference`s; `LaunchPadEnable=false` opts out. Every LaunchPad SDK also chains the **Chirograph** SDK (OpenAPI clients from `OpenApiClient` items) through `src/Sdks/LaunchPad/Sdk/Rocket.Surgery.LaunchPad.Chirograph.targets`, after the project body, unless the project applies Chirograph itself or sets `LaunchPadEnableChirograph=false`; the repository's own test projects apply `` directly, at the version `global.json` pins, which must equal the `Chirograph` `PackageVersion`. The versions are written into `Sdk/Packages.props` when the SDK is packed. `src/Sdks/Console` is the **console SDK** (`Rocket.Surgery.LaunchPad.Sdk.Console`): the same SDK for ConsoleAppFramework applications, chaining `Joinery.Dovetail.Sdk.Console`. `src/Sdks/{Web,Worker,Razor,BlazorWebAssembly,WebAssembly,WindowsDesktop}` are the **mirrors** (`Rocket.Surgery.LaunchPad.Sdk.Web`, ...): each is the Microsoft SDK of the same name with LaunchPad, chains Dovetail's mirror (`Joinery.Dovetail.Sdk.Web`, ...) and then applies `src/Sdks/Mirror/Rocket.Surgery.LaunchPad.Mirror.props`, which skips LaunchPad when a `Directory.Build.props` already applied it. Every SDK but `Rocket.Surgery.LaunchPad.Sdk` packs the shared files of `src/Sdks/LaunchPad/Sdk` beside its own `Sdk.props`/`Sdk.targets`; `src/Sdks/Directory.Build.props`/`.targets` hold the package settings and generate each `Sdk/Packages.props` from `LaunchPadChainedSdk`. `test/Sdk.Tests` packs it and builds throwaway applications against it, and `sample/Sample.Sdk` consumes it from packed packages (`dotnet msbuild build/pack.proj` there first). Like an application outside the repository, that sample and the throwaway projects of the tests stand outside central package management and name their own versions. +- `src/Sdks/LaunchPad` is the **LaunchPad SDK** (`Rocket.Surgery.LaunchPad.Sdk`), an MSBuild SDK an application applies with an `` element in each project (`#:sdk` in a file-based app) or once in its `Directory.Build.props`. It chains `Joinery.Dovetail.Sdk` (the version `Directory.Packages.props` pins for it) and adds LaunchPad packages from what Dovetail's host detection finds and from the project's direct `PackageReference`s; `LaunchPadEnable=false` opts out. A project that references `Rocket.Surgery.LaunchPad.Validation` itself gets the `Validation.*` integration package of each partner it has (`Sdk/Rocket.Surgery.LaunchPad.Detection.Validation.targets`), as one that references ZeroAlloc.Validation gets the `ZeroAlloc.*` ones. Every LaunchPad SDK also chains the **Chirograph** SDK (OpenAPI clients from `OpenApiClient` items) through `src/Sdks/LaunchPad/Sdk/Rocket.Surgery.LaunchPad.Chirograph.targets`, after the project body, unless the project applies Chirograph itself or sets `LaunchPadEnableChirograph=false`; the repository's own test projects apply `` directly, at the version `global.json` pins, which must equal the `Chirograph` `PackageVersion`. The versions are written into `Sdk/Packages.props` when the SDK is packed. `src/Sdks/Console` is the **console SDK** (`Rocket.Surgery.LaunchPad.Sdk.Console`): the same SDK for ConsoleAppFramework applications, chaining `Joinery.Dovetail.Sdk.Console`. `src/Sdks/{Web,Worker,Razor,BlazorWebAssembly,WebAssembly,WindowsDesktop}` are the **mirrors** (`Rocket.Surgery.LaunchPad.Sdk.Web`, ...): each is the Microsoft SDK of the same name with LaunchPad, chains Dovetail's mirror (`Joinery.Dovetail.Sdk.Web`, ...) and then applies `src/Sdks/Mirror/Rocket.Surgery.LaunchPad.Mirror.props`, which skips LaunchPad when a `Directory.Build.props` already applied it. Every SDK but `Rocket.Surgery.LaunchPad.Sdk` packs the shared files of `src/Sdks/LaunchPad/Sdk` beside its own `Sdk.props`/`Sdk.targets`; `src/Sdks/Directory.Build.props`/`.targets` hold the package settings and generate each `Sdk/Packages.props` from `LaunchPadChainedSdk`. `test/Sdk.Tests` packs it and builds throwaway applications against it, and `sample/Sample.Sdk` consumes it from packed packages (`dotnet msbuild build/pack.proj` there first). Like an application outside the repository, that sample and the throwaway projects of the tests stand outside central package management and name their own versions. - An operation that can fail responds with a **union response** instead of throwing ([`docs/design/union-types.md`](docs/design/union-types.md), [ADR-0005](docs/adr/0005-portable-unions-shaped-like-csharp-unions.md), [ADR-0010](docs/adr/0010-net11-only-and-native-unions.md), [ADR-0006](docs/adr/0006-union-responses-over-every-transport.md)); the generated servers answer each error case in their transport's error shape. Unions are native C# 15 unions (`public union Result(RocketModel, NotFound);`), or hand-written custom unions; LaunchPad has no union generator and no polyfill ([ADR-0010](docs/adr/0010-net11-only-and-native-unions.md)). The standard error cases (`Problem`, `NotFound` and the rest) are in Foundation. Generators detect a union by name (`UnionAttribute` or `IUnion`), take its cases from its public one-parameter constructors (implicitly declared ones included) and read it through `Value`. - Every test project runs on TUnit with Microsoft.Testing.Platform, as moved by tickets [#3050](https://github.com/RocketSurgeonsGuild/LaunchPad/issues/3050) and [#3051](https://github.com/RocketSurgeonsGuild/LaunchPad/issues/3051); `test/Directory.Build.targets` adds the TUnit, Verify.TUnit, TUnit.Mocks and TUnit.Assertions.Should packages to each of them, and there is no xunit, FakeItEasy or Shouldly anywhere. Tests assert with the Should syntax (`await x.Should().BeEqualTo(y)`), falling back to `Assert.That` only where it has no equivalent, and mock with TUnit.Mocks. A test that resolves services from a populated service collection derives from `ContainerTest` (`test/Shared/ContainerTest.cs`, linked into the projects that use it). The same file gives every test project `Joinery.Dovetail` and Specular, so a test gets the joints and the Specular scan results of the projects it references. Shared test code (the web app fixtures and fake time) lives in the non-packable `test/TestSupport` project. A test creates scopes directly with `CreateScope()` / `CreateAsyncScope()`. diff --git a/docs/src/content/docs/concepts/integration-packages.md b/docs/src/content/docs/concepts/integration-packages.md index 8f1e5be202b..c185b43a62f 100644 --- a/docs/src/content/docs/concepts/integration-packages.md +++ b/docs/src/content/docs/concepts/integration-packages.md @@ -16,18 +16,20 @@ small packages, which the [LaunchPad SDK](../launchpad-sdk/) chooses for you. ## The packages the SDK chooses -| The project references | The SDK adds | -| ------------------------------- | ----------------------------------------------------------------------------------------------------- | -| a [host model](../host-models/) | `Rocket.Surgery.LaunchPad.Hosting` | -| the `WebApplication` host model | `Rocket.Surgery.LaunchPad.AspNetCore`, and `.AspNetCore.Mvc` unless `PublishAot` or `IsAotCompatible` | -| `NodaTime` | `.NodaTime`, and `.NodaTime.HotChocolate` / `.NodaTime.StrawberryShake` with those libraries | -| `NetTopologySuite` | `.Spatial`, and `.StrawberryShake.Spatial` with StrawberryShake | -| `ZeroAlloc.Validation` | the ZeroAlloc ASP.NET Core, gRPC, HotChocolate and Blazor packages with those | -| `HotChocolate` | `.HotChocolate` | -| `StrawberryShake` | `.StrawberryShake` | -| `Grpc.AspNetCore` | `.Grpc` | - -Validation is ZeroAlloc.Validation's. With ZeroAlloc.Mediator, its validation behavior checks each request against the request's +| The project references | The SDK adds | +| ------------------------------------- | ----------------------------------------------------------------------------------------------------- | +| a [host model](../host-models/) | `Rocket.Surgery.LaunchPad.Hosting` | +| the `WebApplication` host model | `Rocket.Surgery.LaunchPad.AspNetCore`, and `.AspNetCore.Mvc` unless `PublishAot` or `IsAotCompatible` | +| `NodaTime` | `.NodaTime`, and `.NodaTime.HotChocolate` / `.NodaTime.StrawberryShake` with those libraries | +| `NetTopologySuite` | `.Spatial`, and `.StrawberryShake.Spatial` with StrawberryShake | +| `ZeroAlloc.Validation` | the ZeroAlloc ASP.NET Core, gRPC, HotChocolate and Blazor packages with those | +| `Rocket.Surgery.LaunchPad.Validation` | the Validation ASP.NET Core, gRPC, HotChocolate and Blazor packages with those | +| `HotChocolate` | `.HotChocolate` | +| `StrawberryShake` | `.StrawberryShake` | +| `Grpc.AspNetCore` | `.Grpc` | + +LaunchPad has [validation of its own](../validation/), which is being built: the SDK adds its integration packages to a project that +references it, and it will replace ZeroAlloc.Validation. Until then, validation is ZeroAlloc.Validation's. With ZeroAlloc.Mediator, its validation behavior checks each request against the request's rules and throws a `ValidationFailedException`, and the ZeroAlloc package of each transport reports the failures in that transport's error shape (problem details over HTTP, a status over gRPC, GraphQL errors over HotChocolate). The other mediators have no validation step that LaunchPad hooks into: validate in the handler and return an error case such as `Invalid` or diff --git a/docs/src/content/docs/concepts/validation.md b/docs/src/content/docs/concepts/validation.md new file mode 100644 index 00000000000..9ab8bf80cb5 --- /dev/null +++ b/docs/src/content/docs/concepts/validation.md @@ -0,0 +1,125 @@ +--- +title: Validation +description: Rocket.Surgery.LaunchPad.Validation writes one validator for each type at build time, from rule attributes, DataAnnotations and Validate functions, with no reflection and no expression trees. +--- + +`Rocket.Surgery.LaunchPad.Validation` is LaunchPad's own validation. You declare **rules** for a type, and a source generator writes +one **validator** for it at build time: straight-line code, with no reflection and no expression trees, so it works under trimming +and native AOT. It is optional: an application opts in by referencing the package, and the [LaunchPad SDK](../launchpad-sdk/) never +adds it. + +:::caution[In progress] +LaunchPad's validation is being built ([#3374](https://github.com/RocketSurgeonsGuild/LaunchPad/issues/3374)). The samples and the +mediator still validate with ZeroAlloc.Validation, and nothing validates a request before its handler for you yet: you call the +validator yourself. +::: + +## Declaring rules + +Rules come from three places, and the generator merges them into the one validator of the type. + +**Attributes** on the members, from `Rocket.Surgery.LaunchPad.Validation.Rules`: + +```csharp +using Rocket.Surgery.LaunchPad.Validation.Rules; + +public sealed record CreateRocket +{ + [NotEmpty, MaxLength(30)] + public string Name { get; init; } = ""; + + [InclusiveBetween(1, 33)] + public int Engines { get; init; } + + [ValidateNested] + public IReadOnlyList Stages { get; init; } = []; +} +``` + +The `System.ComponentModel.DataAnnotations` attributes the generator knows (`[Required]`, `[StringLength]`, `[Range]`, +`[RegularExpression]`, `[EmailAddress]` and others) are compiled the same way. A custom `ValidationAttribute` never runs: the +generator reports it and points at `[Must]` or a function. + +**A function validator**: a static `Validate` method in any partial type. Its first parameter is the builder, and the others are +services the rules need: + +```csharp +public static partial class CreateRocketRules +{ + private static void Validate(IValidationBuilder v, ICatalog catalog) + { + v.Ensure(x => x.Name).Must(name => !catalog.IsTaken(name)).WithCode("NameTaken").WithMessage("{Name} is taken"); + v.Ensure(x => x.Engines).GreaterThan(8).When(x => x.Stages.Count > 1); + } +} +``` + +The body never runs. The generator reads it at build time and writes each chain as a method of the type that contains it, so a +`Validate` body may only call the builder. + +**A class validator**: a partial class that implements `IValidator`, whose dependencies are its constructor's. + +A member is validated with its own type's validator only where you say so, with `[ValidateNested]` or `.ValidateNested()`. An +analyzer warns about a member whose type has rules and that says neither that nor `[SkipValidation]`. + +## Using a validator + +The generator writes `Add{AssemblyName}Validators()` for each assembly. It registers the assembly's validators and those of the +assemblies it references. + +```csharp +services.AddMyAppValidators(); + +public sealed class RocketService(IValidate validator) +{ + public void Create(CreateRocket request) + { + validator.Validate(request).ThrowIfInvalid(); + // ... + } +} +``` + +| You inject | It gives | +| --------------------- | ------------------------------------------------------------------------ | +| `IValidate` | `Validate(value)`. Only a type with no rule that waits has one. | +| `IValidateAsync` | `ValidateAsync(value, cancellationToken)`. Every validated type has one. | +| `IValidateMembers` | One member at a time, which a form does when a field changes. | + +A type with a `MustAsync` rule is validated asynchronously only. Asking for its `IValidate` is a build error, with a fix that +makes the use asynchronous. + +A failure carries the path of the member (`Stages[2].Thrust`), a code that stays the same whatever the message says (`MaxLength`), +the message, a severity and the values of the message's placeholders. Only an error makes a result invalid: a rule declared as a +warning (`Severity = ValidationSeverity.Warning`) is reported and does not reject the value. + +## Rules from other types + +- A rule declared for a **base class** or an **interface** applies to every type that derives from or implements it, in the same + assembly or in one that references it. +- `[InheritFrom]` and `v.Include()` bring `T`'s rules for the members the type takes from it. +- The view model of a `[Mutable]` type is validated as the `T` it makes, and one field at a time with `T`'s rules. +- An application can add rules to a type a library declares. Its validator runs the library's rules and then its own. + +## Transports + +Each transport has an integration package, which the SDK adds to a project that references `Rocket.Surgery.LaunchPad.Validation` +and that transport. Each turns a `ValidationFailedException` into the transport's error shape, and sends the warnings of a request +that was accepted with its response. + +| Package | A rejected request | Warnings of an accepted request | +| -------------------------------------------------- | --------------------------------------------------------- | --------------------------------- | +| `Rocket.Surgery.LaunchPad.Validation.AspNetCore` | 422 problem details, with the errors by path | the `Validation-Notices` header | +| `Rocket.Surgery.LaunchPad.Validation.Grpc` | `InvalidArgument`, with the failures in a trailer | a trailer | +| `Rocket.Surgery.LaunchPad.Validation.HotChocolate` | one `VALIDATION` error for each failure | the `validationNotices` extension | +| `Rocket.Surgery.LaunchPad.Validation.Blazor` | the `LaunchPadValidator` component shows them in the form | shown as messages | + +The ASP.NET Core package also states the rules in the OpenAPI document: required members, lengths, ranges, patterns, e-mail +addresses and URLs. + +In a Blazor form, put `` inside the `EditForm`. A field is validated when it changes, and +`EditContext.IsValidationPending` is `true` for it while a rule that waits is running. + +The design and the decisions behind it are in +[`docs/design/validation.md`](https://github.com/RocketSurgeonsGuild/LaunchPad/blob/main/docs/design/validation.md) and +[ADR 0012](https://github.com/RocketSurgeonsGuild/LaunchPad/blob/main/docs/adr/0012-launchpad-owns-validation.md). diff --git a/src/Sdks/LaunchPad/Sdk/Rocket.Surgery.LaunchPad.Detection.Validation.targets b/src/Sdks/LaunchPad/Sdk/Rocket.Surgery.LaunchPad.Detection.Validation.targets new file mode 100644 index 00000000000..3786e18ff96 --- /dev/null +++ b/src/Sdks/LaunchPad/Sdk/Rocket.Surgery.LaunchPad.Detection.Validation.targets @@ -0,0 +1,37 @@ + + + + + + + + + diff --git a/src/Sdks/LaunchPad/Sdk/Rocket.Surgery.LaunchPad.Detection.targets b/src/Sdks/LaunchPad/Sdk/Rocket.Surgery.LaunchPad.Detection.targets index f43b31656d5..a3247681750 100644 --- a/src/Sdks/LaunchPad/Sdk/Rocket.Surgery.LaunchPad.Detection.targets +++ b/src/Sdks/LaunchPad/Sdk/Rocket.Surgery.LaunchPad.Detection.targets @@ -67,6 +67,7 @@ true true true + true true true true @@ -93,6 +94,11 @@ and (@(PackageReference->AnyHaveMetadataValue('Identity', 'ZeroAlloc.Validation')) == 'true' or @(PackageReference->AnyHaveMetadataValue('Identity', 'ZeroAlloc.Mediator.Validation')) == 'true')" /> + + <_LaunchPadTechnology + Include="Validation" + Condition="'$(LaunchPadEnableValidation)' != 'false' and @(PackageReference->AnyHaveMetadataValue('Identity', 'Rocket.Surgery.LaunchPad.Validation')) == 'true'" + /> <_LaunchPadTechnology Include="Grpc" @@ -144,6 +150,7 @@ + diff --git a/test/Sdk.Tests/SdkValidationTests.cs b/test/Sdk.Tests/SdkValidationTests.cs index f8c43a82598..06f8ea27fc1 100644 --- a/test/Sdk.Tests/SdkValidationTests.cs +++ b/test/Sdk.Tests/SdkValidationTests.cs @@ -7,7 +7,9 @@ namespace Sdk.Tests; /// /// LaunchPad's validation from packed packages, across an assembly boundary: a contracts library declares types with rules, and an /// application derives from them, copies their members with [InheritFrom] and adds rules of its own to one of them. The -/// application's generator has only the library's metadata to go by (the rule manifest), as it has for any package. +/// application's generator has only the library's metadata to go by (the rule manifest), as it has for any package. And what the +/// SDK adds to a project that references Rocket.Surgery.LaunchPad.Validation directly: the integration package of each partner +/// it has (ASP.NET Core, gRPC, GraphQL, Blazor), unless LaunchPadEnableValidation is false. /// /// The target framework of the throwaway projects. [TargetFrameworks] @@ -19,6 +21,62 @@ public class SdkValidationTests(string targetFramework) private static CancellationToken Cancellation => TestContext.Current!.Execution.CancellationToken; + /// + /// A library that references Validation gets nothing more: there is no partner there. + /// + [Test] + public async Task Should_Give_A_Library_No_Validation_Integration() + { + using var tree = new SdkTree(await PackedSdk.Pack(), targetFramework); + tree.AddProject("library", HostModel.None, await WithValidation(HostModel.None)); + + await Verify(await tree.Evaluate("library", Cancellation)); + } + + /// + /// An ASP.NET Core application gets the ASP.NET Core package, and with a gRPC server or HotChocolate theirs too. + /// + [Test] + [Arguments("none")] + [Arguments("Grpc.AspNetCore")] + [Arguments("HotChocolate")] + public async Task Should_Give_An_AspNetCore_Application_The_Validation_Integrations(string partner) + { + using var tree = new SdkTree(await PackedSdk.Pack(), targetFramework); + var project = await WithValidation(HostModel.AspNetCore); + if (partner != "none") project.ItemPackageReference(partner, Repository.PackageVersion(partner, targetFramework)); + tree.AddProject("app", HostModel.AspNetCore, project); + + await Verify(await tree.Evaluate("app", Cancellation)); + } + + /// + /// A Blazor WebAssembly application gets the Blazor package. + /// + [Test] + public async Task Should_Give_A_WebAssembly_Application_Validation_For_Blazor() + { + using var tree = new SdkTree(await PackedSdk.Pack(), targetFramework); + tree.AddProject("app", HostModel.WebAssembly, await WithValidation(HostModel.WebAssembly)); + + await Verify(await tree.Evaluate("app", Cancellation)); + } + + /// + /// LaunchPadEnableValidation set to false in the project leaves every integration package out. + /// + [Test] + public async Task Should_Not_Add_Validation_Integrations_When_Opted_Out() + { + using var tree = new SdkTree(await PackedSdk.Pack(), targetFramework); + tree.AddProject("app", HostModel.AspNetCore, ( await WithValidation(HostModel.AspNetCore) ).Property("LaunchPadEnableValidation", "false")); + + await Verify(await tree.Evaluate("app", Cancellation)); + } + + private async Task WithValidation(HostModel host) => + HostModelShape.Project(host, targetFramework).ItemPackageReference(Validation, ( await PackedSdk.Pack() ).Version); + [Test] public async Task Should_Check_The_Rules_Of_A_Library_In_The_Application() { diff --git a/test/Sdk.Tests/snapshots/SdkConsoleTests.Should_Ship_Only_Msbuild_Files.verified.txt b/test/Sdk.Tests/snapshots/SdkConsoleTests.Should_Ship_Only_Msbuild_Files.verified.txt index 72612448e47..8b66cdaca71 100644 --- a/test/Sdk.Tests/snapshots/SdkConsoleTests.Should_Ship_Only_Msbuild_Files.verified.txt +++ b/test/Sdk.Tests/snapshots/SdkConsoleTests.Should_Ship_Only_Msbuild_Files.verified.txt @@ -9,6 +9,7 @@ Sdk/Rocket.Surgery.LaunchPad.Detection.NetTopologySuite.targets, Sdk/Rocket.Surgery.LaunchPad.Detection.NodaTime.targets, Sdk/Rocket.Surgery.LaunchPad.Detection.OpenTelemetry.targets, + Sdk/Rocket.Surgery.LaunchPad.Detection.Validation.targets, Sdk/Rocket.Surgery.LaunchPad.Detection.ZeroAlloc.targets, Sdk/Rocket.Surgery.LaunchPad.Detection.targets, Sdk/Rocket.Surgery.LaunchPad.Sdk.props, diff --git a/test/Sdk.Tests/snapshots/SdkMirrorTests.Should_Ship_Only_Msbuild_Files.verified.txt b/test/Sdk.Tests/snapshots/SdkMirrorTests.Should_Ship_Only_Msbuild_Files.verified.txt index b7d40374f51..d5ced11f528 100644 --- a/test/Sdk.Tests/snapshots/SdkMirrorTests.Should_Ship_Only_Msbuild_Files.verified.txt +++ b/test/Sdk.Tests/snapshots/SdkMirrorTests.Should_Ship_Only_Msbuild_Files.verified.txt @@ -9,6 +9,7 @@ Sdk/Rocket.Surgery.LaunchPad.Detection.NetTopologySuite.targets, Sdk/Rocket.Surgery.LaunchPad.Detection.NodaTime.targets, Sdk/Rocket.Surgery.LaunchPad.Detection.OpenTelemetry.targets, + Sdk/Rocket.Surgery.LaunchPad.Detection.Validation.targets, Sdk/Rocket.Surgery.LaunchPad.Detection.ZeroAlloc.targets, Sdk/Rocket.Surgery.LaunchPad.Detection.targets, Sdk/Rocket.Surgery.LaunchPad.Mirror.props, diff --git a/test/Sdk.Tests/snapshots/SdkPackageTests.Should_Ship_Only_Msbuild_Files.verified.txt b/test/Sdk.Tests/snapshots/SdkPackageTests.Should_Ship_Only_Msbuild_Files.verified.txt index 3c508a5ddc4..5d98b4db8ae 100644 --- a/test/Sdk.Tests/snapshots/SdkPackageTests.Should_Ship_Only_Msbuild_Files.verified.txt +++ b/test/Sdk.Tests/snapshots/SdkPackageTests.Should_Ship_Only_Msbuild_Files.verified.txt @@ -9,6 +9,7 @@ Sdk/Rocket.Surgery.LaunchPad.Detection.NetTopologySuite.targets, Sdk/Rocket.Surgery.LaunchPad.Detection.NodaTime.targets, Sdk/Rocket.Surgery.LaunchPad.Detection.OpenTelemetry.targets, + Sdk/Rocket.Surgery.LaunchPad.Detection.Validation.targets, Sdk/Rocket.Surgery.LaunchPad.Detection.ZeroAlloc.targets, Sdk/Rocket.Surgery.LaunchPad.Detection.targets, Sdk/Rocket.Surgery.LaunchPad.Sdk.props, diff --git a/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_A_Library_No_Validation_Integration.verified.txt b/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_A_Library_No_Validation_Integration.verified.txt new file mode 100644 index 00000000000..9a74d885d06 --- /dev/null +++ b/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_A_Library_No_Validation_Integration.verified.txt @@ -0,0 +1,7 @@ +{ + Hosts: [], + PackageReferences: [ + Joinery.Dovetail {DovetailVersion} (SDK), + Rocket.Surgery.LaunchPad.Validation + ] +} \ No newline at end of file diff --git a/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_A_WebAssembly_Application_Validation_For_Blazor.verified.txt b/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_A_WebAssembly_Application_Validation_For_Blazor.verified.txt new file mode 100644 index 00000000000..acec363c59b --- /dev/null +++ b/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_A_WebAssembly_Application_Validation_For_Blazor.verified.txt @@ -0,0 +1,16 @@ +{ + Hosts: [ + WebAssembly + ], + PackageReferences: [ + Joinery.Dovetail {DovetailVersion} (SDK), + Joinery.Dovetail.Hosting {DovetailVersion} (SDK), + Joinery.Dovetail.OpenTelemetry {DovetailVersion} (SDK), + Microsoft.AspNetCore.Components.WebAssembly, + OpenTelemetry.Exporter.OpenTelemetryProtocol {Pinned} (SDK), + OpenTelemetry.Instrumentation.Http {Pinned} (SDK), + Rocket.Surgery.LaunchPad.Hosting {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.Validation, + Rocket.Surgery.LaunchPad.Validation.Blazor {LaunchPadVersion} (SDK) + ] +} \ No newline at end of file diff --git a/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_An_AspNetCore_Application_The_Validation_Integrations_partner=Grpc.AspNetCore.verified.txt b/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_An_AspNetCore_Application_The_Validation_Integrations_partner=Grpc.AspNetCore.verified.txt new file mode 100644 index 00000000000..20badbc9011 --- /dev/null +++ b/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_An_AspNetCore_Application_The_Validation_Integrations_partner=Grpc.AspNetCore.verified.txt @@ -0,0 +1,24 @@ +{ + Hosts: [ + WebApplication + ], + PackageReferences: [ + Grpc.AspNetCore, + Joinery.Dovetail {DovetailVersion} (SDK), + Joinery.Dovetail.Hosting {DovetailVersion} (SDK), + Joinery.Dovetail.OpenTelemetry {DovetailVersion} (SDK), + OpenTelemetry.Exporter.OpenTelemetryProtocol {Pinned} (SDK), + OpenTelemetry.Extensions.Hosting {Pinned} (SDK), + OpenTelemetry.Instrumentation.AspNetCore {Pinned} (SDK), + OpenTelemetry.Instrumentation.Http {Pinned} (SDK), + OpenTelemetry.Instrumentation.Process {Pinned} (SDK), + OpenTelemetry.Instrumentation.Runtime {Pinned} (SDK), + Rocket.Surgery.LaunchPad.AspNetCore {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.AspNetCore.Mvc {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.Grpc {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.Hosting {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.Validation, + Rocket.Surgery.LaunchPad.Validation.AspNetCore {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.Validation.Grpc {LaunchPadVersion} (SDK) + ] +} \ No newline at end of file diff --git a/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_An_AspNetCore_Application_The_Validation_Integrations_partner=HotChocolate.verified.txt b/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_An_AspNetCore_Application_The_Validation_Integrations_partner=HotChocolate.verified.txt new file mode 100644 index 00000000000..6733d160bef --- /dev/null +++ b/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_An_AspNetCore_Application_The_Validation_Integrations_partner=HotChocolate.verified.txt @@ -0,0 +1,24 @@ +{ + Hosts: [ + WebApplication + ], + PackageReferences: [ + HotChocolate, + Joinery.Dovetail {DovetailVersion} (SDK), + Joinery.Dovetail.Hosting {DovetailVersion} (SDK), + Joinery.Dovetail.OpenTelemetry {DovetailVersion} (SDK), + OpenTelemetry.Exporter.OpenTelemetryProtocol {Pinned} (SDK), + OpenTelemetry.Extensions.Hosting {Pinned} (SDK), + OpenTelemetry.Instrumentation.AspNetCore {Pinned} (SDK), + OpenTelemetry.Instrumentation.Http {Pinned} (SDK), + OpenTelemetry.Instrumentation.Process {Pinned} (SDK), + OpenTelemetry.Instrumentation.Runtime {Pinned} (SDK), + Rocket.Surgery.LaunchPad.AspNetCore {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.AspNetCore.Mvc {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.Hosting {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.HotChocolate {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.Validation, + Rocket.Surgery.LaunchPad.Validation.AspNetCore {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.Validation.HotChocolate {LaunchPadVersion} (SDK) + ] +} \ No newline at end of file diff --git a/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_An_AspNetCore_Application_The_Validation_Integrations_partner=none.verified.txt b/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_An_AspNetCore_Application_The_Validation_Integrations_partner=none.verified.txt new file mode 100644 index 00000000000..5808b602a26 --- /dev/null +++ b/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Give_An_AspNetCore_Application_The_Validation_Integrations_partner=none.verified.txt @@ -0,0 +1,21 @@ +{ + Hosts: [ + WebApplication + ], + PackageReferences: [ + Joinery.Dovetail {DovetailVersion} (SDK), + Joinery.Dovetail.Hosting {DovetailVersion} (SDK), + Joinery.Dovetail.OpenTelemetry {DovetailVersion} (SDK), + OpenTelemetry.Exporter.OpenTelemetryProtocol {Pinned} (SDK), + OpenTelemetry.Extensions.Hosting {Pinned} (SDK), + OpenTelemetry.Instrumentation.AspNetCore {Pinned} (SDK), + OpenTelemetry.Instrumentation.Http {Pinned} (SDK), + OpenTelemetry.Instrumentation.Process {Pinned} (SDK), + OpenTelemetry.Instrumentation.Runtime {Pinned} (SDK), + Rocket.Surgery.LaunchPad.AspNetCore {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.AspNetCore.Mvc {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.Hosting {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.Validation, + Rocket.Surgery.LaunchPad.Validation.AspNetCore {LaunchPadVersion} (SDK) + ] +} \ No newline at end of file diff --git a/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Not_Add_Validation_Integrations_When_Opted_Out.verified.txt b/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Not_Add_Validation_Integrations_When_Opted_Out.verified.txt new file mode 100644 index 00000000000..d40ccd0c6a8 --- /dev/null +++ b/test/Sdk.Tests/snapshots/SdkValidationTests.Should_Not_Add_Validation_Integrations_When_Opted_Out.verified.txt @@ -0,0 +1,20 @@ +{ + Hosts: [ + WebApplication + ], + PackageReferences: [ + Joinery.Dovetail {DovetailVersion} (SDK), + Joinery.Dovetail.Hosting {DovetailVersion} (SDK), + Joinery.Dovetail.OpenTelemetry {DovetailVersion} (SDK), + OpenTelemetry.Exporter.OpenTelemetryProtocol {Pinned} (SDK), + OpenTelemetry.Extensions.Hosting {Pinned} (SDK), + OpenTelemetry.Instrumentation.AspNetCore {Pinned} (SDK), + OpenTelemetry.Instrumentation.Http {Pinned} (SDK), + OpenTelemetry.Instrumentation.Process {Pinned} (SDK), + OpenTelemetry.Instrumentation.Runtime {Pinned} (SDK), + Rocket.Surgery.LaunchPad.AspNetCore {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.AspNetCore.Mvc {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.Hosting {LaunchPadVersion} (SDK), + Rocket.Surgery.LaunchPad.Validation + ] +} \ No newline at end of file