From ace8d71af4f1120e05f2c49f70ba61485a45c4a3 Mon Sep 17 00:00:00 2001 From: Tanay Parikh Date: Mon, 29 Aug 2022 13:53:38 -0700 Subject: [PATCH 01/10] Add Blazor AssetDifferencesDetails --- .../AspNetSdkBaselineTest.cs | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs index 4fcddc09d826..f0827749bac7 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs @@ -355,9 +355,37 @@ internal void AssertManifest( manifest.ReferencedProjectsConfiguration.OrderBy(cm => cm.Identity) .Should() .BeEquivalentTo(expected.ReferencedProjectsConfiguration.OrderBy(cm => cm.Identity)); + manifest.DiscoveryPatterns.OrderBy(dp => dp.Name).ShouldBeEquivalentTo(expected.DiscoveryPatterns.OrderBy(dp => dp.Name)); - manifest.Assets.OrderBy(a => a.BasePath).ThenBy(a => a.RelativePath).ThenBy(a => a.AssetKind) - .ShouldBeEquivalentTo(expected.Assets.OrderBy(a => a.BasePath).ThenBy(a => a.RelativePath).ThenBy(a => a.AssetKind)); + var manifestAssets = manifest.Assets.OrderBy(a => a.BasePath).ThenBy(a => a.RelativePath).ThenBy(a => a.AssetKind); + var expectedAssets = expected.Assets.OrderBy(a => a.BasePath).ThenBy(a => a.RelativePath).ThenBy(a => a.AssetKind); + + manifestAssets.ShouldBeEquivalentTo(expectedAssets, AssetDifferencesDetails(manifestAssets, expectedAssets)); + + string AssetDifferencesDetails(IEnumerable manifestAssets, IEnumerable expectedAssets) + { + var missingAssets = expectedAssets.Except(manifestAssets); + var unexpectedAssets = manifestAssets.Except(expectedAssets); + + var differences = new List(); + + if (missingAssets.Any()) + { + differences.Add($"The following expected assets weren't found in the manifest {string.Join(", ", missingAssets)}."); + } + + if (unexpectedAssets.Any()) + { + differences.Add($"The following additional unexpected assets were found in the manifest {string.Join(", ", unexpectedAssets)}."); + } + + if (differences.Any()) + { + differences.Add("If the difference in baselines is expected, please re-generate the baselines. Instructions are available at https://aka.ms/aspnet/blazor/blazor-wasm-sdk-baselines"); + } + + return string.Join(Environment.NewLine, differences); + } } else { From c866ca84f4404cc7eea86c7f71033468ba690cc3 Mon Sep 17 00:00:00 2001 From: Tanay Parikh Date: Mon, 29 Aug 2022 14:16:53 -0700 Subject: [PATCH 02/10] Update AspNetSdkBaselineTest.cs For https://github.com/dotnet/sdk/issues/27346 --- .../Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs index f0827749bac7..646861d92a32 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs @@ -362,7 +362,7 @@ internal void AssertManifest( manifestAssets.ShouldBeEquivalentTo(expectedAssets, AssetDifferencesDetails(manifestAssets, expectedAssets)); - string AssetDifferencesDetails(IEnumerable manifestAssets, IEnumerable expectedAssets) + static string AssetDifferencesDetails(IEnumerable manifestAssets, IEnumerable expectedAssets) { var missingAssets = expectedAssets.Except(manifestAssets); var unexpectedAssets = manifestAssets.Except(expectedAssets); @@ -371,12 +371,12 @@ string AssetDifferencesDetails(IEnumerable manifestAssets, IEnum if (missingAssets.Any()) { - differences.Add($"The following expected assets weren't found in the manifest {string.Join(", ", missingAssets)}."); + differences.Add($"The following expected assets weren't found in the manifest {string.Join(", ", missingAssets.Select(a => a.Identity))}."); } if (unexpectedAssets.Any()) { - differences.Add($"The following additional unexpected assets were found in the manifest {string.Join(", ", unexpectedAssets)}."); + differences.Add($"The following additional unexpected assets were found in the manifest {string.Join(", ", unexpectedAssets.Select(a => a.Identity))}."); } if (differences.Any()) From 4ecc3902bc8d7cc5a5b06f36b8825a00a74a2b8c Mon Sep 17 00:00:00 2001 From: Tanay Parikh Date: Mon, 29 Aug 2022 15:57:15 -0700 Subject: [PATCH 03/10] Spacing --- .../Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs index 646861d92a32..55273c24ea37 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs @@ -355,8 +355,8 @@ internal void AssertManifest( manifest.ReferencedProjectsConfiguration.OrderBy(cm => cm.Identity) .Should() .BeEquivalentTo(expected.ReferencedProjectsConfiguration.OrderBy(cm => cm.Identity)); - manifest.DiscoveryPatterns.OrderBy(dp => dp.Name).ShouldBeEquivalentTo(expected.DiscoveryPatterns.OrderBy(dp => dp.Name)); + var manifestAssets = manifest.Assets.OrderBy(a => a.BasePath).ThenBy(a => a.RelativePath).ThenBy(a => a.AssetKind); var expectedAssets = expected.Assets.OrderBy(a => a.BasePath).ThenBy(a => a.RelativePath).ThenBy(a => a.AssetKind); From 3041fc1b13bfc7a7a5d297b3c2659e30fc27381e Mon Sep 17 00:00:00 2001 From: Tanay Parikh Date: Mon, 29 Aug 2022 16:09:08 -0700 Subject: [PATCH 04/10] Create blazor-swa-baseline-generation.md --- .../blazor-swa-baseline-generation.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 documentation/project-docs/blazor-swa-baseline-generation.md diff --git a/documentation/project-docs/blazor-swa-baseline-generation.md b/documentation/project-docs/blazor-swa-baseline-generation.md new file mode 100644 index 000000000000..7669bedfb728 --- /dev/null +++ b/documentation/project-docs/blazor-swa-baseline-generation.md @@ -0,0 +1,19 @@ +# Blazor WebAssembly Static Web Asset (SWA) Baseline Generation + +The Blazor WASM SWA baselines are used to determine if the expected assets in the manifest are present, and if new assets have been added. Occasionally, it's required to update the SWA baselines to account for expected changes in the packaged files. + +**Please note:** These steps must be performed in a Windows development environment otherwise the line-ending and ordering result in very large diff-counts. + +## Updating Baselines + +1. Clone SDK repo: `git clone git@github.com:dotnet/sdk.git` + - Switch branches as appropriate +2. Restore repo: `.\restore.cmd` +3. Build dotnet: `.\build.cmd` +4. Activate local dotnet environment: `.\eng\dogfood.cmd` +5. Enter the following into the CLI from the activated dogfood environment to open VS: `.\src\BlazorWasmSdk\BlazorWasmSdk.slnf` +6. Open `src\Tests\Microsoft.NET.Sdk.Razor.Tests\AspNetSdkBaselineTest.cs` +7. Add `#define GENERATE_SWA_BASELINES` on the first line (above the license comment) +8. Run all tests from `Microsoft.NET.Sdk.BlazorWebAssembly.Tests.csproj` +9. Delete `#define GENERATE_SWA_BASELINES` from step 7. +10. Commit the changes to the project baselines. From 24860475564b310b2da1adad69fe1d7eb3ea56d2 Mon Sep 17 00:00:00 2001 From: Tanay Parikh Date: Mon, 29 Aug 2022 19:46:37 -0700 Subject: [PATCH 05/10] PR Feedback --- .../blazor-swa-baseline-generation.md | 19 ----------- .../AspNetSdkBaselineTest.cs | 34 +++++++++++++++++-- 2 files changed, 32 insertions(+), 21 deletions(-) delete mode 100644 documentation/project-docs/blazor-swa-baseline-generation.md diff --git a/documentation/project-docs/blazor-swa-baseline-generation.md b/documentation/project-docs/blazor-swa-baseline-generation.md deleted file mode 100644 index 7669bedfb728..000000000000 --- a/documentation/project-docs/blazor-swa-baseline-generation.md +++ /dev/null @@ -1,19 +0,0 @@ -# Blazor WebAssembly Static Web Asset (SWA) Baseline Generation - -The Blazor WASM SWA baselines are used to determine if the expected assets in the manifest are present, and if new assets have been added. Occasionally, it's required to update the SWA baselines to account for expected changes in the packaged files. - -**Please note:** These steps must be performed in a Windows development environment otherwise the line-ending and ordering result in very large diff-counts. - -## Updating Baselines - -1. Clone SDK repo: `git clone git@github.com:dotnet/sdk.git` - - Switch branches as appropriate -2. Restore repo: `.\restore.cmd` -3. Build dotnet: `.\build.cmd` -4. Activate local dotnet environment: `.\eng\dogfood.cmd` -5. Enter the following into the CLI from the activated dogfood environment to open VS: `.\src\BlazorWasmSdk\BlazorWasmSdk.slnf` -6. Open `src\Tests\Microsoft.NET.Sdk.Razor.Tests\AspNetSdkBaselineTest.cs` -7. Add `#define GENERATE_SWA_BASELINES` on the first line (above the license comment) -8. Run all tests from `Microsoft.NET.Sdk.BlazorWebAssembly.Tests.csproj` -9. Delete `#define GENERATE_SWA_BASELINES` from step 7. -10. Commit the changes to the project baselines. diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs index 55273c24ea37..2b9623ef96a3 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs @@ -15,6 +15,36 @@ using Xunit; using Xunit.Abstractions; + +/*** + +----------------------------------------------------------------- + Blazor WebAssembly Static Web Asset (SWA) Baseline Generation +----------------------------------------------------------------- + +The Blazor WASM SWA baselines are used to determine if the expected assets in +the manifest are present, and if new assets have been added. Occasionally, it's +required to update the SWA baselines to account for expected changes in the +packaged files. + +**Please note:** These steps must be performed in a Windows development environment +otherwise the line-ending and ordering result in very large diff-counts. + + +Updating Baselines: + +1. Restore repo: `.\restore.cmd` +2. Build dotnet: `.\build.cmd` +3. Activate local dotnet environment: `.\eng\dogfood.cmd` +4. Enter the following into the CLI from the activated dogfood environment to open VS: `.\src\BlazorWasmSdk\BlazorWasmSdk.slnf` +5. Add `#define GENERATE_SWA_BASELINES` on the first line of this file (above the license comment) +6. Run all tests from `Microsoft.NET.Sdk.BlazorWebAssembly.Tests.csproj` +7. Delete `#define GENERATE_SWA_BASELINES` added in step 5 from the top of this file. +8. Commit the changes to the project baselines. + + ***/ + + namespace Microsoft.NET.Sdk.Razor.Tests { [Trait("AspNetCore", "BaselineTest")] @@ -356,7 +386,7 @@ internal void AssertManifest( .Should() .BeEquivalentTo(expected.ReferencedProjectsConfiguration.OrderBy(cm => cm.Identity)); manifest.DiscoveryPatterns.OrderBy(dp => dp.Name).ShouldBeEquivalentTo(expected.DiscoveryPatterns.OrderBy(dp => dp.Name)); - + var manifestAssets = manifest.Assets.OrderBy(a => a.BasePath).ThenBy(a => a.RelativePath).ThenBy(a => a.AssetKind); var expectedAssets = expected.Assets.OrderBy(a => a.BasePath).ThenBy(a => a.RelativePath).ThenBy(a => a.AssetKind); @@ -381,7 +411,7 @@ static string AssetDifferencesDetails(IEnumerable manifestAssets if (differences.Any()) { - differences.Add("If the difference in baselines is expected, please re-generate the baselines. Instructions are available at https://aka.ms/aspnet/blazor/blazor-wasm-sdk-baselines"); + differences.Add("If the difference in baselines is expected, please re-generate the baselines using the steps at the top of this file in the source code."); } return string.Join(Environment.NewLine, differences); From 8154110428f7310e99f062ad0cc92191da19d084 Mon Sep 17 00:00:00 2001 From: Tanay Parikh Date: Tue, 30 Aug 2022 10:14:23 -0700 Subject: [PATCH 06/10] Remove instructions add script reference --- .../AspNetSdkBaselineTest.cs | 32 +------------------ 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs index 2b9623ef96a3..2b58a5ac0490 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs @@ -15,36 +15,6 @@ using Xunit; using Xunit.Abstractions; - -/*** - ------------------------------------------------------------------ - Blazor WebAssembly Static Web Asset (SWA) Baseline Generation ------------------------------------------------------------------ - -The Blazor WASM SWA baselines are used to determine if the expected assets in -the manifest are present, and if new assets have been added. Occasionally, it's -required to update the SWA baselines to account for expected changes in the -packaged files. - -**Please note:** These steps must be performed in a Windows development environment -otherwise the line-ending and ordering result in very large diff-counts. - - -Updating Baselines: - -1. Restore repo: `.\restore.cmd` -2. Build dotnet: `.\build.cmd` -3. Activate local dotnet environment: `.\eng\dogfood.cmd` -4. Enter the following into the CLI from the activated dogfood environment to open VS: `.\src\BlazorWasmSdk\BlazorWasmSdk.slnf` -5. Add `#define GENERATE_SWA_BASELINES` on the first line of this file (above the license comment) -6. Run all tests from `Microsoft.NET.Sdk.BlazorWebAssembly.Tests.csproj` -7. Delete `#define GENERATE_SWA_BASELINES` added in step 5 from the top of this file. -8. Commit the changes to the project baselines. - - ***/ - - namespace Microsoft.NET.Sdk.Razor.Tests { [Trait("AspNetCore", "BaselineTest")] @@ -411,7 +381,7 @@ static string AssetDifferencesDetails(IEnumerable manifestAssets if (differences.Any()) { - differences.Add("If the difference in baselines is expected, please re-generate the baselines using the steps at the top of this file in the source code."); + differences.Add("If the difference in baselines is expected, please re-generate the baselines using the src/RazorSdk/update-test-baselines.ps1 script."); } return string.Join(Environment.NewLine, differences); From 86747ab4842eb986e31bc88f8048d6419560b8c6 Mon Sep 17 00:00:00 2001 From: Tanay Parikh Date: Tue, 1 Nov 2022 16:28:35 -0700 Subject: [PATCH 07/10] Property level comparison --- .../AspNetSdkBaselineTest.cs | 93 ++++++++++++++++++- 1 file changed, 91 insertions(+), 2 deletions(-) diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs index 2b58a5ac0490..6c03c0687230 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs @@ -359,9 +359,98 @@ internal void AssertManifest( var manifestAssets = manifest.Assets.OrderBy(a => a.BasePath).ThenBy(a => a.RelativePath).ThenBy(a => a.AssetKind); var expectedAssets = expected.Assets.OrderBy(a => a.BasePath).ThenBy(a => a.RelativePath).ThenBy(a => a.AssetKind); - - manifestAssets.ShouldBeEquivalentTo(expectedAssets, AssetDifferencesDetails(manifestAssets, expectedAssets)); + // If there's a mismatch in the number of assets, just print the strict difference in the asset `Identity` + if (manifest.Assets.Length != expected.Assets.Length) + { + manifestAssets.Should().BeEquivalentTo(expectedAssets, AssetDifferencesDetails(manifestAssets, expectedAssets)); + return; + } + + var manifestAssetsEnumerator = manifestAssets.GetEnumerator(); + var expectedAssetsEnumerator = expectedAssets.GetEnumerator(); + + var differences = new List(); + + // Otherwise, do a property level comparison of all assets + do + { + var manifestAsset = manifestAssetsEnumerator.Current; + var expectedAsset = expectedAssetsEnumerator.Current; + + var assetDifferences = new List(); + + if (manifestAsset.Identity != expectedAsset.Identity) + { + assetDifferences.Add($"Expected manifest Identity of {expectedAsset.Identity} but found {manifestAsset.Identity}."); + } + if (manifestAsset.SourceType != expectedAsset.SourceType) + { + assetDifferences.Add($"Expected manifest SourceType of {expectedAsset.SourceType} but found {manifestAsset.SourceType}."); + } + if (manifestAsset.SourceId != expectedAsset.SourceId) + { + assetDifferences.Add($"Expected manifest SourceId of {expectedAsset.SourceId} but found {manifestAsset.SourceId}."); + } + if (manifestAsset.ContentRoot != expectedAsset.ContentRoot) + { + assetDifferences.Add($"Expected manifest ContentRoot of {expectedAsset.ContentRoot} but found {manifestAsset.ContentRoot}."); + } + if (manifestAsset.BasePath != expectedAsset.BasePath) + { + assetDifferences.Add($"Expected manifest BasePath of {expectedAsset.BasePath} but found {manifestAsset.BasePath}."); + } + if (manifestAsset.RelativePath != expectedAsset.RelativePath) + { + assetDifferences.Add($"Expected manifest RelativePath of {expectedAsset.RelativePath} but found {manifestAsset.RelativePath}."); + } + if (manifestAsset.AssetKind != expectedAsset.AssetKind) + { + assetDifferences.Add($"Expected manifest AssetKind of {expectedAsset.AssetKind} but found {manifestAsset.AssetKind}."); + } + if (manifestAsset.AssetMode != expectedAsset.AssetMode) + { + assetDifferences.Add($"Expected manifest AssetMode of {expectedAsset.AssetMode} but found {manifestAsset.AssetMode}."); + } + if (manifestAsset.AssetRole != expectedAsset.AssetRole) + { + assetDifferences.Add($"Expected manifest AssetRole of {expectedAsset.AssetRole} but found {manifestAsset.AssetRole}."); + } + if (manifestAsset.RelatedAsset != expectedAsset.RelatedAsset) + { + assetDifferences.Add($"Expected manifest RelatedAsset of {expectedAsset.RelatedAsset} but found {manifestAsset.RelatedAsset}."); + } + if (manifestAsset.AssetTraitName != expectedAsset.AssetTraitName) + { + assetDifferences.Add($"Expected manifest AssetTraitName of {expectedAsset.AssetTraitName} but found {manifestAsset.AssetTraitName}."); + } + if (manifestAsset.AssetTraitValue != expectedAsset.AssetTraitValue) + { + assetDifferences.Add($"Expected manifest AssetTraitValue of {expectedAsset.AssetTraitValue} but found {manifestAsset.AssetTraitValue}."); + } + if (manifestAsset.CopyToOutputDirectory != expectedAsset.CopyToOutputDirectory) + { + assetDifferences.Add($"Expected manifest CopyToOutputDirectory of {expectedAsset.CopyToOutputDirectory} but found {manifestAsset.CopyToOutputDirectory}."); + } + if (manifestAsset.CopyToPublishDirectory != expectedAsset.CopyToPublishDirectory) + { + assetDifferences.Add($"Expected manifest CopyToPublishDirectory of {expectedAsset.CopyToPublishDirectory} but found {manifestAsset.CopyToPublishDirectory}."); + } + if (manifestAsset.OriginalItemSpec != expectedAsset.OriginalItemSpec) + { + assetDifferences.Add($"Expected manifest OriginalItemSpec of {expectedAsset.OriginalItemSpec} but found {manifestAsset.OriginalItemSpec}."); + } + + if (assetDifferences.Any()) + { + differences.Add($"For {expectedAsset.Identity}:"); + differences.AddRange(assetDifferences); + } + + } while (manifestAssetsEnumerator.MoveNext() && expectedAssetsEnumerator.MoveNext()); + + differences.Should().BeEmpty(); + static string AssetDifferencesDetails(IEnumerable manifestAssets, IEnumerable expectedAssets) { var missingAssets = expectedAssets.Except(manifestAssets); From e585f498b3af056730bcd86248e0b966f971ab5d Mon Sep 17 00:00:00 2001 From: Tanay Parikh Date: Tue, 1 Nov 2022 16:43:03 -0700 Subject: [PATCH 08/10] Added instructions --- .../AspNetSdkBaselineTest.cs | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs index f8f9c45ee4d9..1c7634c6b361 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs @@ -21,6 +21,18 @@ namespace Microsoft.NET.Sdk.Razor.Tests public class AspNetSdkBaselineTest : AspNetSdkTest { private static readonly JsonSerializerOptions BaselineSerializationOptions = new() { WriteIndented = true }; + private static readonly string BaselineGenerationInstructions = + @"If the difference in baselines is expected, please re-generate the baselines. +Note, baseline generation must be done on a Windows device. +Start by ensuring you're dogfooding the SDK from the current branch (dotnet --version should be '*.0.0-dev'). + If you're not on the dogfood sdk, run: + 1. dotnet clean + 2. .\restore.cmd + 3. .\build.cmd + 4. .\eng\dogfood.cmd + +Then, using the dogfood SDK run the src/RazorSdk/update-test-baselines.ps1 script."; + protected static readonly string DotNetJSHashRegexPattern = "\\.[a-z0-9]{10}\\.js"; protected static readonly string DotNetJSHashTemplate = ".[[hash]].js"; @@ -352,7 +364,7 @@ internal void AssertManifest( manifest.BasePath.Should().Be(expected.BasePath); manifest.Mode.Should().Be(expected.Mode); manifest.ManifestType.Should().Be(expected.ManifestType); - + manifest.ReferencedProjectsConfiguration.Count().Should().Be(expected.ReferencedProjectsConfiguration.Count()); // Relax the check for project reference configuration items see @@ -374,12 +386,12 @@ internal void AssertManifest( return; } + // Otherwise, do a property level comparison of all assets var manifestAssetsEnumerator = manifestAssets.GetEnumerator(); var expectedAssetsEnumerator = expectedAssets.GetEnumerator(); var differences = new List(); - // Otherwise, do a property level comparison of all assets do { var manifestAsset = manifestAssetsEnumerator.Current; @@ -456,8 +468,8 @@ internal void AssertManifest( } while (manifestAssetsEnumerator.MoveNext() && expectedAssetsEnumerator.MoveNext()); - differences.Should().BeEmpty(); - + differences.Should().BeEmpty(BaselineGenerationInstructions); + static string AssetDifferencesDetails(IEnumerable manifestAssets, IEnumerable expectedAssets) { var missingAssets = expectedAssets.Except(manifestAssets); @@ -477,7 +489,7 @@ static string AssetDifferencesDetails(IEnumerable manifestAssets if (differences.Any()) { - differences.Add("If the difference in baselines is expected, please re-generate the baselines using the src/RazorSdk/update-test-baselines.ps1 script."); + differences.Add(BaselineGenerationInstructions); } return string.Join(Environment.NewLine, differences); From 5c4acfe34f5e712bdd9aeb1e144c3df60154f16e Mon Sep 17 00:00:00 2001 From: Tanay Parikh Date: Wed, 2 Nov 2022 14:31:43 -0700 Subject: [PATCH 09/10] Update AspNetSdkBaselineTest.cs --- .../AspNetSdkBaselineTest.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs index 1c7634c6b361..b02d3e16a198 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs @@ -25,13 +25,13 @@ public class AspNetSdkBaselineTest : AspNetSdkTest @"If the difference in baselines is expected, please re-generate the baselines. Note, baseline generation must be done on a Windows device. Start by ensuring you're dogfooding the SDK from the current branch (dotnet --version should be '*.0.0-dev'). - If you're not on the dogfood sdk, run: + If you're not on the dogfood sdk, from the root of the repository run: 1. dotnet clean 2. .\restore.cmd 3. .\build.cmd 4. .\eng\dogfood.cmd -Then, using the dogfood SDK run the src/RazorSdk/update-test-baselines.ps1 script."; +Then, using the dogfood SDK run the .\src\RazorSdk\update-test-baselines.ps1 script."; protected static readonly string DotNetJSHashRegexPattern = "\\.[a-z0-9]{10}\\.js"; protected static readonly string DotNetJSHashTemplate = ".[[hash]].js"; @@ -375,7 +375,6 @@ internal void AssertManifest( // .BeEquivalentTo(expected.ReferencedProjectsConfiguration.OrderBy(cm => cm.Identity)); manifest.DiscoveryPatterns.OrderBy(dp => dp.Name).Should().BeEquivalentTo(expected.DiscoveryPatterns.OrderBy(dp => dp.Name)); - var manifestAssets = manifest.Assets.OrderBy(a => a.BasePath).ThenBy(a => a.RelativePath).ThenBy(a => a.AssetKind); var expectedAssets = expected.Assets.OrderBy(a => a.BasePath).ThenBy(a => a.RelativePath).ThenBy(a => a.AssetKind); @@ -397,6 +396,11 @@ internal void AssertManifest( var manifestAsset = manifestAssetsEnumerator.Current; var expectedAsset = expectedAssetsEnumerator.Current; + if (manifestAsset is null && expectedAsset is null) + { + continue; + } + var assetDifferences = new List(); if (manifestAsset.Identity != expectedAsset.Identity) From 2d93e06e3f71553e8702e3cde0d8dc779e41574f Mon Sep 17 00:00:00 2001 From: Tanay Parikh Date: Wed, 2 Nov 2022 15:33:29 -0700 Subject: [PATCH 10/10] Update AspNetSdkBaselineTest.cs --- .../AspNetSdkBaselineTest.cs | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs index b02d3e16a198..24c661c81609 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs @@ -365,7 +365,7 @@ internal void AssertManifest( manifest.Mode.Should().Be(expected.Mode); manifest.ManifestType.Should().Be(expected.ManifestType); - manifest.ReferencedProjectsConfiguration.Count().Should().Be(expected.ReferencedProjectsConfiguration.Count()); + manifest.ReferencedProjectsConfiguration.Should().HaveSameCount(expected.ReferencedProjectsConfiguration); // Relax the check for project reference configuration items see // https://github.com/dotnet/sdk/pull/27381#issuecomment-1228764471 @@ -375,14 +375,14 @@ internal void AssertManifest( // .BeEquivalentTo(expected.ReferencedProjectsConfiguration.OrderBy(cm => cm.Identity)); manifest.DiscoveryPatterns.OrderBy(dp => dp.Name).Should().BeEquivalentTo(expected.DiscoveryPatterns.OrderBy(dp => dp.Name)); + var manifestAssets = manifest.Assets.OrderBy(a => a.BasePath).ThenBy(a => a.RelativePath).ThenBy(a => a.AssetKind); var expectedAssets = expected.Assets.OrderBy(a => a.BasePath).ThenBy(a => a.RelativePath).ThenBy(a => a.AssetKind); // If there's a mismatch in the number of assets, just print the strict difference in the asset `Identity` - if (manifest.Assets.Length != expected.Assets.Length) + if (manifestAssets.Count() != expectedAssets.Count()) { - manifestAssets.Should().BeEquivalentTo(expectedAssets, AssetDifferencesDetails(manifestAssets, expectedAssets)); - return; + ThrowAssetCountMismatchError(manifestAssets, expectedAssets); } // Otherwise, do a property level comparison of all assets @@ -466,15 +466,26 @@ internal void AssertManifest( if (assetDifferences.Any()) { - differences.Add($"For {expectedAsset.Identity}:"); - differences.AddRange(assetDifferences); + differences.Add(@$" +================================================== + +For {expectedAsset.Identity}: + +{string.Join(Environment.NewLine, assetDifferences)} + +=================================================="); } } while (manifestAssetsEnumerator.MoveNext() && expectedAssetsEnumerator.MoveNext()); - differences.Should().BeEmpty(BaselineGenerationInstructions); + differences.Should().BeEmpty( + @$" the generated manifest should match the expected baseline. + +{BaselineGenerationInstructions} - static string AssetDifferencesDetails(IEnumerable manifestAssets, IEnumerable expectedAssets) +"); + + static void ThrowAssetCountMismatchError(IEnumerable manifestAssets, IEnumerable expectedAssets) { var missingAssets = expectedAssets.Except(manifestAssets); var unexpectedAssets = manifestAssets.Except(expectedAssets); @@ -483,20 +494,19 @@ static string AssetDifferencesDetails(IEnumerable manifestAssets if (missingAssets.Any()) { - differences.Add($"The following expected assets weren't found in the manifest {string.Join(", ", missingAssets.Select(a => a.Identity))}."); + differences.Add($@"The following expected assets weren't found in the manifest: + {string.Join($"{Environment.NewLine}\t", missingAssets.Select(a => a.Identity))}"); } if (unexpectedAssets.Any()) { - differences.Add($"The following additional unexpected assets were found in the manifest {string.Join(", ", unexpectedAssets.Select(a => a.Identity))}."); + differences.Add($@"The following additional unexpected assets were found in the manifest: + {string.Join($"{Environment.NewLine}\t", unexpectedAssets.Select(a => a.Identity))}"); } - if (differences.Any()) - { - differences.Add(BaselineGenerationInstructions); - } + throw new Exception($@"{string.Join(Environment.NewLine, differences)} - return string.Join(Environment.NewLine, differences); +{BaselineGenerationInstructions}"); } } else @@ -668,3 +678,4 @@ string TemplatizeRestorePath(string restorePath, string property) } } } +