diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/TransientSdkResolutionErrorDetectorTests.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/TransientSdkResolutionErrorDetectorTests.cs index 793954e8856e..a731be88fef0 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/TransientSdkResolutionErrorDetectorTests.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/TransientSdkResolutionErrorDetectorTests.cs @@ -3,9 +3,10 @@ namespace Microsoft.DotNet.Cli.Utils.Tests { + [TestClass] public class TransientSdkResolutionErrorDetectorTests { - [Fact] + [TestMethod] public void TransientInBoxSdkResolutionFailureIsDetected() { string input = @@ -20,13 +21,13 @@ public void TransientInBoxSdkResolutionFailureIsDetected() TransientSdkResolutionErrorDetector.IsTransientError(input).Should().BeTrue(); } - [Fact] + [TestMethod] public void NullInputIsNotTransient() { TransientSdkResolutionErrorDetector.IsTransientError(null).Should().BeFalse(); } - [Fact] + [TestMethod] public void SuccessfulBuildIsNotTransient() { string input = @@ -37,7 +38,7 @@ public void SuccessfulBuildIsNotTransient() TransientSdkResolutionErrorDetector.IsTransientError(input).Should().BeFalse(); } - [Fact] + [TestMethod] public void MissingVersionedSdkWithoutResolverNullIsNotTransient() { // A genuinely missing, version-specified SDK is a deterministic failure (no workload resolver @@ -47,7 +48,7 @@ public void MissingVersionedSdkWithoutResolverNullIsNotTransient() TransientSdkResolutionErrorDetector.IsTransientError(input).Should().BeFalse(); } - [Fact] + [TestMethod] public void OtherResolverReturningNullIsNotTransient() { // A "returned null" message from a different resolver must not trigger a retry: only the in-box diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests/Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests.csproj b/test/Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests/Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests.csproj index b5abb23bac4c..a6b7463145bc 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests/Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests.csproj +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests/Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests.csproj @@ -1,4 +1,4 @@ - + false @@ -9,8 +9,6 @@ - Exe - testSdkBlazorWasmAoT false @@ -52,11 +50,16 @@ + + + + + - + diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests/WasmAoTPublishIntegrationTest.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests/WasmAoTPublishIntegrationTest.cs index c31b418a5aff..b151e9f579ba 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests/WasmAoTPublishIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests/WasmAoTPublishIntegrationTest.cs @@ -9,11 +9,10 @@ namespace Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests { + [TestClass] public class WasmAoTPublishIntegrationTest : WasmPublishIntegrationTestBase { - public WasmAoTPublishIntegrationTest(ITestOutputHelper log) : base(log) { } - - [Fact] + [TestMethod] public void AoT_Publish_InRelease_Works() { // Arrange @@ -56,7 +55,7 @@ public void AoT_Publish_InRelease_Works() new FileInfo(Path.Combine(blazorPublishDirectory, "css", "app.css")).Should().Contain(".publish"); } - [Fact] + [TestMethod] public void AoT_Publish_WithExistingWebConfig_Works() { // Arrange @@ -84,7 +83,7 @@ public void AoT_Publish_WithExistingWebConfig_Works() webConfig.Should().Contain(webConfigContents); } - [Fact] + [TestMethod] public void AoT_Publish_HostedAppWithScopedCss_VisualStudio() { // Simulates publishing the same way VS does by setting BuildProjectReferences=false. diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest50.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest50.cs index 50d8f0efa332..886bb739fe66 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest50.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest50.cs @@ -1,14 +1,17 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.NET.Sdk.StaticWebAssets.Tests; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { - public class BlazorLegacyIntegrationTest50(ITestOutputHelper log) - : IsolatedNuGetPackageFolderAspNetSdkBaselineTest(log, nameof(BlazorLegacyIntegrationTest50)) + [TestClass] + public class BlazorLegacyIntegrationTest50 : IsolatedNuGetPackageFolderAspNetSdkBaselineTest { - [CoreMSBuildOnlyFact] + protected override string RestoreNugetPackagePath => nameof(BlazorLegacyIntegrationTest50); + [TestMethod] + [CoreMSBuildOnly] public void Build50Hosted_Works() { // Arrange @@ -45,16 +48,12 @@ public void Build50Hosted_Works() content.Should().Contain(Path.Combine("Client", "wwwroot")); } - [CoreMSBuildOnlyFact] + [TestMethod] + [CoreMSBuildOnly] + // https://github.com/dotnet/sdk/issues/49665 + [OSCondition(ConditionMode.Exclude, OperatingSystems.OSX)] public void Publish50Hosted_Works() { - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - // https://github.com/dotnet/sdk/issues/49665 - // tried: '/private/tmp/helix/working/A452091E/p/d/shared/Microsoft.NETCore.App/7.0.0/libhostpolicy.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), - return; - } - // Arrange var testAsset = "BlazorWasmHosted50"; var targetFramework = "net5.0"; @@ -87,4 +86,4 @@ public void Publish50Hosted_Works() }); } } -} +} \ No newline at end of file diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest60.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest60.cs index 6ea4020a48ff..b5f5b66109cd 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest60.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest60.cs @@ -1,14 +1,16 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.NET.Sdk.StaticWebAssets.Tests; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { - public class BlazorLegacyIntegrationTest60(ITestOutputHelper log) - : IsolatedNuGetPackageFolderAspNetSdkBaselineTest(log, nameof(BlazorLegacyIntegrationTest60)) + [TestClass] + public class BlazorLegacyIntegrationTest60 : IsolatedNuGetPackageFolderAspNetSdkBaselineTest { + protected override string RestoreNugetPackagePath => nameof(BlazorLegacyIntegrationTest60); protected override string EmbeddedResourcePrefix => string.Join('.', "Microsoft.NET.Sdk.BlazorWebAssembly.Tests", "StaticWebAssetsBaselines"); @@ -16,7 +18,8 @@ public class BlazorLegacyIntegrationTest60(ITestOutputHelper log) protected override string ComputeBaselineFolder() => Path.Combine(SdkTestContext.GetRepoRoot() ?? AppContext.BaseDirectory, "test", "Microsoft.NET.Sdk.BlazorWebAssembly.Tests", "StaticWebAssetsBaselines"); - [CoreMSBuildOnlyFact] + [TestMethod] + [CoreMSBuildOnly] public void Build60Hosted_Works() { // Arrange @@ -43,8 +46,11 @@ public void Build60Hosted_Works() new FileInfo(Path.Combine(serverBuildOutputDirectory, $"{testAsset}.Shared.dll")).Should().Exist(); } - [WindowsOnlyRequiresMSBuildVersionFact("17.13", Reason = "Needs System.Text.Json 8.0.5", Skip = "https://github.com/dotnet/sdk/issues/49925")] // https://github.com/dotnet/sdk/issues/44886 - [SkipOnPlatform(TestPlatforms.Linux | TestPlatforms.OSX, "https://github.com/dotnet/sdk/issues/42145")] + [TestMethod] + [OSCondition(OperatingSystems.Windows)] + [RequiresMSBuildVersion("17.13")] + [Ignore("https://github.com/dotnet/sdk/issues/49925")] // https://github.com/dotnet/sdk/issues/44886 + // https://github.com/dotnet/sdk/issues/42145 public void Publish60Hosted_Works() { // Arrange @@ -92,4 +98,4 @@ public void Publish60Hosted_Works() intermediateOutputPath); } } -} +} \ No newline at end of file diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorMultitargetIntegrationTest.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorMultitargetIntegrationTest.cs index 2fe340a9e079..a7abfb11edd8 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorMultitargetIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorMultitargetIntegrationTest.cs @@ -2,14 +2,17 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.NET.Sdk.StaticWebAssets.Tests; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { - public class BlazorMultitargetIntegrationTest(ITestOutputHelper log) - : IsolatedNuGetPackageFolderAspNetSdkBaselineTest(log, nameof(BlazorMultitargetIntegrationTest)) + [TestClass] + public class BlazorMultitargetIntegrationTest : IsolatedNuGetPackageFolderAspNetSdkBaselineTest { + protected override string RestoreNugetPackagePath => nameof(BlazorMultitargetIntegrationTest); - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void MultiTargetApp_LoadsTheCorrectSdkBasedOnTfm() { // Arrange @@ -29,7 +32,8 @@ public void MultiTargetApp_LoadsTheCorrectSdkBasedOnTfm() browserDependencies.File("captured-references.txt").Should().NotContain("Microsoft.AspNetCore.Components.Server.dll"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void ReferencedMultiTargetApp_LoadsTheCorrectSdkBasedOnTfm() { // Arrange @@ -49,4 +53,4 @@ public void ReferencedMultiTargetApp_LoadsTheCorrectSdkBasedOnTfm() browserDependencies.File("captured-references.txt").Should().NotContain("Microsoft.AspNetCore.Components.Server.dll"); } } -} +} \ No newline at end of file diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorReadSatelliteAssemblyFileTest.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorReadSatelliteAssemblyFileTest.cs index 9fd3bb0865b5..76c7016b06e8 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorReadSatelliteAssemblyFileTest.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorReadSatelliteAssemblyFileTest.cs @@ -4,12 +4,14 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Moq; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { + [TestClass] public class BlazorReadSatelliteAssemblyFileTest { - [Fact] + [TestMethod] public void WritesAndReadsRoundTrip() { // Arrange/Act @@ -59,4 +61,4 @@ public void WritesAndReadsRoundTrip() ); } } -} +} \ No newline at end of file diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorWasmBaselineTests.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorWasmBaselineTests.cs index 1afe686bdf97..00a28b107cde 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorWasmBaselineTests.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorWasmBaselineTests.cs @@ -1,15 +1,19 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.NET.Sdk.StaticWebAssets.Tests; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { - public class BlazorWasmBaselineTests(ITestOutputHelper log, bool generateBaselines) : AspNetSdkBaselineTest(log, generateBaselines) +#pragma warning disable MSTEST0016 + [TestClass] + public class BlazorWasmBaselineTests : AspNetSdkBaselineTest { protected override string EmbeddedResourcePrefix => string.Join('.', "Microsoft.NET.Sdk.BlazorWebAssembly.Tests", "StaticWebAssetsBaselines"); protected override string ComputeBaselineFolder() => Path.Combine(SdkTestContext.GetRepoRoot() ?? AppContext.BaseDirectory, "test", "Microsoft.NET.Sdk.BlazorWebAssembly.Tests", "StaticWebAssetsBaselines"); } -} +#pragma warning restore MSTEST0016 +} \ No newline at end of file diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorWasmStaticWebAssetsIntegrationTest.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorWasmStaticWebAssetsIntegrationTest.cs index 2380d0f17f63..a7fd215d9e86 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorWasmStaticWebAssetsIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorWasmStaticWebAssetsIntegrationTest.cs @@ -1,15 +1,18 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable using Microsoft.AspNetCore.StaticWebAssets.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { - public class BlazorWasmStaticWebAssetsIntegrationTest(ITestOutputHelper log) : BlazorWasmBaselineTests(log, GenerateBaselines) + [TestClass] + public class BlazorWasmStaticWebAssetsIntegrationTest : BlazorWasmBaselineTests { - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void StaticWebAssets_BuildMinimal_Works() { // Arrange @@ -51,7 +54,8 @@ public void StaticWebAssets_BuildMinimal_Works() intermediateOutputPath); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void StaticWebAssets_PublishMinimal_Works() { // Arrange @@ -88,7 +92,8 @@ public void StaticWebAssets_PublishMinimal_Works() intermediateOutputPath); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void StaticWebAssets_Build_Hosted_Works() { // Arrange @@ -128,7 +133,8 @@ public void StaticWebAssets_Build_Hosted_Works() intermediateOutputPath); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void StaticWebAssets_Publish_Hosted_Works() { // Arrange @@ -168,7 +174,8 @@ public void StaticWebAssets_Publish_Hosted_Works() intermediateOutputPath); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void StaticWebAssets_Publish_DoesNotIncludeXmlDocumentationFiles_AsAssets() { // Arrange @@ -208,7 +215,7 @@ public void StaticWebAssets_Publish_DoesNotIncludeXmlDocumentationFiles_AsAssets intermediateOutputPath); } - [Fact] + [TestMethod] public void StaticWebAssets_HostedApp_ReferencingNetStandardLibrary_Works() { // Arrange @@ -259,7 +266,8 @@ public void StaticWebAssets_HostedApp_ReferencingNetStandardLibrary_Works() // https://github.com/dotnet/sdk/issues/49665 // ILLINK : Failed to load /private/tmp/helix/working/B3F609DC/p/d/shared/Microsoft.NETCore.App/7.0.0/libhostpolicy.dylib, error : dlopen(/private/tmp/helix/working/B3F609DC/p/d/shared/Microsoft.NETCore.App/7.0.0/libhostpolicy.dylib, 0x0001): tried: '/private/tmp/helix/working/B3F609DC/p/d/shared/Microsoft.NETCore.App/7.0.0/libhostpolicy.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/private/tmp/helix/working/B3F609DC/p/d/shared/Microsoft.NETCore.App/7.0.0/libhostpolicy.dylib' (no such file), '/private/tmp/helix/working/B3F609DC/p/d/shared/Microsoft.NETCore.App/7.0.0/libhostpolicy.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')) - [PlatformSpecificFact(TestPlatforms.Any & ~TestPlatforms.OSX)] + [TestMethod] + [OSCondition(ConditionMode.Exclude, OperatingSystems.OSX)] public void StaticWebAssets_BackCompatibilityPublish_Hosted_Works() { // Arrange @@ -308,4 +316,4 @@ public void StaticWebAssets_BackCompatibilityPublish_Hosted_Works() intermediateOutputPath); } } -} +} \ No newline at end of file diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests.csproj b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests.csproj index 63e7982fac3e..62f487b3b63f 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests.csproj +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests.csproj @@ -1,4 +1,4 @@ - + false @@ -8,11 +8,6 @@ $(SdkTargetFramework) - - Exe - testSdkBlazorWasm - - @@ -46,13 +41,18 @@ + + + + + - + diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/VanillaWasmTests.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/VanillaWasmTests.cs index 833819dd317f..364af53b2776 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/VanillaWasmTests.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/VanillaWasmTests.cs @@ -1,13 +1,17 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { - public class VanillaWasmTests(ITestOutputHelper log) : BlazorWasmBaselineTests(log, GenerateBaselines) + [TestClass] + public class VanillaWasmTests : BlazorWasmBaselineTests { - [CoreMSBuildOnlyFact] + [TestMethod] + [CoreMSBuildOnly] public void Build_Works() { var testAsset = "VanillaWasm"; @@ -35,4 +39,4 @@ public void Build_Works() new FileInfo(Path.Combine(buildOutputDirectory, "wwwroot", "_framework", "dotnet.native.wasm")).Should().NotExist(); } } -} +} \ No newline at end of file diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildIncrementalismTest.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildIncrementalismTest.cs index 98d6f9f03242..c868c4e210d8 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildIncrementalismTest.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildIncrementalismTest.cs @@ -5,12 +5,15 @@ using System.Text.Json; using Microsoft.NET.Sdk.WebAssembly; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { - public class WasmBuildIncrementalismTest(ITestOutputHelper log) : AspNetSdkTest(log) + [TestClass] + public class WasmBuildIncrementalismTest : AspNetSdkTest { - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_IsIncremental() { // Arrange @@ -54,7 +57,8 @@ public void Build_IsIncremental() } } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_GzipCompression_IsIncremental() { // Arrange @@ -91,7 +95,7 @@ public void Build_GzipCompression_IsIncremental() .Pass(); var newThumbPrint = FileThumbPrint.CreateFolderThumbprint(projectDirectory, gzipCompressionDirectory); - Assert.Equal(thumbPrint.Count, newThumbPrint.Count); + newThumbPrint.Should().HaveCount(thumbPrint.Count); for (var j = 0; j < thumbPrint.Count; j++) { thumbPrint[j].Equals(newThumbPrint[j]).Should().BeTrue($"because {thumbPrint[j].Hash} should be the same as {newThumbPrint[j].Hash} for file {thumbPrint[j].Path}"); @@ -99,7 +103,8 @@ public void Build_GzipCompression_IsIncremental() } } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_SatelliteAssembliesFileIsPreserved() { // Arrange @@ -163,7 +168,8 @@ void Verify() } } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_SatelliteAssembliesFileIsCreated_IfNewFileIsAdded() { // Arrange @@ -214,7 +220,8 @@ public void Build_SatelliteAssembliesFileIsCreated_IfNewFileIsAdded() kvp.Value.Should().ContainKey("blazorwasm.resources.wasm"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_SatelliteAssembliesFileIsDeleted_IfAllSatelliteFilesAreRemoved() { // Arrange @@ -266,4 +273,4 @@ public void Build_SatelliteAssembliesFileIsDeleted_IfAllSatelliteFilesAreRemoved satelliteResources.Should().BeNull(); } } -} +} \ No newline at end of file diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildIntegrationTest.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildIntegrationTest.cs index bf998cfd5da0..9350d5fa3b30 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildIntegrationTest.cs @@ -7,10 +7,12 @@ using System.Text.Json; using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.NET.Sdk.WebAssembly; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { - public class WasmBuildIntegrationTest(ITestOutputHelper log) : BlazorWasmBaselineTests(log, GenerateBaselines) + [TestClass] + public class WasmBuildIntegrationTest : BlazorWasmBaselineTests { private static string customIcuFilename = "icudt_custom.dat"; private static string fullIcuFilename = "icudt.dat"; @@ -20,7 +22,8 @@ public class WasmBuildIntegrationTest(ITestOutputHelper log) : BlazorWasmBaselin "icudt_no_CJK.dat" }; - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void BuildMinimal_Works() { // Arrange @@ -50,9 +53,10 @@ public void BuildMinimal_Works() new FileInfo(Path.Combine(buildOutputDirectory, "wwwroot", "_framework", "blazorwasm-minimal.wasm")).Should().NotExist(); } - [RequiresMSBuildVersionTheory("17.12", Reason = "Needs System.Text.Json 8.0.5")] - [InlineData("blazor")] - [InlineData("blazor spaces")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] + [DataRow("blazor")] + [DataRow("blazor spaces")] public void Build_Works(string identifier) { // Arrange @@ -78,7 +82,8 @@ public void Build_Works(string identifier) new FileInfo(Path.Combine(buildOutputDirectory, "wwwroot", "_framework", "blazorwasm.wasm")).Should().NotExist(); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_Works_WithLibraryUsingHintPath() { // Arrange @@ -121,7 +126,8 @@ public void Build_Works_WithLibraryUsingHintPath() new FileInfo(Path.Combine(buildOutputDirectory, "wwwroot", "_framework", "blazorwasm.wasm")).Should().NotExist(); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_InRelease_Works() { // Arrange @@ -150,7 +156,8 @@ public void Build_InRelease_Works() new FileInfo(Path.Combine(buildOutputDirectory, "wwwroot", "_framework", "blazorwasm.wasm")).Should().NotExist(); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_ProducesBootJsonDataWithExpectedContent() { // Arrange @@ -197,7 +204,8 @@ public void Build_ProducesBootJsonDataWithExpectedContent() bootJsonData.config.Should().Contain("../appsettings.development.json"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_InRelease_ProducesBootJsonDataWithExpectedContent() { // Arrange @@ -241,7 +249,8 @@ public void Build_InRelease_ProducesBootJsonDataWithExpectedContent() bootJsonData.resources.satelliteResources.Should().BeNull(); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_WithBlazorEnableTimeZoneSupportDisabled_DoesNotCopyTimeZoneInfo() { // Arrange @@ -274,7 +283,8 @@ public void Build_WithBlazorEnableTimeZoneSupportDisabled_DoesNotCopyTimeZoneInf new FileInfo(Path.Combine(buildOutputDirectory, "wwwroot", "_framework", "dotnet.timezones.blat")).Should().NotExist(); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_WithInvariantGlobalizationEnabled_DoesNotCopyGlobalizationData() { // Arrange @@ -313,7 +323,8 @@ public void Build_WithInvariantGlobalizationEnabled_DoesNotCopyGlobalizationData } } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_WithInvariantGlobalizationEnabled_DoesNotCopyGlobalizationData() { // Arrange @@ -351,7 +362,8 @@ public void Publish_WithInvariantGlobalizationEnabled_DoesNotCopyGlobalizationDa } } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_WithBlazorWebAssemblyLoadCustomGlobalizationData_SetsGlobalizationMode() { // Arrange @@ -396,7 +408,8 @@ public void Build_WithBlazorWebAssemblyLoadCustomGlobalizationData_SetsGlobaliza } } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_WithBlazorWebAssemblyLoadCustomGlobalizationData_SetsGlobalizationMode() { var testAppName = "BlazorHosted"; @@ -439,7 +452,8 @@ public void Publish_WithBlazorWebAssemblyLoadCustomGlobalizationData_SetsGlobali } } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_WithBlazorWebAssemblyLoadAllGlobalizationData_SetsICUDataMode() { // Arrange @@ -482,7 +496,8 @@ public void Build_WithBlazorWebAssemblyLoadAllGlobalizationData_SetsICUDataMode( } } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_WithBlazorWebAssemblyLoadAllGlobalizationData_SetsGlobalizationMode() { // Arrange @@ -524,7 +539,8 @@ public void Publish_WithBlazorWebAssemblyLoadAllGlobalizationData_SetsGlobalizat } } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_Hosted_Works() { // Arrange @@ -539,7 +555,8 @@ public void Build_Hosted_Works() new FileInfo(Path.Combine(buildOutputDirectory, "wwwroot", "_framework", "_bin", "blazorwasm.wasm")).Should().NotExist(); } - [Fact(Skip = "https://github.com/dotnet/sdk/issues/52429")] + [TestMethod] + [Ignore("https://github.com/dotnet/sdk/issues/52429")] public void Build_SatelliteAssembliesAreCopiedToBuildOutput() { // Arrange @@ -597,7 +614,8 @@ public void Build_SatelliteAssembliesAreCopiedToBuildOutput() bootJsonPath.Should().Contain("\"Microsoft.CodeAnalysis.CSharp.resources.wasm\""); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_WithCustomOutputPath_Works() { var testAppName = "BlazorWasmWithLibrary"; @@ -619,7 +637,8 @@ public void Build_WithCustomOutputPath_Works() ExecuteCommand(buildCommand).Should().Pass(); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_WithTransitiveReference_Works() { // Regression test for https://github.com/dotnet/aspnetcore/issues/37574. @@ -676,7 +695,8 @@ public class TestReference fileInWwwroot.Should().NotExist(); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Restore_WithRuntime_Works() { var testInstance = CreateAspNetSdkTestAsset("BlazorHosted"); @@ -693,7 +713,8 @@ public void Restore_WithRuntime_Works() .Should().NotExist(); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_WithReference_Works() { // Regression test for https://github.com/dotnet/aspnetcore/issues/37574. @@ -757,10 +778,11 @@ public class TestReference fileInWwwroot.Should().NotExist(); } - [RequiresMSBuildVersionTheory("17.12", Reason = "Needs System.Text.Json 8.0.5")] - [InlineData(true)] - [InlineData(false)] - [InlineData(null)] + [TestMethod] + [RequiresMSBuildVersion("17.12")] + [DataRow(true)] + [DataRow(false)] + [DataRow(null)] public void Build_WithJiterpreter(bool? value) => BuildWasmMinimalAndValidateBootConfig(new[] { ("BlazorWebAssemblyJiterpreter", value?.ToString()) }, b => { @@ -775,7 +797,8 @@ public void Build_WithJiterpreter(bool? value) } }); - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_WithJiterpreter_Advanced() => BuildWasmMinimalAndValidateBootConfig(new[] { ("BlazorWebAssemblyJiterpreter", "true"), ("BlazorWebAssemblyRuntimeOptions", "--no-jiterpreter-interp-entry-enabled") }, b => { @@ -823,4 +846,4 @@ private static BootJsonData ReadBootJsonData(string path) return BootJsonDataLoader.ParseBootData(path); } } -} +} \ No newline at end of file diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildLazyLoadTest.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildLazyLoadTest.cs index 684bea14741c..ccc77096bc63 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildLazyLoadTest.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildLazyLoadTest.cs @@ -5,14 +5,16 @@ using System.Text.Json; using Microsoft.NET.Sdk.WebAssembly; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { + [TestClass] public class WasmBuildLazyLoadTest : AspNetSdkTest { - public WasmBuildLazyLoadTest(ITestOutputHelper log) : base(log) { } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_LazyLoadExplicitAssembly_Debug_Works() { // Arrange @@ -69,7 +71,8 @@ public void Build_LazyLoadExplicitAssembly_Debug_Works() assemblies.Keys.Should().Contain("blazorwasm.wasm"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_LazyLoadExplicitAssembly_Release_Works() { // Arrange @@ -126,7 +129,8 @@ public void Build_LazyLoadExplicitAssembly_Release_Works() assemblies.Keys.Should().Contain("blazorwasm.wasm"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_LazyLoadExplicitAssembly_Debug_Works() { // Arrange @@ -178,7 +182,8 @@ public void Publish_LazyLoadExplicitAssembly_Debug_Works() assemblies.Keys.Should().Contain("blazorwasm.wasm"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_LazyLoadExplicitAssembly_Release_Works() { // Arrange @@ -230,7 +235,8 @@ public void Publish_LazyLoadExplicitAssembly_Release_Works() assemblies.Keys.Should().Contain("blazorwasm.wasm"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_LazyLoadExplicitAssembly_InvalidAssembly() { // Arrange @@ -251,7 +257,8 @@ public void Build_LazyLoadExplicitAssembly_InvalidAssembly() ExecuteCommand(buildCommand).Should().Fail().And.HaveStdOutContaining("BLAZORSDK1001"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_LazyLoadExplicitAssembly_InvalidAssembly() { // Arrange @@ -277,4 +284,4 @@ private static BootJsonData ReadBootJsonData(string path) return BootJsonDataLoader.ParseBootData(path); } } -} +} \ No newline at end of file diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmCompressionTests.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmCompressionTests.cs index 9eb941e19ad2..18a9840a638b 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmCompressionTests.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmCompressionTests.cs @@ -3,13 +3,16 @@ #nullable disable +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { + [TestClass] public class WasmCompressionTests : AspNetSdkTest { - public WasmCompressionTests(ITestOutputHelper log) : base(log) { } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_UpdatesFilesWhenSourcesChange() { // Arrange @@ -55,14 +58,15 @@ public void Publish_UpdatesFilesWhenSourcesChange() var newBlazorBootJsonThumbPrint = FileThumbPrint.Create(blazorBootJson); var newBlazorBootJsonCompressedThumbPrint = FileThumbPrint.Create(blazorBootJsonCompressed); - Assert.NotEqual(mainAppDllThumbPrint, newMainAppDllThumbPrint); - Assert.NotEqual(mainAppCompressedDllThumbPrint, newMainAppCompressedDllThumbPrint); + Assert.AreNotEqual(mainAppDllThumbPrint, newMainAppDllThumbPrint); + Assert.AreNotEqual(mainAppCompressedDllThumbPrint, newMainAppCompressedDllThumbPrint); - Assert.NotEqual(blazorBootJsonThumbPrint, newBlazorBootJsonThumbPrint); - Assert.NotEqual(blazorBootJsonCompressedThumbPrint, newBlazorBootJsonCompressedThumbPrint); + Assert.AreNotEqual(blazorBootJsonThumbPrint, newBlazorBootJsonThumbPrint); + Assert.AreNotEqual(blazorBootJsonCompressedThumbPrint, newBlazorBootJsonCompressedThumbPrint); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_WithoutLinkerAndCompression_UpdatesFilesWhenSourcesChange() { // Arrange @@ -102,11 +106,12 @@ public void Publish_WithoutLinkerAndCompression_UpdatesFilesWhenSourcesChange() var newMainAppDllThumbPrint = FileThumbPrint.Create(mainAppDll); var newMainAppCompressedDllThumbPrint = FileThumbPrint.Create(mainAppCompressedDll); - Assert.NotEqual(mainAppDllThumbPrint, newMainAppDllThumbPrint); - Assert.NotEqual(mainAppCompressedDllThumbPrint, newMainAppCompressedDllThumbPrint); + Assert.AreNotEqual(mainAppDllThumbPrint, newMainAppDllThumbPrint); + Assert.AreNotEqual(mainAppCompressedDllThumbPrint, newMainAppCompressedDllThumbPrint); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_WithLinkerAndCompression_IsIncremental() { // Arrange @@ -130,15 +135,16 @@ public void Publish_WithLinkerAndCompression_IsIncremental() ExecuteCommand(buildCommand).Should().Pass(); var newThumbPrint = FileThumbPrint.CreateFolderThumbprint(testInstance, compressedFilesFolder); - Assert.Equal(thumbPrint.Count, newThumbPrint.Count); + newThumbPrint.Should().HaveCount(thumbPrint.Count); for (var j = 0; j < thumbPrint.Count; j++) { - Assert.Equal(thumbPrint[j], newThumbPrint[j]); + Assert.AreEqual(thumbPrint[j], newThumbPrint[j]); } } } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_WithoutLinkerAndCompression_IsIncremental() { // Arrange @@ -162,15 +168,16 @@ public void Publish_WithoutLinkerAndCompression_IsIncremental() ExecuteCommand(buildCommand, "/p:BlazorWebAssemblyEnableLinking=false").Should().Pass(); var newThumbPrint = FileThumbPrint.CreateFolderThumbprint(testInstance, compressedFilesFolder); - Assert.Equal(thumbPrint.Count, newThumbPrint.Count); + newThumbPrint.Should().HaveCount(thumbPrint.Count); for (var j = 0; j < thumbPrint.Count; j++) { - Assert.Equal(thumbPrint[j], newThumbPrint[j]); + Assert.AreEqual(thumbPrint[j], newThumbPrint[j]); } } } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_CompressesAllFrameworkFiles() { // Arrange @@ -193,10 +200,10 @@ public void Publish_CompressesAllFrameworkFiles() var extension = Path.GetExtension(file); if (extension != ".br" && extension != ".gz") { - Assert.True(File.Exists($"{file}.gz"), $"Expected file {$"{file}.gz"} to exist, but it did not."); - Assert.True(File.Exists($"{file}.br"), $"Expected file {$"{file}.br"} to exist, but it did not."); + Assert.IsTrue(File.Exists($"{file}.gz"), $"Expected file {$"{file}.gz"} to exist, but it did not."); + Assert.IsTrue(File.Exists($"{file}.br"), $"Expected file {$"{file}.br"} to exist, but it did not."); } } } } -} +} \ No newline at end of file diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmJsModulesIntegrationTests.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmJsModulesIntegrationTests.cs index 4f0aa5c29ea1..1db707f431e3 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmJsModulesIntegrationTests.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmJsModulesIntegrationTests.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable @@ -6,12 +6,15 @@ using System.Text.Json; using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.NET.Sdk.WebAssembly; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { - public class WasmJsModulesIntegrationTests(ITestOutputHelper log) : BlazorWasmBaselineTests(log, GenerateBaselines) + [TestClass] + public class WasmJsModulesIntegrationTests : BlazorWasmBaselineTests { - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_DoesNotGenerateManifestJson_IncludesJSModulesOnBlazorBootJsonManifest() { // Arrange @@ -52,7 +55,8 @@ public void Build_DoesNotGenerateManifestJson_IncludesJSModulesOnBlazorBootJsonM new FileInfo(Path.Combine(outputPath, "wwwroot", "blazorwasm-minimal.modules.json")).Should().NotExist(); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void JSModules_ManifestIncludesModuleTargetPaths() { // Arrange @@ -100,7 +104,8 @@ public void JSModules_ManifestIncludesModuleTargetPaths() new FileInfo(Path.Combine(outputPath, "wwwroot", "blazorhosted.modules.json")).Should().NotExist(); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_DoesNotGenerateManifestJson_IncludesJSModulesOnBlazorBootJsonManifest() { // Arrange @@ -149,7 +154,8 @@ public void Publish_DoesNotGenerateManifestJson_IncludesJSModulesOnBlazorBootJso intermediateOutputPath); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void JsModules_CanHaveDifferentBuildAndPublishModules() { // Arrange @@ -202,7 +208,7 @@ public void JsModules_CanHaveDifferentBuildAndPublishModules() intermediateOutputPath); } - [Fact] + [TestMethod] public void JsModules_CanCustomizeBlazorInitialization() { // Arrange @@ -267,7 +273,7 @@ public void JsModules_CanCustomizeBlazorInitialization() intermediateOutputPath); } - [Fact] + [TestMethod] public void JsModules_Hosted_CanCustomizeBlazorInitialization() { // Arrange @@ -360,4 +366,4 @@ private static int GetPublishExtensionEntriesCount(string path) return extension.EnumerateObject().Count(); } } -} +} \ No newline at end of file diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPublishIntegrationTest.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPublishIntegrationTest.cs index b326fe8e13e4..18661b52a81b 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPublishIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPublishIntegrationTest.cs @@ -7,14 +7,16 @@ using System.Text.Json; using Microsoft.NET.Sdk.WebAssembly; using static Microsoft.NET.Sdk.BlazorWebAssembly.Tests.ServiceWorkerAssert; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { + [TestClass] public class WasmPublishIntegrationTest : WasmPublishIntegrationTestBase { - public WasmPublishIntegrationTest(ITestOutputHelper log) : base(log) { } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_MinimalApp_Works() { // Arrange @@ -53,7 +55,8 @@ public void Publish_MinimalApp_Works() VerifyBootManifestHashes(testInstance, Path.Combine(publishDirectory.ToString(), "wwwroot")); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_WithDefaultSettings_Works() { // Arrange @@ -105,7 +108,8 @@ public void Publish_WithDefaultSettings_Works() VerifyTypeGranularTrimming(blazorPublishDirectory); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_Works_WithLibraryUsingHintPath() { // Arrange @@ -158,7 +162,8 @@ public void Publish_Works_WithLibraryUsingHintPath() new FileInfo(Path.Combine(publishOutputDirectory, "wwwroot", "_framework", "RazorClassLibrary.wasm")).Should().Exist(); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_WithScopedCss_Works() { // Arrange @@ -207,7 +212,8 @@ public void Publish_WithScopedCss_Works() assetsManifestPath: "custom-service-worker-assets.js"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_InRelease_Works() { // Arrange @@ -251,7 +257,8 @@ public void Publish_InRelease_Works() new FileInfo(Path.Combine(blazorPublishDirectory, "css", "app.css")).Should().Contain(".publish"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_WithExistingWebConfig_Works() { // Arrange @@ -271,7 +278,8 @@ public void Publish_WithExistingWebConfig_Works() webConfig.Should().Contain(webConfigContents); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_WithNoBuild_Works() { // Arrange @@ -320,9 +328,10 @@ public void Publish_WithNoBuild_Works() VerifyCompression(testInstance, blazorPublishDirectory); } - [RequiresMSBuildVersionTheory("17.12", Reason = "Needs System.Text.Json 8.0.5")] - [InlineData("different-path")] - [InlineData("/different-path")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] + [DataRow("different-path")] + [DataRow("/different-path")] public void Publish_WithStaticWebBasePathWorks(string basePath) { // Arrange @@ -383,9 +392,10 @@ public void Publish_WithStaticWebBasePathWorks(string basePath) staticWebAssetsBasePath: "different-path"); } - [RequiresMSBuildVersionTheory("17.12", Reason = "Needs System.Text.Json 8.0.5")] - [InlineData("different-path/")] - [InlineData("/different-path/")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] + [DataRow("different-path/")] + [DataRow("/different-path/")] public void Publish_Hosted_WithStaticWebBasePathWorks(string basePath) { var testAppName = "BlazorHosted"; @@ -451,7 +461,8 @@ private static void VerifyCompression(TestAsset testAsset, string blazorPublishD uncompressedText.Should().Be(originalText); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_WithTrimmingdDisabled_Works() { // Arrange @@ -522,7 +533,8 @@ public void Publish_WithTrimmingdDisabled_Works() VerifyAssemblyHasTypes(loggingAssemblyPath, new[] { "Microsoft.Extensions.Logging.LoggerFactory" }); } - [Fact(Skip = "https://github.com/dotnet/sdk/issues/52429")] + [TestMethod] + [Ignore("https://github.com/dotnet/sdk/issues/52429")] public void Publish_SatelliteAssemblies_AreCopiedToBuildOutput() { // Arrange @@ -574,7 +586,8 @@ public void Publish_SatelliteAssemblies_AreCopiedToBuildOutput() VerifyBootManifestHashes(testInstance, blazorPublishDirectory); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_HostedApp_DefaultSettings_Works() { // Arrange @@ -667,7 +680,8 @@ public void Publish_HostedApp_DefaultSettings_Works() VerifyTypeGranularTrimming(blazorPublishDirectory); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_HostedApp_ProducesBootJsonDataWithExpectedContent() { // Arrange @@ -709,7 +723,8 @@ public void Publish_HostedApp_ProducesBootJsonDataWithExpectedContent() bootJsonData.config.Should().Contain("../appsettings.development.json"); } - [Fact(Skip = "https://github.com/dotnet/sdk/issues/52429")] + [TestMethod] + [Ignore("https://github.com/dotnet/sdk/issues/52429")] public void Publish_HostedApp_WithSatelliteAssemblies() { // Arrange @@ -768,7 +783,8 @@ public void Publish_HostedApp_WithSatelliteAssemblies() bootJsonData.Should().Contain("\"Microsoft.CodeAnalysis.CSharp.resources.wasm\""); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] // Regression test for https://github.com/dotnet/aspnetcore/issues/18752 public void Publish_HostedApp_WithoutTrimming_Works() { @@ -869,7 +885,8 @@ public void Publish_HostedApp_WithoutTrimming_Works() assetsManifestPath: "custom-service-worker-assets.js"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_HostedApp_WithNoBuild_Works() { // Arrange @@ -931,7 +948,8 @@ public void Publish_HostedApp_WithNoBuild_Works() assetsManifestPath: "custom-service-worker-assets.js"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_HostedApp_VisualStudio() { // Simulates publishing the same way VS does by setting BuildProjectReferences=false. @@ -1025,7 +1043,8 @@ public void Publish_HostedApp_VisualStudio() assetsManifestPath: "custom-service-worker-assets.js"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_HostedAppWithScopedCss_VisualStudio() { // Simulates publishing the same way VS does by setting BuildProjectReferences=false. @@ -1128,7 +1147,8 @@ public void Publish_HostedAppWithScopedCss_VisualStudio() // Regression test to verify satellite assemblies from the blazor app are copied to the published app's wwwroot output directory as // part of publishing in VS - [Fact(Skip = "https://github.com/dotnet/sdk/issues/52429")] + [TestMethod] + [Ignore("https://github.com/dotnet/sdk/issues/52429")] public void Publish_HostedApp_VisualStudio_WithSatelliteAssemblies() { var testAppName = "BlazorWasmWithLibrary"; @@ -1189,7 +1209,8 @@ public void Publish_HostedApp_VisualStudio_WithSatelliteAssemblies() VerifyBootManifestHashes(testInstance, blazorPublishDirectory); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_HostedApp_WithRidSpecifiedInCLI_Works() { // Arrange @@ -1212,7 +1233,8 @@ public void Publish_HostedApp_WithRidSpecifiedInCLI_Works() AssertRIDPublishOutput(publishCommand, testInstance, hosted: true); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_HostedApp_WithRidSpecifiedAsArgument_NoSelfContained_Works() { // Arrange @@ -1248,7 +1270,7 @@ public void Publish_HostedApp_WithRidSpecifiedAsArgument_NoSelfContained_Works() AssertRIDPublishOutput(publishCommand, testInstance, hosted: true, selfContained: false); } - [Fact] + [TestMethod] public void Publish_HostedApp_WithRidSpecifiedAsArgument_Works() { // Arrange @@ -1274,7 +1296,8 @@ public void Publish_HostedApp_WithRidSpecifiedAsArgument_Works() AssertRIDPublishOutput(publishCommand, testInstance, hosted: true); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_HostedApp_WithRid_Works() { // Arrange @@ -1459,7 +1482,8 @@ private void AssertRIDPublishOutput(DotnetPublishCommand command, TestAsset test assetsManifestPath: "custom-service-worker-assets.js"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_WithInvariantGlobalizationEnabled_DoesNotCopyGlobalizationData() { // Arrange @@ -1495,7 +1519,9 @@ public void Publish_WithInvariantGlobalizationEnabled_DoesNotCopyGlobalizationDa new FileInfo(Path.Combine(publishOutputDirectory, "wwwroot", "_framework", "icudt_no_CJK.dat")).Should().NotExist(); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5", Skip = "https://github.com/dotnet/sdk/issues/53689")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] + [Ignore("https://github.com/dotnet/sdk/issues/53689")] public void Publish_HostingMultipleBlazorWebApps_Works() { // Regression test for https://github.com/dotnet/aspnetcore/issues/29264 @@ -1556,7 +1582,8 @@ public void Publish_HostingMultipleBlazorWebApps_Works() new FileInfo(Path.Combine(secondAppPublishDirectory, "_framework", "Newtonsoft.Json.wasm.br")).Should().NotExist(); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_WithTransitiveReference_Works() { // Regression test for https://github.com/dotnet/aspnetcore/issues/37574. @@ -1612,9 +1639,10 @@ public class TestReference fileInWwwroot.Should().Exist(); } - [RequiresMSBuildVersionTheory("17.12", Reason = "Needs System.Text.Json 8.0.5")] - [InlineData("")] - [InlineData("/p:BlazorFingerprintBlazorJs=false")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] + [DataRow("")] + [DataRow("/p:BlazorFingerprintBlazorJs=false")] public void Publish_BlazorWasmReferencedByAspNetCoreServer(string publishArg) { var testInstance = CreateAspNetSdkTestAsset("BlazorWasmReferencedByAspNetCoreServer"); @@ -1669,4 +1697,4 @@ public static DirectoryInfo GetOutputDirectory(this DotnetPublishCommand command return new DirectoryInfo(Path.Combine(baseDirectory.FullName, "publish")); } } -} +} \ No newline at end of file diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPublishIntegrationTestBase.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPublishIntegrationTestBase.cs index 60b933cd6629..a868417a2a42 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPublishIntegrationTestBase.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPublishIntegrationTestBase.cs @@ -6,10 +6,13 @@ using System.Text.Json; using Microsoft.NET.Sdk.WebAssembly; using ResourceHashesByNameDictionary = System.Collections.Generic.Dictionary; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { - public abstract class WasmPublishIntegrationTestBase(ITestOutputHelper log) : AspNetSdkTest(log) +#pragma warning disable MSTEST0016 + [TestClass] + public abstract class WasmPublishIntegrationTestBase : AspNetSdkTest { protected static void VerifyBootManifestHashes(TestAsset testAsset, string blazorPublishDirectory) { @@ -60,9 +63,10 @@ static void VerifyBootManifestHashes(TestAsset testAsset, string blazorPublishDi static string ParseWebFormattedHash(string webFormattedHash) { - Assert.StartsWith("sha256-", webFormattedHash); + webFormattedHash.Should().StartWith("sha256-"); return webFormattedHash.Substring(7); } } } -} +#pragma warning restore MSTEST0016 +} \ No newline at end of file diff --git a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPwaManifestTests.cs b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPwaManifestTests.cs index 8e5cedbbe27b..8122275a4bd6 100644 --- a/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPwaManifestTests.cs +++ b/test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPwaManifestTests.cs @@ -6,13 +6,16 @@ using System.Text.Json; using System.Text.RegularExpressions; using static Microsoft.NET.Sdk.BlazorWebAssembly.Tests.ServiceWorkerAssert; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { - public class WasmPwaManifestTests(ITestOutputHelper log) : AspNetSdkTest(log) + [TestClass] + public class WasmPwaManifestTests : AspNetSdkTest { - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_ServiceWorkerAssetsManifest_Works() { // Arrange @@ -61,7 +64,8 @@ public void Build_ServiceWorkerAssetsManifest_Works() assetsManifestPath: "service-worker-assets.js"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Build_HostedAppWithServiceWorker_Works() { // Arrange @@ -87,7 +91,8 @@ public void Build_HostedAppWithServiceWorker_Works() entries.Should().Contain(e => expectedExtensions.Contains(Path.GetExtension(e))); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void PublishWithPWA_ProducesAssets() { // Arrange @@ -106,7 +111,7 @@ public void PublishWithPWA_ProducesAssets() var manifestContentsJson = JsonDocument.Parse(manifestContents); manifestContentsJson.RootElement.TryGetProperty("assets", out var assets).Should().BeTrue(); - Assert.Equal(JsonValueKind.Array, assets.ValueKind); + Assert.AreEqual(JsonValueKind.Array, assets.ValueKind); var entries = assets.EnumerateArray().Select(e => e.GetProperty("url").GetString()).OrderBy(e => e).ToArray(); entries.Should().Contain(e => expectedExtensions.Contains(Path.GetExtension(e))); @@ -115,7 +120,8 @@ public void PublishWithPWA_ProducesAssets() // Assert.FileContainsLine(result, serviceWorkerFile, "// This is the production service worker"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void PublishHostedWithPWA_ProducesAssets() { // Arrange @@ -143,7 +149,8 @@ public void PublishHostedWithPWA_ProducesAssets() // Assert.FileContainsLine(result, serviceWorkerFile, "// This is the production service worker"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_UpdatesServiceWorkerVersionHash_WhenSourcesChange() { // Arrange @@ -193,7 +200,8 @@ public void Publish_UpdatesServiceWorkerVersionHash_WhenSourcesChange() updatedCapture.Should().NotBe(capture); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12")] public void Publish_DeterministicAcrossBuilds_WhenNoSourcesChange() { // Arrange @@ -239,4 +247,4 @@ public void Publish_DeterministicAcrossBuilds_WhenNoSourcesChange() updatedCapture.Should().Be(capture); } } -} +} \ No newline at end of file diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/AspNetSdkBaselineTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/AspNetSdkBaselineTest.cs index 74e16f6b04bd..0a6adfca6746 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/AspNetSdkBaselineTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/AspNetSdkBaselineTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Reflection; using System.Runtime.CompilerServices; using System.Text.Json; @@ -10,7 +16,8 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { - [Trait("AspNetCore", "BaselineTest")] + [TestCategory("BaselineTest")] + [TestProperty("AspNetCore", "BaselineTest")] public class AspNetSdkBaselineTest : AspNetSdkTest { private static readonly JsonSerializerOptions BaselineSerializationOptions = new() { WriteIndented = true }; @@ -27,9 +34,9 @@ public class AspNetSdkBaselineTest : AspNetSdkTest private bool _generateBaselines = GenerateBaselines; - public AspNetSdkBaselineTest(ITestOutputHelper log) : base(log) + public AspNetSdkBaselineTest() { - TestAssembly = Assembly.GetCallingAssembly(); + TestAssembly = GetType().Assembly; var testAssemblyMetadata = TestAssembly.GetCustomAttributes(); RuntimeVersion = testAssemblyMetadata.SingleOrDefault(a => a.Key == "NetCoreAppRuntimePackageVersion").Value; DefaultPackageVersion = testAssemblyMetadata.SingleOrDefault(a => a.Key == "DefaultTestBaselinePackageVersion").Value; @@ -46,12 +53,6 @@ protected void EnsureLocalPackagesExists() ExecuteCommand(packDirectDependency).Should().Pass(); } - public AspNetSdkBaselineTest(ITestOutputHelper log, bool generateBaselines) : this(log) - { - _generateBaselines = generateBaselines; - _comparer = CreateBaselineComparer(); - } - public TestAsset ProjectDirectory { get; set; } public string RuntimeVersion { get; set; } diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/AssetGroupsIntegrationTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/AssetGroupsIntegrationTest.cs index 2de1933ee3f4..de60c92c16cd 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/AssetGroupsIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/AssetGroupsIntegrationTest.cs @@ -1,17 +1,24 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.IO.Compression; using Microsoft.AspNetCore.StaticWebAssets.Tasks; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { - public class AssetGroupsIntegrationTest(ITestOutputHelper log) - : IsolatedNuGetPackageFolderAspNetSdkBaselineTest(log, nameof(AssetGroupsIntegrationTest)) + [TestClass] + public class AssetGroupsIntegrationTest : IsolatedNuGetPackageFolderAspNetSdkBaselineTest { - [Fact] + protected override string RestoreNugetPackagePath => nameof(AssetGroupsIntegrationTest); + [TestMethod] public void Pack_NupkgContains_GroupedStaticWebAssets() { var packagePath = PackIdentityUILib("Pack_Nupkg"); @@ -43,7 +50,7 @@ public void Pack_NupkgContains_GroupedStaticWebAssets() } } - [Fact] + [TestMethod] public void Pack_PropsFile_ContainsAssetGroups_Metadata() { var packagePath = PackIdentityUILib("Pack_Props"); @@ -69,7 +76,7 @@ public void Pack_PropsFile_ContainsAssetGroups_Metadata() "V4 assets should have AssetGroups metadata with BootstrapVersion=V4"); } - [Fact] + [TestMethod] public void Build_ConsumerDefault_ExcludesGroupedAssets() { var manifest = BuildConsumer("Build_Default", "IdentityUIConsumer"); @@ -89,7 +96,7 @@ public void Build_ConsumerDefault_ExcludesGroupedAssets() "V5 should be the default group — at least css/site.css and js/site.js expected"); } - [Fact] + [TestMethod] public void Build_ConsumerV4_IncludesOnlyV4Assets() { var manifest = BuildConsumer("Build_V4", "IdentityUIConsumerV4"); @@ -121,7 +128,7 @@ public void Build_ConsumerV4_IncludesOnlyV4Assets() "file-only segment (~) should be excluded from endpoint routes")); } - [Fact] + [TestMethod] public void Build_ConsumerV5_IncludesOnlyV5Assets() { var manifest = BuildConsumer("Build_V5", "IdentityUIConsumerV5"); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/ComputeStaticWebAssetsTargetPathsMultiThreadingTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/ComputeStaticWebAssetsTargetPathsMultiThreadingTest.cs index 41d1fcff1b07..52e64da90738 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/ComputeStaticWebAssetsTargetPathsMultiThreadingTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/ComputeStaticWebAssetsTargetPathsMultiThreadingTest.cs @@ -1,23 +1,25 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Moq; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; -[CollectionDefinition("ProcessState", DisableParallelization = true)] -public class ProcessStateCollection -{ -} - -[Collection("ProcessState")] +[DoNotParallelize] +[TestClass] public class ComputeStaticWebAssetsTargetPathsMultiThreadingTest { - [Fact] + [TestMethod] public void ResolvesRelativeContentRootAgainstTaskEnvironmentProjectDirectoryNotProcessCurrentDirectory() { var testRoot = Path.Combine(AppContext.BaseDirectory, nameof(ComputeStaticWebAssetsTargetPathsMultiThreadingTest), Guid.NewGuid().ToString("N")); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/ComputeStaticWebAssetsTargetPathsTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/ComputeStaticWebAssetsTargetPathsTest.cs index 8bf1bafb89dd..36b8afa2b2c9 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/ComputeStaticWebAssetsTargetPathsTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/ComputeStaticWebAssetsTargetPathsTest.cs @@ -3,6 +3,12 @@ #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System; using System.Collections.Generic; using System.Linq; @@ -13,9 +19,10 @@ using Moq; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; +[TestClass] public class ComputeStaticWebAssetsTargetPathsTest { - [Fact] + [TestMethod] public void IncludesFingerprintInFileWhenPreferred() { var errorMessages = new List(); @@ -43,7 +50,7 @@ public void IncludesFingerprintInFileWhenPreferred() asset.GetMetadata("TargetPath").Should().Be(Path.Combine("wwwroot", "candidate.1234asdf.js")); } - [Fact] + [TestMethod] public void IncludesFingerprintInFileWhenRequired() { var errorMessages = new List(); @@ -71,7 +78,7 @@ public void IncludesFingerprintInFileWhenRequired() asset.GetMetadata("TargetPath").Should().Be(Path.Combine("wwwroot", "candidate.1234asdf.js")); } - [Fact] + [TestMethod] public void DoesNotIncludeFingerprintInFileWhenNotPreferred() { var errorMessages = new List(); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/DeferredAssetGroupsIntegrationTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/DeferredAssetGroupsIntegrationTest.cs index 52cd072926b7..05e7e93b1bd0 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/DeferredAssetGroupsIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/DeferredAssetGroupsIntegrationTest.cs @@ -1,17 +1,24 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Text.Json; using System.Xml.Linq; using Microsoft.AspNetCore.StaticWebAssets.Tasks; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { - public class DeferredAssetGroupsIntegrationTest(ITestOutputHelper log) : AspNetSdkTest(log) + [TestClass] + public class DeferredAssetGroupsIntegrationTest : AspNetSdkTest { - [Fact] + [TestMethod] public void Build_DeferredGroupEnabled_IncludesGroupedAssetAndEndpoints() { var intermediateOutputPath = BuildWithDeferredGroup(enableBlazorGroup: "enabled"); @@ -55,7 +62,7 @@ public void Build_DeferredGroupEnabled_IncludesGroupedAssetAndEndpoints() existingEndpoints.Should().NotBeEmpty("endpoints for existing non-grouped assets should be unaffected"); } - [Fact] + [TestMethod] public void Build_DeferredGroupDisabled_ExcludesGroupedAssetAndEndpoints() { var intermediateOutputPath = BuildWithDeferredGroup(enableBlazorGroup: "disabled"); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/FrameworkAssetsIntegrationTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/FrameworkAssetsIntegrationTest.cs index 2c87c4b69f0e..0f00d7cee2b7 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/FrameworkAssetsIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/FrameworkAssetsIntegrationTest.cs @@ -1,18 +1,25 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.IO.Compression; using System.Text.Json; using Microsoft.AspNetCore.StaticWebAssets.Tasks; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { - public class FrameworkAssetsIntegrationTest(ITestOutputHelper log) - : IsolatedNuGetPackageFolderAspNetSdkBaselineTest(log, nameof(FrameworkAssetsIntegrationTest)) + [TestClass] + public class FrameworkAssetsIntegrationTest : IsolatedNuGetPackageFolderAspNetSdkBaselineTest { - [Fact] + protected override string RestoreNugetPackagePath => nameof(FrameworkAssetsIntegrationTest); + [TestMethod] public void Pack_PropsFile_ContainsFrameworkSourceType_ForMatchedAssets() { var testAsset = "FrameworkAssetsSample"; @@ -53,7 +60,7 @@ public void Pack_PropsFile_ContainsFrameworkSourceType_ForMatchedAssets() "CSS assets not matching the FrameworkPattern should have SourceType=Package"); } - [Fact] + [TestMethod] public void Pack_NupkgContains_ExpectedStaticWebAssets() { var testAsset = "FrameworkAssetsSample"; @@ -83,7 +90,7 @@ public void Pack_NupkgContains_ExpectedStaticWebAssets() }); } - [Fact] + [TestMethod] public void Build_Consumer_MaterializesFrameworkAssets() { var (intermediateOutputPath, _) = BuildFrameworkAssetsConsumer(); @@ -116,7 +123,7 @@ public void Build_Consumer_MaterializesFrameworkAssets() "CSS assets should remain as Package type since they don't match the FrameworkPattern"); } - [Fact] + [TestMethod] public void Build_Consumer_MaterializedFrameworkAsset_FileExistsOnDisk() { var (intermediateOutputPath, _) = BuildFrameworkAssetsConsumer(); @@ -130,7 +137,7 @@ public void Build_Consumer_MaterializedFrameworkAsset_FileExistsOnDisk() "materialized file should contain the original framework.js content"); } - [Fact] + [TestMethod] public void Build_Consumer_EndpointsRemapped_ForFrameworkAssets() { var (intermediateOutputPath, _) = BuildFrameworkAssetsConsumer(); @@ -162,7 +169,7 @@ public void Build_Consumer_EndpointsRemapped_ForFrameworkAssets() "at least one endpoint for framework.js should point to the materialized file path under staticwebassets/fx/"); } - [Fact] + [TestMethod] public void Build_Consumer_IsIncremental() { var (intermediateOutputPath, _) = BuildFrameworkAssetsConsumer(); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/FrameworkAssetsP2PIntegrationTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/FrameworkAssetsP2PIntegrationTest.cs index 03f64c4ec58e..64f141b08a99 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/FrameworkAssetsP2PIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/FrameworkAssetsP2PIntegrationTest.cs @@ -1,16 +1,23 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Xml.Linq; using Microsoft.AspNetCore.StaticWebAssets.Tasks; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { - public class FrameworkAssetsP2PIntegrationTest(ITestOutputHelper log) : AspNetSdkTest(log) + [TestClass] + public class FrameworkAssetsP2PIntegrationTest : AspNetSdkTest { - [Fact] + [TestMethod] public void Build_Consumer_MaterializesFrameworkAssetsFromProjectReference() { var intermediateOutputPath = BuildConsumerWithFrameworkPattern(); @@ -45,7 +52,7 @@ public void Build_Consumer_MaterializesFrameworkAssetsFromProjectReference() } } - [Fact] + [TestMethod] public void Build_Consumer_NonMatchingAssetsRemainUnchanged() { var intermediateOutputPath = BuildConsumerWithFrameworkPattern(); @@ -61,7 +68,7 @@ public void Build_Consumer_NonMatchingAssetsRemainUnchanged() "CSS assets not matching FrameworkPattern should remain as Project type"); } - [Fact] + [TestMethod] public void Build_Consumer_MaterializedFrameworkAssetFilesExistOnDisk() { var intermediateOutputPath = BuildConsumerWithFrameworkPattern(); @@ -73,7 +80,7 @@ public void Build_Consumer_MaterializedFrameworkAssetFilesExistOnDisk() materializedFiles.Should().NotBeEmpty("JS framework assets should be copied to the fx/ directory"); } - [Fact] + [TestMethod] public void Build_Consumer_EndpointsExistForMaterializedFrameworkAssets() { var intermediateOutputPath = BuildConsumerWithFrameworkPattern(); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/GroupedFrameworkAssetsIntegrationTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/GroupedFrameworkAssetsIntegrationTest.cs index a1f9ce7d7aa4..d5cd9612dd90 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/GroupedFrameworkAssetsIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/GroupedFrameworkAssetsIntegrationTest.cs @@ -1,16 +1,23 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Xml.Linq; using Microsoft.AspNetCore.StaticWebAssets.Tasks; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { - public class GroupedFrameworkAssetsIntegrationTest(ITestOutputHelper log) - : IsolatedNuGetPackageFolderAspNetSdkBaselineTest(log, nameof(GroupedFrameworkAssetsIntegrationTest)) + [TestClass] + public class GroupedFrameworkAssetsIntegrationTest : IsolatedNuGetPackageFolderAspNetSdkBaselineTest { + protected override string RestoreNugetPackagePath => nameof(GroupedFrameworkAssetsIntegrationTest); // Regression coverage for the blazor.webassembly.js 404. A package ships an asset that is both a // framework asset and a member of a group (as Microsoft.AspNetCore.Components.WebAssembly does for // blazor.webassembly.js). The scenario is Package -> Library -> App: @@ -21,9 +28,9 @@ public class GroupedFrameworkAssetsIntegrationTest(ITestOutputHelper log) // cleared during materialization, downstream endpoint generation skips the asset and it 404s. // * The materialized framework asset is a current-project asset of the library, so the app (which // does not enable the group) does not include it at the root. - [Theory] - [InlineData(true)] - [InlineData(false)] + [TestMethod] + [DataRow(true)] + [DataRow(false)] public void Build_PackageToLibraryToApp_GroupedFrameworkAsset_IsConditionalAndMaterializedIntoLibrary(bool includeGroupedFrameworkAssets) { ProjectDirectory = CreateAspNetSdkTestAsset("GroupedFrameworkAssetsSample", identifier: includeGroupedFrameworkAssets.ToString()) diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/IsolatedNuGetPackageFolderAspNetSdkBaselineTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/IsolatedNuGetPackageFolderAspNetSdkBaselineTest.cs index 528f4606a602..53ee63351588 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/IsolatedNuGetPackageFolderAspNetSdkBaselineTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/IsolatedNuGetPackageFolderAspNetSdkBaselineTest.cs @@ -2,25 +2,29 @@ // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; + + namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { - [Trait("AspNetCore", "NugetIsolation")] - [Trait("AspNetCore", "BaselineTest")] - public class IsolatedNuGetPackageFolderAspNetSdkBaselineTest : AspNetSdkBaselineTest + [TestCategory("NugetIsolation")] + [TestCategory("BaselineTest")] + [TestProperty("AspNetCore", "NugetIsolation")] + [TestProperty("AspNetCore", "BaselineTest")] + public abstract class IsolatedNuGetPackageFolderAspNetSdkBaselineTest : AspNetSdkBaselineTest { - private readonly string _cachePath; - - public IsolatedNuGetPackageFolderAspNetSdkBaselineTest(ITestOutputHelper log, string restoreNugetPackagePath) : base(log) - { - _cachePath = Path.GetFullPath(Path.Combine(SdkTestContext.Current.TestExecutionDirectory, Shorten(restoreNugetPackagePath))); - } + protected abstract string RestoreNugetPackagePath { get; } + private string? _cachePath; + protected override string GetNuGetCachePath() => + _cachePath ??= Path.GetFullPath(Path.Combine(SdkTestContext.Current.TestExecutionDirectory, Shorten(RestoreNugetPackagePath))); private static string Shorten(string restoreNugetPackagePath) => restoreNugetPackagePath .Replace("IntegrationTest", string.Empty, StringComparison.OrdinalIgnoreCase) .Replace("Tests", string.Empty, StringComparison.OrdinalIgnoreCase); - - protected override string GetNuGetCachePath() => _cachePath; } } - diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/JsModulesIntegrationTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/JsModulesIntegrationTest.cs index d96dab0d59e5..58888340bd1b 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/JsModulesIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/JsModulesIntegrationTest.cs @@ -3,13 +3,21 @@ #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { - public class JsModulesIntegrationTest(ITestOutputHelper log) : IsolatedNuGetPackageFolderAspNetSdkBaselineTest(log, nameof(JsModulesIntegrationTest)) + [TestClass] + public class JsModulesIntegrationTest : IsolatedNuGetPackageFolderAspNetSdkBaselineTest { - [Fact] + protected override string RestoreNugetPackagePath => nameof(JsModulesIntegrationTest); + [TestMethod] public void Build_NoOps_WhenJsModulesIsDisabled() { var testAsset = "RazorComponentApp"; @@ -26,7 +34,7 @@ public void Build_NoOps_WhenJsModulesIsDisabled() new FileInfo(Path.Combine(intermediateOutputPath, "jsmodules", "jsmodules.build.manifest.json")).Should().NotExist(); } - [Fact] + [TestMethod] public void Build_GeneratesManifestWhenItFindsALibrary() { var testAsset = "RazorComponentApp"; @@ -50,7 +58,7 @@ public void Build_GeneratesManifestWhenItFindsALibrary() file.Should().Match("""ComponentApp\.[a-zA-Z-0-9]{10}\.lib\.module\.js"""); } - [Fact] + [TestMethod] public void Build_DiscoversJsModulesBasedOnPatterns() { var testAsset = "RazorComponentApp"; @@ -84,7 +92,7 @@ public void Build_DiscoversJsModulesBasedOnPatterns() intermediateOutputPath); } - [Fact] + [TestMethod] public void Publish_PublishesJsModuleBundleBundleToTheRightLocation() { var testAsset = "RazorComponentApp"; @@ -115,7 +123,7 @@ public void Publish_PublishesJsModuleBundleBundleToTheRightLocation() intermediateOutputPath); } - [Fact] + [TestMethod] public void Publish_DoesNotPublishAnyFile_WhenThereAreNoJsModulesFiles() { var testAsset = "RazorComponentApp"; @@ -130,7 +138,7 @@ public void Publish_DoesNotPublishAnyFile_WhenThereAreNoJsModulesFiles() new FileInfo(Path.Combine(publishOutputPath, "wwwroot", "ComponentApp.modules.json")).Should().NotExist(); } - [Fact] + [TestMethod] public void Does_Nothing_WhenThereAreNoJsModulesFiles() { var testAsset = "RazorComponentApp"; @@ -145,7 +153,7 @@ public void Does_Nothing_WhenThereAreNoJsModulesFiles() file.Should().NotExist(); } - [Fact] + [TestMethod] public void Build_JsModules_IsIncremental() { // Arrange @@ -180,7 +188,7 @@ public void Build_JsModules_IsIncremental() foreach (var file in files) { var thumbprint = FileThumbPrint.Create(file); - Assert.Equal(thumbprintLookup[file], thumbprint); + Assert.AreEqual(thumbprintLookup[file], thumbprint); } } } @@ -192,9 +200,11 @@ private void CreateFile(string content, params string[] path) } } - public class JsModulesPackagesIntegrationTest(ITestOutputHelper log) : IsolatedNuGetPackageFolderAspNetSdkBaselineTest(log, nameof(JsModulesPackagesIntegrationTest)) + [TestClass] + public class JsModulesPackagesIntegrationTest : IsolatedNuGetPackageFolderAspNetSdkBaselineTest { - [Fact] + protected override string RestoreNugetPackagePath => nameof(JsModulesPackagesIntegrationTest); + [TestMethod] public void BuildProjectWithReferences_IncorporatesInitializersFromClassLibraries() { var testAsset = "RazorAppWithPackageAndP2PReference"; @@ -231,7 +241,7 @@ public void BuildProjectWithReferences_IncorporatesInitializersFromClassLibrarie file.Should().Contain("_content/ClassLibrary/ClassLibrary.lib.module.js"); } - [Fact] + [TestMethod] public void PublishProjectWithReferences_IncorporatesInitializersFromClassLibrariesAndPublishesAssetsToTheRightLocation() { var testAsset = "RazorAppWithPackageAndP2PReference"; @@ -276,7 +286,7 @@ public void PublishProjectWithReferences_IncorporatesInitializersFromClassLibrar file.Should().NotContain("_content/ClassLibrary/AnotherClassLib.lib.module.js"); } - [Fact] + [TestMethod] public void PublishProjectWithReferences_DifferentBuildAndPublish_LibraryInitializers() { var testAsset = "RazorAppWithPackageAndP2PReference"; diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/LegacyStaticWebAssetsV1IntegrationTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/LegacyStaticWebAssetsV1IntegrationTest.cs index 9089ed148d04..ab19e8d1a519 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/LegacyStaticWebAssetsV1IntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/LegacyStaticWebAssetsV1IntegrationTest.cs @@ -3,14 +3,19 @@ using Microsoft.AspNetCore.StaticWebAssets.Tasks; -[assembly:CollectionBehavior(DisableTestParallelization = true)] +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { - public class LegacyStaticWebAssetsV1IntegrationTest(ITestOutputHelper log) - : IsolatedNuGetPackageFolderAspNetSdkBaselineTest(log, nameof(LegacyStaticWebAssetsV1IntegrationTest)) + [TestClass] + public class LegacyStaticWebAssetsV1IntegrationTest : IsolatedNuGetPackageFolderAspNetSdkBaselineTest { - [Fact] + protected override string RestoreNugetPackagePath => nameof(LegacyStaticWebAssetsV1IntegrationTest); + [TestMethod] public void PublishProjectWithReferences_WorksWithStaticWebAssetsV1ClassLibraries() { var testAsset = "RazorAppWithPackageAndP2PReference"; @@ -73,7 +78,7 @@ public void PublishProjectWithReferences_WorksWithStaticWebAssetsV1ClassLibrarie intermediateOutputPath); } - [Fact] + [TestMethod] public void BuildProjectWithReferences_WorksWithStaticWebAssetsV1ClassLibraries() { var testAsset = "RazorAppWithPackageAndP2PReference"; diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/Microsoft.NET.Sdk.StaticWebAssets.Tests.csproj b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/Microsoft.NET.Sdk.StaticWebAssets.Tests.csproj index 447138e1e272..4f33ec6df026 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/Microsoft.NET.Sdk.StaticWebAssets.Tests.csproj +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/Microsoft.NET.Sdk.StaticWebAssets.Tests.csproj @@ -1,4 +1,4 @@ - + false @@ -9,8 +9,16 @@ $(SdkTargetFramework) + + + None + + - Exe testSdkStaticWebAssets @@ -48,7 +56,7 @@ - + diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/ScopedCssIntegrationTests.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/ScopedCssIntegrationTests.cs index f12e024fb662..f49728631816 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/ScopedCssIntegrationTests.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/ScopedCssIntegrationTests.cs @@ -1,18 +1,25 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Text.Json; using System.Text.RegularExpressions; using Microsoft.AspNetCore.StaticWebAssets.Tasks; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { - public class ScopedCssIntegrationTest(ITestOutputHelper log) - : IsolatedNuGetPackageFolderAspNetSdkBaselineTest(log, nameof(ScopedCssIntegrationTest)) + [TestClass] + public class ScopedCssIntegrationTest : IsolatedNuGetPackageFolderAspNetSdkBaselineTest { - [Fact] + protected override string RestoreNugetPackagePath => nameof(ScopedCssIntegrationTest); + [TestMethod] public void Build_NoOps_WhenScopedCssIsDisabled() { var testAsset = "RazorComponentApp"; @@ -29,7 +36,7 @@ public void Build_NoOps_WhenScopedCssIsDisabled() new FileInfo(Path.Combine(intermediateOutputPath, "scopedcss", "Components", "Pages", "FetchData.razor.rz.scp.css")).Should().NotExist(); } - [Fact] + [TestMethod] public void Build_NoOps_ForMvcApp_WhenScopedCssIsDisabled() { var testAsset = "RazorSimpleMvc"; @@ -46,7 +53,7 @@ public void Build_NoOps_ForMvcApp_WhenScopedCssIsDisabled() new FileInfo(Path.Combine(intermediateOutputPath, "scopedcss", "Views", "Home", "About.cshtml.rz.scp.css")).Should().NotExist(); } - [Fact] + [TestMethod] public void CanDisableDefaultDiscoveryConvention() { var testAsset = "RazorComponentApp"; @@ -63,7 +70,8 @@ public void CanDisableDefaultDiscoveryConvention() new FileInfo(Path.Combine(intermediateOutputPath, "scopedcss", "Components", "Pages", "FetchData.razor.rz.scp.css")).Should().NotExist(); } - [CoreMSBuildOnlyFact] + [TestMethod] + [CoreMSBuildOnly] public void CanOverrideScopeIdentifiers() { var testAsset = "RazorComponentApp"; @@ -98,7 +106,7 @@ public void CanOverrideScopeIdentifiers() new FileInfo(Path.Combine(intermediateOutputPath, "scopedcss", "Components", "Pages", "Index.razor.rz.scp.css")).Should().NotExist(); } - [Fact] + [TestMethod] public void Build_GeneratesTransformedFilesAndBundle_ForComponentsWithScopedCss() { var testAsset = "RazorComponentApp"; @@ -116,7 +124,7 @@ public void Build_GeneratesTransformedFilesAndBundle_ForComponentsWithScopedCss( new FileInfo(Path.Combine(intermediateOutputPath, "scopedcss", "Components", "Pages", "FetchData.razor.rz.scp.css")).Should().NotExist(); } - [Fact] + [TestMethod] public void Build_GeneratesTransformedFilesAndBundle_ForViewsWithScopedCss() { var testAsset = "RazorSimpleMvc"; @@ -134,7 +142,7 @@ public void Build_GeneratesTransformedFilesAndBundle_ForViewsWithScopedCss() new FileInfo(Path.Combine(intermediateOutputPath, "scopedcss", "Views", "Home", "About.cshtml.rz.scp.css")).Should().Exist(); } - [Fact] + [TestMethod] public void Build_ScopedCssFiles_ContainsUniqueScopesPerFile() { var testAsset = "RazorComponentApp"; @@ -153,17 +161,17 @@ public void Build_ScopedCssFiles_ContainsUniqueScopesPerFile() var indexContent = File.ReadAllText(generatedIndex); var counterScopeMatch = Regex.Match(counterContent, ".*button\\[(.*)\\].*", RegexOptions.Multiline | RegexOptions.IgnoreCase); - Assert.True(counterScopeMatch.Success, "Couldn't find a scope id in the generated Counter scoped css file."); + Assert.IsTrue(counterScopeMatch.Success, "Couldn't find a scope id in the generated Counter scoped css file."); var counterScopeId = counterScopeMatch.Groups[1].Captures[0].Value; var indexScopeMatch = Regex.Match(indexContent, ".*h1\\[(.*)\\].*", RegexOptions.Multiline | RegexOptions.IgnoreCase); - Assert.True(indexScopeMatch.Success, "Couldn't find a scope id in the generated Index scoped css file."); + Assert.IsTrue(indexScopeMatch.Success, "Couldn't find a scope id in the generated Index scoped css file."); var indexScopeId = indexScopeMatch.Groups[1].Captures[0].Value; - Assert.NotEqual(counterScopeId, indexScopeId); + Assert.AreNotEqual(counterScopeId, indexScopeId); } - [Fact] + [TestMethod] public void Build_ScopedCssViews_ContainsUniqueScopesPerView() { var testAsset = "RazorSimpleMvc"; @@ -185,23 +193,23 @@ public void Build_ScopedCssViews_ContainsUniqueScopesPerView() var contactContent = File.ReadAllText(generatedContact); var indexScopeMatch = Regex.Match(indexContent, ".*p\\[(.*)\\].*", RegexOptions.Multiline | RegexOptions.IgnoreCase); - Assert.True(indexScopeMatch.Success, "Couldn't find a scope id in the generated Index scoped css file."); + Assert.IsTrue(indexScopeMatch.Success, "Couldn't find a scope id in the generated Index scoped css file."); var indexScopeId = indexScopeMatch.Groups[1].Captures[0].Value; var aboutScopeMatch = Regex.Match(aboutContent, ".*h2\\[(.*)\\].*", RegexOptions.Multiline | RegexOptions.IgnoreCase); - Assert.True(aboutScopeMatch.Success, "Couldn't find a scope id in the generated About scoped css file."); + Assert.IsTrue(aboutScopeMatch.Success, "Couldn't find a scope id in the generated About scoped css file."); var aboutScopeId = aboutScopeMatch.Groups[1].Captures[0].Value; var contactScopeMatch = Regex.Match(contactContent, ".*a\\[(.*)\\].*", RegexOptions.Multiline | RegexOptions.IgnoreCase); - Assert.True(contactScopeMatch.Success, "Couldn't find a scope id in the generated Contact scoped css file."); + Assert.IsTrue(contactScopeMatch.Success, "Couldn't find a scope id in the generated Contact scoped css file."); var contactScopeId = contactScopeMatch.Groups[1].Captures[0].Value; - Assert.NotEqual(indexScopeId, aboutScopeId); - Assert.NotEqual(indexScopeId, contactScopeId); - Assert.NotEqual(aboutScopeId, contactScopeId); + Assert.AreNotEqual(indexScopeId, aboutScopeId); + Assert.AreNotEqual(indexScopeId, contactScopeId); + Assert.AreNotEqual(aboutScopeId, contactScopeId); } - [Fact] + [TestMethod] public void Build_WorksWhenViewsAndComponentsArePartOfTheSameProject_ContainsUniqueScopesPerFile() { var testAsset = "RazorMvcWithComponents"; @@ -222,17 +230,17 @@ public void Build_WorksWhenViewsAndComponentsArePartOfTheSameProject_ContainsUni var counterContent = File.ReadAllText(generatedCounter); var indexScopeMatch = Regex.Match(indexContent, ".*p\\[(.*)\\].*", RegexOptions.Multiline | RegexOptions.IgnoreCase); - Assert.True(indexScopeMatch.Success, "Couldn't find a scope id in the generated Index scoped css file."); + Assert.IsTrue(indexScopeMatch.Success, "Couldn't find a scope id in the generated Index scoped css file."); var indexScopeId = indexScopeMatch.Groups[1].Captures[0].Value; var counterScopeMatch = Regex.Match(counterContent, ".*div\\[(.*)\\].*", RegexOptions.Multiline | RegexOptions.IgnoreCase); - Assert.True(counterScopeMatch.Success, "Couldn't find a scope id in the generated Counter scoped css file."); + Assert.IsTrue(counterScopeMatch.Success, "Couldn't find a scope id in the generated Counter scoped css file."); var counterScopeId = counterScopeMatch.Groups[1].Captures[0].Value; - Assert.NotEqual(indexScopeId, counterScopeId); + Assert.AreNotEqual(indexScopeId, counterScopeId); } - [Fact] + [TestMethod] public void Publish_PublishesScopedCssBundleToTheRightLocation() { var testAsset = "RazorComponentApp"; @@ -248,7 +256,7 @@ public void Publish_PublishesScopedCssBundleToTheRightLocation() new FileInfo(Path.Combine(publishOutputPath, "wwwroot", "_content", "ComponentApp", "Components", "Pages", "Counter.razor.rz.scp.css")).Should().NotExist(); } - [Fact] + [TestMethod] public void Publish_NoBuild_PublishesBundleToTheRightLocation() { var testAsset = "RazorComponentApp"; @@ -268,7 +276,7 @@ public void Publish_NoBuild_PublishesBundleToTheRightLocation() new FileInfo(Path.Combine(publishOutputPath, "wwwroot", "_content", "ComponentApp", "Components", "Pages", "Counter.razor.rz.scp.css")).Should().NotExist(); } - [Fact] + [TestMethod] public void Publish_DoesNotPublishAnyFile_WhenThereAreNoScopedCssFiles() { var testAsset = "RazorComponentApp"; @@ -285,7 +293,7 @@ public void Publish_DoesNotPublishAnyFile_WhenThereAreNoScopedCssFiles() new FileInfo(Path.Combine(publishOutputPath, "wwwroot", "_content", "ComponentApp", "_framework", "scoped.styles.css")).Should().NotExist(); } - [Fact] + [TestMethod] public void Publish_Publishes_IndividualScopedCssFiles_WhenNoBundlingIsEnabled() { var testAsset = "RazorComponentApp"; @@ -302,7 +310,8 @@ public void Publish_Publishes_IndividualScopedCssFiles_WhenNoBundlingIsEnabled() new FileInfo(Path.Combine(publishOutputPath, "wwwroot", "Components", "Pages", "Counter.razor.rz.scp.css")).Should().Exist(); } - [CoreMSBuildOnlyFact] + [TestMethod] + [CoreMSBuildOnly] public void Build_RemovingScopedCssAndBuilding_UpdatesGeneratedCodeAndBundle() { var testAsset = "RazorComponentApp"; @@ -335,11 +344,11 @@ public void Build_RemovingScopedCssAndBuilding_UpdatesGeneratedCodeAndBundle() var newComponentThumbprint = FileThumbPrint.Create(generatedCounter); var newBundleThumbprint = FileThumbPrint.Create(generatedBundle); - Assert.NotEqual(componentThumbprint, newComponentThumbprint); - Assert.NotEqual(bundleThumbprint, newBundleThumbprint); + Assert.AreNotEqual(componentThumbprint, newComponentThumbprint); + Assert.AreNotEqual(bundleThumbprint, newBundleThumbprint); } - [Fact] + [TestMethod] public void Does_Nothing_WhenThereAreNoScopedCssFiles() { var testAsset = "RazorComponentApp"; @@ -358,7 +367,7 @@ public void Does_Nothing_WhenThereAreNoScopedCssFiles() new FileInfo(Path.Combine(intermediateOutputPath, "scopedcss", "_framework", "scoped.styles.css")).Should().NotExist(); } - [Fact] + [TestMethod] public void Build_ScopedCssTransformation_AndBundling_IsIncremental() { // Arrange @@ -390,13 +399,13 @@ public void Build_ScopedCssTransformation_AndBundling_IsIncremental() foreach (var file in files) { var thumbprint = FileThumbPrint.Create(file); - Assert.Equal(thumbprintLookup[file], thumbprint); + Assert.AreEqual(thumbprintLookup[file], thumbprint); } } } // Regression test for https://github.com/dotnet/sdk/issues/50646 - [Fact] + [TestMethod] public void Build_RegeneratesScopedCss_WhenCssScopeMetadataChanges() { // Arrange @@ -442,8 +451,8 @@ public void Build_RegeneratesScopedCss_WhenCssScopeMetadataChanges() var newScopedCssThumbprint = FileThumbPrint.Create(scopedCssFile); var newBundleThumbprint = FileThumbPrint.Create(bundleFile); - Assert.NotEqual(initialScopedCssThumbprint, newScopedCssThumbprint); - Assert.NotEqual(initialBundleThumbprint, newBundleThumbprint); + Assert.AreNotEqual(initialScopedCssThumbprint, newScopedCssThumbprint); + Assert.AreNotEqual(initialBundleThumbprint, newBundleThumbprint); // Verify the new content uses the custom scope var newContent = File.ReadAllText(scopedCssFile); @@ -470,8 +479,8 @@ public void Build_RegeneratesScopedCss_WhenCssScopeMetadataChanges() var updatedScopedCssThumbprint = FileThumbPrint.Create(scopedCssFile); var updatedBundleThumbprint = FileThumbPrint.Create(bundleFile); - Assert.NotEqual(newScopedCssThumbprint, updatedScopedCssThumbprint); - Assert.NotEqual(newBundleThumbprint, updatedBundleThumbprint); + Assert.AreNotEqual(newScopedCssThumbprint, updatedScopedCssThumbprint); + Assert.AreNotEqual(newBundleThumbprint, updatedBundleThumbprint); // Verify the content uses the updated scope var updatedContent = File.ReadAllText(scopedCssFile); @@ -485,12 +494,12 @@ public void Build_RegeneratesScopedCss_WhenCssScopeMetadataChanges() build = CreateBuildCommand(projectDirectory); ExecuteCommand(build).Should().Pass(); - Assert.Equal(finalScopedCssThumbprint, FileThumbPrint.Create(scopedCssFile)); - Assert.Equal(finalBundleThumbprint, FileThumbPrint.Create(bundleFile)); + Assert.AreEqual(finalScopedCssThumbprint, FileThumbPrint.Create(scopedCssFile)); + Assert.AreEqual(finalBundleThumbprint, FileThumbPrint.Create(bundleFile)); } // This test verifies if the targets that VS calls to update scoped css works to update these files - [Fact] + [TestMethod] public void RegeneratingScopedCss_ForProject() { // Arrange @@ -536,10 +545,11 @@ static void AssertFileContains(string fileName, string content) } } - public class ScopedCssCompatibilityIntegrationTest(ITestOutputHelper log) - : IsolatedNuGetPackageFolderAspNetSdkBaselineTest(log, Path.Combine(nameof(ScopedCssCompatibilityIntegrationTest), ".nuget")) + [TestClass] + public class ScopedCssCompatibilityIntegrationTest : IsolatedNuGetPackageFolderAspNetSdkBaselineTest { - [Fact] + protected override string RestoreNugetPackagePath => Path.Combine(nameof(ScopedCssCompatibilityIntegrationTest), ".nuget"); + [TestMethod] public void ScopedCss_IsBackwardsCompatible_WithPreviousVersions() { var testAsset = "RazorAppWithPackageAndP2PReference"; @@ -587,7 +597,7 @@ public void ScopedCss_IsBackwardsCompatible_WithPreviousVersions() appBundle.Should().Match(""".*_content/RazorPackageLibraryDirectDependency/RazorPackageLibraryDirectDependency\.[a-zA-Z0-9]+\.bundle\.scp\.css.*"""); } - [Fact] + [TestMethod] public void ScopedCss_PublishIsBackwardsCompatible_WithPreviousVersions() { var testAsset = "RazorAppWithPackageAndP2PReference"; @@ -635,10 +645,11 @@ public void ScopedCss_PublishIsBackwardsCompatible_WithPreviousVersions() } } - public class ScopedCssPackageReferences(ITestOutputHelper log) - : IsolatedNuGetPackageFolderAspNetSdkBaselineTest(log, Path.Combine(nameof(ScopedCssPackageReferences), ".nuget")) + [TestClass] + public class ScopedCssPackageReferences : IsolatedNuGetPackageFolderAspNetSdkBaselineTest { - [Fact] + protected override string RestoreNugetPackagePath => Path.Combine(nameof(ScopedCssPackageReferences), ".nuget"); + [TestMethod] public void BuildProjectWithReferences_CorrectlyBundlesScopedCssFiles() { var testAsset = "RazorAppWithPackageAndP2PReference"; @@ -676,7 +687,7 @@ public void BuildProjectWithReferences_CorrectlyBundlesScopedCssFiles() } // Regression test for https://github.com/dotnet/aspnetcore/issues/37592 - [Fact] + [TestMethod] public void RegeneratingScopedCss_ForProjectWithReferences() { var testAsset = "RazorAppWithPackageAndP2PReference"; @@ -713,7 +724,7 @@ public void RegeneratingScopedCss_ForProjectWithReferences() text.Should().MatchRegex(""".*@import '_content/ClassLibrary/ClassLibrary\.[a-zA-Z0-9]+\.bundle\.scp\.css.*"""); } - [Fact] + [TestMethod] public void Build_GeneratesUrlEncodedLinkHeaderForNonAsciiProjectName() { var testAsset = "RazorAppWithPackageAndP2PReference"; diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetEndpointsIntegrationTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetEndpointsIntegrationTest.cs index da086c81cb7e..d833294b744f 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetEndpointsIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetEndpointsIntegrationTest.cs @@ -3,6 +3,12 @@ #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Diagnostics.Eventing.Reader; using System.Globalization; using System.Text.Json; @@ -11,8 +17,8 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; -public partial class StaticWebAssetEndpointsIntegrationTest(ITestOutputHelper log) - : AspNetSdkBaselineTest(log, GenerateBaselines) +[TestClass] +public partial class StaticWebAssetEndpointsIntegrationTest : AspNetSdkBaselineTest { [GeneratedRegex("""(?'project'[a-zA-Z0-9]+)(?:\.(?'fingerprint'[a-zA-Z0-9]*))?\.bundle\.scp\.css(?'compress'\.(?:gz|br))?$""")] private static partial Regex ProjectBundleRegex(); @@ -20,7 +26,7 @@ public partial class StaticWebAssetEndpointsIntegrationTest(ITestOutputHelper lo [GeneratedRegex("""(?'project'[a-zA-Z0-9]+)(?:\.(?'fingerprint'[a-zA-Z0-9]*))?\.styles\.css(?'compress'\.(?:gz|br))?$""")] private static partial Regex AppBundleRegex(); - [Fact] + [TestMethod] public void Build_CreatesEndpointsForAssets() { ProjectDirectory = CreateAspNetSdkTestAsset("RazorComponentApp"); @@ -170,7 +176,7 @@ private bool MatchCompressedAppBundleWithFingerprint(StaticWebAssetEndpoint ep) } && !string.IsNullOrWhiteSpace(fingerprint) && (compress == ".gz" || compress == ".br"); - [Fact] + [TestMethod] public void Publish_CreatesEndpointsForAssets() { ProjectDirectory = CreateAspNetSdkTestAsset("RazorComponentApp"); @@ -287,7 +293,7 @@ public void Publish_CreatesEndpointsForAssets() AssertManifest(manifest, LoadPublishManifest()); } - [Fact] + [TestMethod] public void Publish_CreatesEndpointsForAssets_BuildAndPublish_Assets() { ProjectDirectory = CreateAspNetSdkTestAsset("RazorComponentApp") @@ -399,7 +405,8 @@ public void Publish_CreatesEndpointsForAssets_BuildAndPublish_Assets() AssertManifest(publishManifest, LoadPublishManifest()); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12", Reason = "Needs System.Text.Json 8.0.5")] public void Build_EndpointManifest_ContainsEndpoints() { // Arrange @@ -427,7 +434,8 @@ public void Build_EndpointManifest_ContainsEndpoints() VerifyEndpointsCollection(buildOutputDirectory, "blazorwasm", readFromDevManifest: true); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12", Reason = "Needs System.Text.Json 8.0.5")] public void BuildHosted_EndpointManifest_ContainsEndpoints() { // Arrange @@ -454,7 +462,8 @@ public void BuildHosted_EndpointManifest_ContainsEndpoints() VerifyEndpointsCollection(buildOutputDirectory, "blazorhosted", readFromDevManifest: true); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12", Reason = "Needs System.Text.Json 8.0.5")] public void Publish_EndpointManifestContainsEndpoints() { // Arrange @@ -480,7 +489,8 @@ public void Publish_EndpointManifestContainsEndpoints() VerifyEndpointsCollection(publishOutputDirectory, "blazorwasm"); } - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12", Reason = "Needs System.Text.Json 8.0.5")] public void PublishHosted_EndpointManifest_ContainsEndpoints() { // Arrange @@ -506,7 +516,7 @@ public void PublishHosted_EndpointManifest_ContainsEndpoints() VerifyEndpointsCollection(publishOutputDirectory, "blazorhosted"); } - [Fact] + [TestMethod] public void Build_DefaultDocumentAndSpaFallback_CreatesAdditionalEndpoints() { ProjectDirectory = CreateAspNetSdkTestAsset("RazorComponentApp") diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ApplyCompressionNegotiationTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ApplyCompressionNegotiationTest.cs index 9e0eca9e4a7e..357fca78a162 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ApplyCompressionNegotiationTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ApplyCompressionNegotiationTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Globalization; using System.Text.Json; using Microsoft.AspNetCore.StaticWebAssets.Tasks; @@ -12,9 +18,11 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests.StaticWebAssets; +[TestClass] + public class ApplyCompressionNegotiationTest { - [Fact] + [TestMethod] public void AppliesContentNegotiationRules_ForExistingAssets() { var errorMessages = new List(); @@ -118,7 +126,7 @@ public void AppliesContentNegotiationRules_ForExistingAssets() ]); } - [Fact] + [TestMethod] public void AppliesContentNegotiationRules_ForExistingAssets_WithFingerprints() { var now = DateTime.Now; @@ -735,7 +743,7 @@ public void AppliesContentNegotiationRules_ForExistingAssets_WithFingerprints() endpoints.Should().BeEquivalentTo(expectedEndpoints); } - [Fact] + [TestMethod] public void AppliesContentNegotiationRules_ToAllRelatedAssetEndpoints() { var errorMessages = new List(); @@ -866,7 +874,7 @@ public void AppliesContentNegotiationRules_ToAllRelatedAssetEndpoints() ]); } - [Fact] + [TestMethod] public void AppliesContentNegotiationRules_IgnoresAlreadyProcessedEndpoints() { var errorMessages = new List(); @@ -1042,7 +1050,7 @@ public void AppliesContentNegotiationRules_IgnoresAlreadyProcessedEndpoints() ]); } - [Fact] + [TestMethod] public void AppliesContentNegotiationRules_ProcessesNewCompressedFormatsWhenAvailable() { var errorMessages = new List(); @@ -1284,7 +1292,7 @@ public void AppliesContentNegotiationRules_ProcessesNewCompressedFormatsWhenAvai ]); } - [Fact] + [TestMethod] public void AppliesContentNegotiationRules_AddsVaryHeaderToEndpointsWithSameRouteButDifferentAssets() { var errorMessages = new List(); @@ -1495,7 +1503,7 @@ private static ITaskItem CreateCandidateEndpoint( }.ToTaskItem(); } - [Fact] + [TestMethod] public void AppliesContentNegotiationRules_AttachesWeakETagAsResponseHeader() { var errorMessages = new List(); @@ -1562,7 +1570,7 @@ public void AppliesContentNegotiationRules_AttachesWeakETagAsResponseHeader() compressedEndpoint.ResponseHeaders.Should().Contain(h => h.Name == "ETag" && h.Value == "W/\"original-etag\""); } - [Fact] + [TestMethod] public void AppliesContentNegotiationRules_AttachesWeakETagAsEndpointProperty() { var errorMessages = new List(); @@ -1629,7 +1637,7 @@ public void AppliesContentNegotiationRules_AttachesWeakETagAsEndpointProperty() compressedEndpoint.EndpointProperties.Should().Contain(p => p.Name == "original-resource" && p.Value == "\"original-etag\""); } - [Fact] + [TestMethod] public void AppliesContentNegotiationRules_DoesNotAttachETagWhenModeIsEmpty() { var errorMessages = new List(); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ApplyCompressionNegotiationTest.cs.bak b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ApplyCompressionNegotiationTest.cs.bak deleted file mode 100644 index 2044287327ce..000000000000 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ApplyCompressionNegotiationTest.cs.bak +++ /dev/null @@ -1,1429 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#nullable disable - -using System.Globalization; -using System.Text.Json; -using Microsoft.AspNetCore.StaticWebAssets.Tasks; -using Microsoft.Build.Framework; -using Microsoft.Build.Utilities; -using Moq; - -namespace Microsoft.NET.Sdk.StaticWebAssets.Tests.StaticWebAssets; - -public class ApplyCompressionNegotiationTest -{ - [Fact] - public void AppliesContentNegotiationRules_ForExistingAssets() - { - var errorMessages = new List(); - var buildEngine = new Mock(); - buildEngine.Setup(e => e.LogErrorEvent(It.IsAny())) - .Callback(args => errorMessages.Add(args.Message)); - - var task = new ApplyCompressionNegotiation - { - BuildEngine = buildEngine.Object, - CandidateAssets = - [ - CreateCandidate( - Path.Combine("wwwroot", "candidate.js"), - "MyPackage", - "Discovered", - "candidate.js", - "All", - "All", - "original-fingerprint", - "original", - fileLength: 20 - ), - CreateCandidate( - Path.Combine("compressed", "candidate.js.gz"), - "MyPackage", - "Discovered", - "candidate.js", - "All", - "All", - "compressed-fingerprint", - "compressed", - Path.Combine("wwwroot", "candidate.js"), - "Content-Encoding", - "gzip", - 9 - ) - ], - CandidateEndpoints = - [ - CreateCandidateEndpoint( - "candidate.js", - Path.Combine("wwwroot", "candidate.js"), - CreateHeaders("text/javascript", [("Content-Length", "20")])), - - CreateCandidateEndpoint( - "candidate.js.gz", - Path.Combine("compressed", "candidate.js.gz"), - CreateHeaders("text/javascript", [("Content-Length", "9")])) - ], - }; - - // Act - var result = task.Execute(); - - // Assert - result.Should().Be(true); - var endpoints = StaticWebAssetEndpoint.FromItemGroup(task.UpdatedEndpoints); - endpoints.Should().BeEquivalentTo((StaticWebAssetEndpoint[])[ - new () - { - Route = "candidate.js", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "gzip" }, - new () { Name = "Content-Length", Value = "9" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - new () { Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [ new () { Name = "Content-Encoding", Value = "gzip", Quality = "0.100000000000" } ], - }, - new () - { - Route = "candidate.js", - AssetFile = Path.GetFullPath(Path.Combine("wwwroot", "candidate.js")), - ResponseHeaders = - [ - new () { Name = "Content-Length", Value = "20" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - ], - EndpointProperties = [], - Selectors = [], - }, - new () - { - Route = "candidate.js.gz", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "gzip" }, - new () { Name = "Content-Length", Value = "9" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - new () { Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [] - } - ]); - } - - [Fact] - public void AppliesContentNegotiationRules_ForExistingAssets_WithFingerprints() - { - var now = DateTime.Now; - var errorMessages = new List(); - var buildEngine = new Mock(); - buildEngine.Setup(e => e.LogErrorEvent(It.IsAny())) - .Callback(args => errorMessages.Add(args.Message)); - - List candidateAssets = [ - CreateCandidate( - Path.Combine("wwwroot", "candidate.js"), - "MyPackage", - "Discovered", - "candidate#[.{fingerprint}]?.js", - "All", - "All", - "original-fingerprint", - "original", - fileLength: 20, - lastModified: now - ) - ]; - - var compressedTask = new ResolveCompressedAssets - { - BuildEngine = buildEngine.Object, - CandidateAssets = [.. candidateAssets], - Formats = "gzip;brotli", - IncludePatterns = "*.js", - OutputPath = AppContext.BaseDirectory - }; - compressedTask.Execute().Should().BeTrue(); - - var compressedAssets = compressedTask.AssetsToCompress; - compressedAssets[0].SetMetadata(nameof(StaticWebAsset.Fingerprint), "gzip"); - compressedAssets[0].SetMetadata(nameof(StaticWebAsset.Integrity), "compressed-gzip"); - compressedAssets[0].SetMetadata(nameof(StaticWebAsset.FileLength), "9"); - compressedAssets[1].SetMetadata(nameof(StaticWebAsset.Fingerprint), "brotli"); - compressedAssets[1].SetMetadata(nameof(StaticWebAsset.Integrity), "compressed-brotli"); - compressedAssets[1].SetMetadata(nameof(StaticWebAsset.FileLength), "7"); - candidateAssets.AddRange(compressedAssets); - var expectedName = Path.GetFileNameWithoutExtension(compressedAssets[0].ItemSpec); - var defineStaticAssetEndpointsTask = new DefineStaticWebAssetEndpoints - { - BuildEngine = buildEngine.Object, - CandidateAssets = [.. candidateAssets], - ExistingEndpoints = [], - ContentTypeMappings = [] - }; - defineStaticAssetEndpointsTask.Execute().Should().BeTrue(); - var compressed = defineStaticAssetEndpointsTask.Endpoints; - - var task = new ApplyCompressionNegotiation - { - BuildEngine = buildEngine.Object, - CandidateAssets = [.. candidateAssets], - CandidateEndpoints = compressed, - }; - - // Act - var result = task.Execute(); - - // Assert - result.Should().Be(true); - var endpoints = StaticWebAssetEndpoint.FromItemGroup(task.UpdatedEndpoints); - var expectedEndpoints = new StaticWebAssetEndpoint[] - { - new() - { - Route = "candidate.fingerprint.js", - AssetFile = Path.Combine(AppContext.BaseDirectory, $"{expectedName}.br"), - Selectors = [ - new () - { - Name = "Content-Encoding", - Value = "br", - Quality = "0.125000000000" - } - ], - ResponseHeaders = [ - new () - { - Name = "Cache-Control", - Value = "max-age=31536000, immutable" - }, - new () - { - Name = "Content-Encoding", - Value = "br" - }, - new () - { - Name = "Content-Length", - Value = "7" - }, - new () - { - Name = "Content-Type", - Value = "text/javascript" - }, - new () - { - Name = "ETag", - Value = "\u0022compressed-brotli\u0022" - }, - new () - { - Name = "ETag", - Value = "W/\u0022original\u0022" - }, - new () - { - Name = "Last-Modified", - Value = now.ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture) - }, - new () - { - Name = "Vary", - Value = "Content-Encoding" - } - ], - EndpointProperties = [ - new () - { - Name = "fingerprint", - Value = "fingerprint" - }, - new () - { - Name = "integrity", - Value = "sha256-original" - }, - new () - { - Name = "label", - Value = "candidate.js" - } - ] - }, - new() - { - Route = "candidate.fingerprint.js", - AssetFile = Path.Combine(AppContext.BaseDirectory, $"{expectedName}.gz"), - Selectors = [ - new () - { - Name = "Content-Encoding", - Value = "gzip", - Quality = "0.100000000000" - } - ], - ResponseHeaders = [ - new () - { - Name = "Accept-Ranges", - Value = "bytes" - }, - new () - { - Name = "Cache-Control", - Value = "max-age=31536000, immutable" - }, - new () - { - Name = "Content-Encoding", - Value = "gzip" - }, - new () - { - Name = "Content-Length", - Value = "9" - }, - new () - { - Name = "Content-Type", - Value = "text/javascript" - }, - new () - { - Name = "ETag", - Value = "\u0022compressed-gzip\u0022" - }, - new () - { - Name = "ETag", - Value = "W/\u0022original\u0022" - }, - new () - { - Name = "Last-Modified", - Value = now.ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture) - }, - new () - { - Name = "Vary", - Value = "Content-Encoding" - } - ], - EndpointProperties = [ - new () - { - Name = "fingerprint", - Value = "fingerprint" - }, - new () - { - Name = "integrity", - Value = "sha256-original" - }, - new () - { - Name = "label", - Value = "candidate.js" - } - ] - }, - new() - { - Route = "candidate.fingerprint.js", - AssetFile = Path.Combine(AppContext.BaseDirectory, "wwwroot", "candidate.js"), - ResponseHeaders = [ - new () - { - Name = "Accept-Ranges", - Value = "bytes" - }, - new () - { - Name = "Cache-Control", - Value = "max-age=31536000, immutable" - }, - new () - { - Name = "Content-Length", - Value = "20" - }, - new () - { - Name = "Content-Type", - Value = "text/javascript" - }, - new () - { - Name = "ETag", - Value = "\u0022original\u0022" - }, - new () - { - Name = "Last-Modified", - Value = now.ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture) - } - ], - EndpointProperties = [ - new () - { - Name = "fingerprint", - Value = "fingerprint" - }, - new () - { - Name = "integrity", - Value = "sha256-original" - }, - new () - { - Name = "label", - Value = "candidate.js" - } - ] - }, - new() - { - Route = "candidate.fingerprint.js.br", - AssetFile = Path.Combine(AppContext.BaseDirectory, $"{expectedName}.br"), - ResponseHeaders = [ - new () - { - Name = "Accept-Ranges", - Value = "bytes" - }, - new () - { - Name = "Cache-Control", - Value = "max-age=31536000, immutable" - }, - new () - { - Name = "Content-Encoding", - Value = "br" - }, - new () - { - Name = "Content-Length", - Value = "7" - }, - new () - { - Name = "Content-Type", - Value = "text/javascript" - }, - new () - { - Name = "ETag", - Value = "\u0022compressed-brotli\u0022" - }, - new () - { - Name = "Last-Modified", - Value = now.ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture) - }, - new () - { - Name = "Vary", - Value = "Content-Encoding" - } - ], - EndpointProperties = [ - new () - { - Name = "fingerprint", - Value = "fingerprint" - }, - new () - { - Name = "integrity", - Value = "sha256-compressed-brotli" - }, - new () - { - Name = "label", - Value = "candidate.js.br" - } - ] - }, - new() - { - Route = "candidate.fingerprint.js.gz", - AssetFile = Path.Combine(AppContext.BaseDirectory, $"{expectedName}.gz"), - ResponseHeaders = [ - new () - { - Name = "Accept-Ranges", - Value = "bytes" - }, - new () - { - Name = "Cache-Control", - Value = "max-age=31536000, immutable" - }, - new () - { - Name = "Content-Encoding", - Value = "gzip" - }, - new () - { - Name = "Content-Length", - Value = "9" - }, - new () - { - Name = "Content-Type", - Value = "text/javascript" - }, - new () - { - Name = "ETag", - Value = "\u0022compressed-gzip\u0022" - }, - new () - { - Name = "Last-Modified", - Value = now.ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture) - }, - new () - { - Name = "Vary", - Value = "Content-Encoding" - } - ], - EndpointProperties = [ - new () - { - Name = "fingerprint", - Value = "fingerprint" - }, - new () - { - Name = "integrity", - Value = "sha256-compressed-gzip" - }, - new () - { - Name = "label", - Value = "candidate.js.gz" - } - ] - }, - new() - { - Route = "candidate.js", - AssetFile = Path.Combine(AppContext.BaseDirectory, $"{expectedName}.br"), - Selectors = [ - new () - { - Name = "Content-Encoding", - Value = "br", - Quality = "0.125000000000" - } - ], - ResponseHeaders = [ - new () - { - Name = "Accept-Ranges", - Value = "bytes" - }, - new () - { - Name = "Cache-Control", - Value = "no-cache" - }, - new () - { - Name = "Content-Encoding", - Value = "br" - }, - new () - { - Name = "Content-Length", - Value = "7" - }, - new () - { - Name = "Content-Type", - Value = "text/javascript" - }, - new () - { - Name = "ETag", - Value = "\u0022compressed-brotli\u0022" - }, - new () - { - Name = "ETag", - Value = "W/\u0022original\u0022" - }, - new () - { - Name = "Last-Modified", - Value = now.ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture) - }, - new () - { - Name = "Vary", - Value = "Content-Encoding" - } - ], - EndpointProperties = [ - new () - { - Name = "integrity", - Value = "sha256-original" - } - ] - }, - new() - { - Route = "candidate.js", - AssetFile = Path.Combine(AppContext.BaseDirectory, $"{expectedName}.gz"), - Selectors = [ - new () - { - Name = "Content-Encoding", - Value = "gzip", - Quality = "0.100000000000" - } - ], - ResponseHeaders = [ - new () - { - Name = "Accept-Ranges", - Value = "bytes" - }, - new () - { - Name = "Cache-Control", - Value = "no-cache" - }, - new () - { - Name = "Content-Encoding", - Value = "gzip" - }, - new () - { - Name = "Content-Length", - Value = "9" - }, - new () - { - Name = "Content-Type", - Value = "text/javascript" - }, - new () - { - Name = "ETag", - Value = "\u0022compressed-gzip\u0022" - }, - new () - { - Name = "ETag", - Value = "W/\u0022original\u0022" - }, - new () - { - Name = "Last-Modified", - Value = now.ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture) - }, - new () - { - Name = "Vary", - Value = "Content-Encoding" - } - ], - EndpointProperties = [ - new () - { - Name = "integrity", - Value = "sha256-original" - } - ] - }, - new() - { - Route = "candidate.js", - AssetFile = Path.Combine(AppContext.BaseDirectory, "wwwroot", "candidate.js"), - ResponseHeaders = [ - new () - { - Name = "Accept-Ranges", - Value = "bytes" - }, - new () - { - Name = "Cache-Control", - Value = "no-cache" - }, - new () - { - Name = "Content-Length", - Value = "20" - }, - new () - { - Name = "Content-Type", - Value = "text/javascript" - }, - new () - { - Name = "ETag", - Value = "\u0022original\u0022" - }, - new () - { - Name = "Last-Modified", - Value = now.ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture) - } - ], - EndpointProperties = [ - new () - { - Name = "integrity", - Value = "sha256-original" - } - ] - }, - new() - { - Route = "candidate.js.br", - AssetFile = Path.Combine(AppContext.BaseDirectory, $"{expectedName}.br"), - ResponseHeaders = [ - new () - { - Name = "Accept-Ranges", - Value = "bytes" - }, - new () - { - Name = "Cache-Control", - Value = "no-cache" - }, - new () - { - Name = "Content-Encoding", - Value = "br" - }, - new () - { - Name = "Content-Length", - Value = "7" - }, - new () - { - Name = "Content-Type", - Value = "text/javascript" - }, - new () - { - Name = "ETag", - Value = "\u0022compressed-brotli\u0022" - }, - new () - { - Name = "Last-Modified", - Value = now.ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture) - }, - new () - { - Name = "Vary", - Value = "Content-Encoding" - } - ], - EndpointProperties = [ - new () - { - Name = "integrity", - Value = "sha256-compressed-brotli" - } - ] - }, - new() - { - Route = "candidate.js.gz", - AssetFile = Path.Combine(AppContext.BaseDirectory, $"{expectedName}.gz"), - ResponseHeaders = [ - new () { - Name = "Accept-Ranges", - Value = "bytes" - }, - new () { - Name = "Cache-Control", - Value = "no-cache" - }, - new () { - Name = "Content-Encoding", - Value = "gzip" - }, - new () { - Name = "Content-Length", - Value = "9" - }, - new () { - Name = "Content-Type", - Value = "text/javascript" - }, - new () { - Name = "ETag", - Value = "\u0022compressed-gzip\u0022" - }, - new () { - Name = "Last-Modified", - Value = now.ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture) - }, - new () { - Name = "Vary", - Value = "Content-Encoding" - } - ], - EndpointProperties = [ - new () { - Name = "integrity", - Value = "sha256-compressed-gzip" - } - ] - } -}; - - endpoints.Should().BeEquivalentTo(expectedEndpoints); - } - - [Fact] - public void AppliesContentNegotiationRules_ToAllRelatedAssetEndpoints() - { - var errorMessages = new List(); - var buildEngine = new Mock(); - buildEngine.Setup(e => e.LogErrorEvent(It.IsAny())) - .Callback(args => errorMessages.Add(args.Message)); - - var task = new ApplyCompressionNegotiation - { - BuildEngine = buildEngine.Object, - CandidateAssets = - [ - CreateCandidate( - Path.Combine("wwwroot", "candidate.js"), - "MyPackage", - "Discovered", - "candidate.js", - "All", - "All", - "original-fingerprint", - "original", - fileLength: 20 - ), - CreateCandidate( - Path.Combine("compressed", "candidate.js.gz"), - "MyPackage", - "Discovered", - "candidate.js", - "All", - "All", - "compressed-fingerprint", - "compressed", - Path.Combine("wwwroot", "candidate.js"), - "Content-Encoding", - "gzip", - fileLength: 9 - ) - ], - CandidateEndpoints = - [ - CreateCandidateEndpoint( - "candidate.js", - Path.Combine("wwwroot", "candidate.js"), - CreateHeaders("text/javascript")), - CreateCandidateEndpoint( - "candidate.fingerprint.js", - Path.Combine("wwwroot", "candidate.js"), - CreateHeaders("text/javascript")), - CreateCandidateEndpoint( - "candidate.js.gz", - Path.Combine("compressed", "candidate.js.gz"), - CreateHeaders("text/javascript")) - ], - }; - - // Act - var result = task.Execute(); - - // Assert - result.Should().Be(true); - var endpoints = StaticWebAssetEndpoint.FromItemGroup(task.UpdatedEndpoints); - endpoints.Should().BeEquivalentTo((StaticWebAssetEndpoint[])[ - new () - { - Route = "candidate.js", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "gzip" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - new () { Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [ new () { Name = "Content-Encoding", Value = "gzip", Quality = "0.100000000000" } ], - }, - new () - { - Route = "candidate.js", - AssetFile = Path.GetFullPath(Path.Combine("wwwroot", "candidate.js")), - ResponseHeaders = - [ - new () { Name = "Content-Type", Value = "text/javascript" } - ], - EndpointProperties = [], - Selectors = [], - }, - new () - { - Route = "candidate.fingerprint.js", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "gzip" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - new () { Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [ new () { Name = "Content-Encoding", Value = "gzip", Quality = "0.100000000000" } ], - }, - new () - { - Route = "candidate.fingerprint.js", - AssetFile = Path.GetFullPath(Path.Combine("wwwroot", "candidate.js")), - ResponseHeaders = - [ - new () { Name = "Content-Type", Value = "text/javascript" } - ], - EndpointProperties = [], - Selectors = [], - }, - new () - { - Route = "candidate.js.gz", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "gzip" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - new () { Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [] - } - ]); - } - - [Fact] - public void AppliesContentNegotiationRules_IgnoresAlreadyProcessedEndpoints() - { - var errorMessages = new List(); - var buildEngine = new Mock(); - buildEngine.Setup(e => e.LogErrorEvent(It.IsAny())) - .Callback(args => errorMessages.Add(args.Message)); - - var task = new ApplyCompressionNegotiation - { - BuildEngine = buildEngine.Object, - CandidateAssets = - [ - CreateCandidate( - Path.Combine("wwwroot", "candidate.js"), - "MyPackage", - "Discovered", - "candidate.js", - "All", - "All", - "original-fingerprint", - "original" - ), - CreateCandidate( - Path.Combine("compressed", "candidate.js.gz"), - "MyPackage", - "Discovered", - "candidate.js", - "All", - "All", - "compressed-fingerprint", - "compressed", - Path.Combine("wwwroot", "candidate.js"), - "Content-Encoding", - "gzip" - ) - ], - CandidateEndpoints = new StaticWebAssetEndpoint[] - { - new() - { - Route = "candidate.js", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "gzip" }, - new (){ Name = "Content-Type", Value = "text/javascript" }, - new (){ Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [ new StaticWebAssetEndpointSelector { Name = "Content-Encoding", Value = "gzip", Quality = "0.100000000000" } ], - }, - new() - { - Route = "candidate.js", - AssetFile = Path.GetFullPath(Path.Combine("wwwroot", "candidate.js")), - ResponseHeaders = - [ - new (){ Name = "Content-Type", Value = "text/javascript" } - ], - EndpointProperties = [], - Selectors = [], - }, - new() - { - Route = "candidate.fingerprint.js", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new (){ Name = "Content-Encoding", Value = "gzip" }, - new (){ Name = "Content-Type", Value = "text/javascript" }, - new (){ Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [ new () { Name = "Content-Encoding", Value = "gzip", Quality = "0.100000000000" } ], - }, - new() - { - Route = "candidate.fingerprint.js", - AssetFile = Path.GetFullPath(Path.Combine("wwwroot", "candidate.js")), - ResponseHeaders = - [ - new () { Name = "Content-Type", Value = "text/javascript" } - ], - EndpointProperties = [], - Selectors = [], - }, - new() - { - Route = "candidate.js.gz", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "gzip" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - new () { Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [] - } - }.Select(e => e.ToTaskItem()).ToArray(), - }; - - // Act - var result = task.Execute(); - - // Assert - result.Should().Be(true); - var endpoints = StaticWebAssetEndpoint.FromItemGroup(task.UpdatedEndpoints); - endpoints.Should().BeEquivalentTo([ - new StaticWebAssetEndpoint - { - Route = "candidate.js", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "gzip" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - new () { Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [ new StaticWebAssetEndpointSelector { Name = "Content-Encoding", Value = "gzip", Quality = "0.100000000000" } ], - }, - new StaticWebAssetEndpoint - { - Route = "candidate.js", - AssetFile = Path.GetFullPath(Path.Combine("wwwroot", "candidate.js")), - ResponseHeaders = - [ - new () { Name = "Content-Type", Value = "text/javascript" } - ], - EndpointProperties = [], - Selectors = [], - }, - new StaticWebAssetEndpoint - { - Route = "candidate.fingerprint.js", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "gzip" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - new () { Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [ new StaticWebAssetEndpointSelector { Name = "Content-Encoding", Value = "gzip", Quality = "0.100000000000" } ], - }, - new StaticWebAssetEndpoint - { - Route = "candidate.fingerprint.js", - AssetFile = Path.GetFullPath(Path.Combine("wwwroot", "candidate.js")), - ResponseHeaders = - [ - new () { Name = "Content-Type", Value = "text/javascript" } - ], - EndpointProperties = [], - Selectors = [], - }, - new StaticWebAssetEndpoint - { - Route = "candidate.js.gz", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "gzip" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - new () { Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [] - } - ]); - } - - [Fact] - public void AppliesContentNegotiationRules_ProcessesNewCompressedFormatsWhenAvailable() - { - var errorMessages = new List(); - var buildEngine = new Mock(); - buildEngine.Setup(e => e.LogErrorEvent(It.IsAny())) - .Callback(args => errorMessages.Add(args.Message)); - - var task = new ApplyCompressionNegotiation - { - BuildEngine = buildEngine.Object, - CandidateAssets = - [ - CreateCandidate( - Path.Combine("wwwroot", "candidate.js"), - "MyPackage", - "Discovered", - "candidate.js", - "All", - "All", - "original-fingerprint", - "original", - fileLength: 20 - ), - CreateCandidate( - Path.Combine("compressed", "candidate.js.gz"), - "MyPackage", - "Discovered", - "candidate.js", - "All", - "All", - "compressed-gzip", - "compressed", - Path.Combine("wwwroot", "candidate.js"), - "Content-Encoding", - "gzip", - fileLength: 9 - ), - CreateCandidate( - Path.Combine("compressed", "candidate.js.br"), - "MyPackage", - "Discovered", - "candidate.js", - "All", - "All", - "compressed-brotli", - "compressed", - Path.Combine("wwwroot", "candidate.js"), - "Content-Encoding", - "br", - fileLength: 9 - ) - ], - CandidateEndpoints = new StaticWebAssetEndpoint[] - { - new() - { - Route = "candidate.js", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "gzip" }, - new (){ Name = "Content-Type", Value = "text/javascript" }, - new (){ Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [ new StaticWebAssetEndpointSelector { Name = "Content-Encoding", Value = "gzip", Quality = "0.100000000000" } ], - }, - new() - { - Route = "candidate.js", - AssetFile = Path.GetFullPath(Path.Combine("wwwroot", "candidate.js")), - ResponseHeaders = - [ - new (){ Name = "Content-Type", Value = "text/javascript" } - ], - EndpointProperties = [], - Selectors = [], - }, - new() - { - Route = "candidate.fingerprint.js", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new (){ Name = "Content-Encoding", Value = "gzip" }, - new (){ Name = "Content-Type", Value = "text/javascript" }, - new (){ Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [ new () { Name = "Content-Encoding", Value = "gzip", Quality = "0.100000000000" } ], - }, - new() - { - Route = "candidate.fingerprint.js", - AssetFile = Path.GetFullPath(Path.Combine("wwwroot", "candidate.js")), - ResponseHeaders = - [ - new () { Name = "Content-Type", Value = "text/javascript" } - ], - EndpointProperties = [], - Selectors = [], - }, - new() - { - Route = "candidate.js.gz", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "gzip" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - new () { Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [] - }, - new() - { - Route = "candidate.js.br", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.br")), - ResponseHeaders = - [ - new () { Name = "Content-Type", Value = "text/javascript" }, - ], - EndpointProperties = [], - Selectors = [] - } - }.Select(e => e.ToTaskItem()).ToArray(), - }; - - // Act - var result = task.Execute(); - - // Assert - result.Should().Be(true); - var endpoints = StaticWebAssetEndpoint.FromItemGroup(task.UpdatedEndpoints); - endpoints.Should().BeEquivalentTo([ - new StaticWebAssetEndpoint - { - Route = "candidate.js", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "gzip" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - new () { Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [ new StaticWebAssetEndpointSelector { Name = "Content-Encoding", Value = "gzip", Quality = "0.100000000000" } ], - }, - new StaticWebAssetEndpoint - { - Route = "candidate.js", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.br")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "br" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - new () { Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [ new StaticWebAssetEndpointSelector { Name = "Content-Encoding", Value = "br", Quality = "0.100000000000" } ], - }, - new StaticWebAssetEndpoint - { - Route = "candidate.js", - AssetFile = Path.GetFullPath(Path.Combine("wwwroot", "candidate.js")), - ResponseHeaders = - [ - new () { Name = "Content-Type", Value = "text/javascript" } - ], - EndpointProperties = [], - Selectors = [], - }, - new StaticWebAssetEndpoint - { - Route = "candidate.fingerprint.js", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "gzip" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - new () { Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [ new StaticWebAssetEndpointSelector { Name = "Content-Encoding", Value = "gzip", Quality = "0.100000000000" } ], - }, - new StaticWebAssetEndpoint - { - Route = "candidate.fingerprint.js", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.br")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "br" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - new () { Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [ new StaticWebAssetEndpointSelector { Name = "Content-Encoding", Value = "br", Quality = "0.100000000000" } ], - }, - new StaticWebAssetEndpoint - { - Route = "candidate.fingerprint.js", - AssetFile = Path.GetFullPath(Path.Combine("wwwroot", "candidate.js")), - ResponseHeaders = - [ - new () { Name = "Content-Type", Value = "text/javascript" } - ], - EndpointProperties = [], - Selectors = [], - }, - new StaticWebAssetEndpoint - { - Route = "candidate.js.gz", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.gz")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "gzip" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - new () { Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [] - }, - new StaticWebAssetEndpoint - { - Route = "candidate.js.br", - AssetFile = Path.GetFullPath(Path.Combine("compressed", "candidate.js.br")), - ResponseHeaders = - [ - new () { Name = "Content-Encoding", Value = "br" }, - new () { Name = "Content-Type", Value = "text/javascript" }, - new () { Name = "Vary", Value = "Content-Encoding" } - ], - EndpointProperties = [], - Selectors = [] - } - ]); - } - - private static StaticWebAssetEndpointSelector[] CreateContentEcondingSelector(string name, string value) - { - return - [ - new StaticWebAssetEndpointSelector - { - Name = name, - Value = value, - Quality = "0.100000000000" - } - ]; - } - - private static StaticWebAssetEndpointResponseHeader[] CreateHeaders(string contentType, params (string name, string value)[] AdditionalHeaders) - { - return - [ - new StaticWebAssetEndpointResponseHeader { - Name = "Content-Type", - Value = contentType - }, - ..(AdditionalHeaders ?? []).Select(h => new StaticWebAssetEndpointResponseHeader { Name = h.name, Value = h.value }) - ]; - } - - private static ITaskItem CreateCandidate( - string itemSpec, - string sourceId, - string sourceType, - string relativePath, - string assetKind, - string assetMode, - string fingerprint = "", - string integrity = "", - string relatedAsset = "", - string assetTraitName = "", - string assetTraitValue = "", - long fileLength = 9, - DateTimeOffset? lastModified = null) - { - lastModified ??= new DateTimeOffset(2023, 10, 1, 0, 0, 0, TimeSpan.Zero); - var result = new StaticWebAsset() - { - Identity = Path.GetFullPath(itemSpec), - SourceId = sourceId, - SourceType = sourceType, - ContentRoot = Directory.GetCurrentDirectory(), - BasePath = "base", - RelativePath = relativePath, - AssetKind = assetKind, - AssetMode = assetMode, - AssetRole = "Primary", - RelatedAsset = relatedAsset, - AssetTraitName = assetTraitName, - AssetTraitValue = assetTraitValue, - CopyToOutputDirectory = "", - CopyToPublishDirectory = "", - OriginalItemSpec = itemSpec, - // Add these to avoid accessing the disk to compute them - Integrity = integrity, - Fingerprint = "fingerprint", - FileLength = fileLength, - LastWriteTime = lastModified.Value, - }; - - result.ApplyDefaults(); - result.Normalize(); - - return result.ToTaskItem(); - } - - private static ITaskItem CreateCandidateEndpoint( - string route, - string assetFile, - StaticWebAssetEndpointResponseHeader[] responseHeaders = null, - StaticWebAssetEndpointSelector[] responseSelector = null, - StaticWebAssetEndpointProperty[] properties = null) - { - return new StaticWebAssetEndpoint - { - Route = route, - AssetFile = Path.GetFullPath(assetFile), - ResponseHeaders = responseHeaders ?? [], - EndpointProperties = properties ?? [], - Selectors = responseSelector ?? [] - }.ToTaskItem(); - } -} diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ApplyCssScopesTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ApplyCssScopesTest.cs index db19972aa054..aecb16809e36 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ApplyCssScopesTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ApplyCssScopesTest.cs @@ -1,16 +1,23 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.AspNetCore.StaticWebAssets.Tasks; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Moq; +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { + [TestClass] public class ApplyAllCssScopesTest { - [Fact] + [TestMethod] public void ApplyAllCssScopes_AppliesScopesToRazorComponentFiles() { // Arrange @@ -39,7 +46,7 @@ public void ApplyAllCssScopes_AppliesScopesToRazorComponentFiles() taskInstance.RazorComponentsWithScopes.Should().ContainSingle(rcws => rcws.ItemSpec == "TestFiles/Pages/Counter.razor" && rcws.GetMetadata("CssScope") == "counter-scope"); } - [Fact] + [TestMethod] public void ApplyAllCssScopes_AppliesScopesToRazorViewFiles() { // Arrange @@ -68,7 +75,7 @@ public void ApplyAllCssScopes_AppliesScopesToRazorViewFiles() taskInstance.RazorGenerateWithScopes.Should().ContainSingle(rcws => rcws.ItemSpec == "TestFiles/Pages/Counter.cshtml" && rcws.GetMetadata("CssScope") == "counter-scope"); } - [Fact] + [TestMethod] public void DoesNotApplyCssScopes_ToRazorComponentsWithoutAssociatedFiles() { // Arrange @@ -92,12 +99,12 @@ public void DoesNotApplyCssScopes_ToRazorComponentsWithoutAssociatedFiles() var result = taskInstance.Execute(); // Assert - Assert.True(result); + Assert.IsTrue(result); result.Should().BeTrue(); taskInstance.RazorComponentsWithScopes.Should().NotContain(rcws => rcws.ItemSpec == "TestFiles/Pages/Fetchdata.razor"); } - [Fact] + [TestMethod] public void DoesNotApplyCssScopes_ToRazorViewsWithoutAssociatedFiles() { // Arrange @@ -121,12 +128,12 @@ public void DoesNotApplyCssScopes_ToRazorViewsWithoutAssociatedFiles() var result = taskInstance.Execute(); // Assert - Assert.True(result); + Assert.IsTrue(result); result.Should().BeTrue(); taskInstance.RazorGenerateWithScopes.Should().NotContain(rcws => rcws.ItemSpec == "TestFiles/Pages/Fetchdata.razor"); } - [Fact] + [TestMethod] public void ApplyAllCssScopes_FailsWhenTheScopedCss_DoesNotMatchTheRazorComponent() { // Arrange @@ -154,7 +161,7 @@ public void ApplyAllCssScopes_FailsWhenTheScopedCss_DoesNotMatchTheRazorComponen result.Should().BeFalse(); } - [Fact] + [TestMethod] public void ApplyAllCssScopes_FailsWhenTheScopedCss_DoesNotMatchTheRazorView() { // Arrange @@ -182,7 +189,7 @@ public void ApplyAllCssScopes_FailsWhenTheScopedCss_DoesNotMatchTheRazorView() result.Should().BeFalse(); } - [Fact] + [TestMethod] public void ScopedCssCanDefineAssociatedRazorComponentFile() { // Arrange @@ -211,7 +218,7 @@ public void ScopedCssCanDefineAssociatedRazorComponentFile() taskInstance.RazorComponentsWithScopes.Should().ContainSingle(rcws => rcws.ItemSpec == "TestFiles/Pages/FetchData.razor" && rcws.GetMetadata("CssScope") == "fetchdata-scope"); } - [Fact] + [TestMethod] public void ScopedCssCanDefineAssociatedRazorGenerateFile() { // Arrange @@ -240,7 +247,7 @@ public void ScopedCssCanDefineAssociatedRazorGenerateFile() taskInstance.RazorGenerateWithScopes.Should().ContainSingle(rcws => rcws.ItemSpec == "TestFiles/Pages/FetchData.cshtml" && rcws.GetMetadata("CssScope") == "fetchdata-scope"); } - [Fact] + [TestMethod] public void ApplyAllCssScopes_FailsWhenMultipleScopedCssFiles_MatchTheSameRazorComponent() { // Arrange @@ -272,7 +279,7 @@ public void ApplyAllCssScopes_FailsWhenMultipleScopedCssFiles_MatchTheSameRazorC result.Should().BeFalse(); } - [Fact] + [TestMethod] public void ApplyAllCssScopes_FailsWhenMultipleScopedCssFiles_MatchTheSameRazorView() { // Arrange @@ -304,7 +311,7 @@ public void ApplyAllCssScopes_FailsWhenMultipleScopedCssFiles_MatchTheSameRazorV result.Should().BeFalse(); } - [Fact] + [TestMethod] public void ApplyAllCssScopes_AppliesScopesToRazorComponentAndViewFiles() { // Arrange @@ -343,7 +350,7 @@ public void ApplyAllCssScopes_AppliesScopesToRazorComponentAndViewFiles() taskInstance.RazorGenerateWithScopes.Should().ContainSingle(rcws => rcws.ItemSpec == "TestFiles/Pages/_Host.cshtml" && rcws.GetMetadata("CssScope") == "_host-scope"); } - [Fact] + [TestMethod] public void ApplyAllCssScopes_ScopedCssComponentsDontMatchWithScopedCssViewStylesAndViceversa() { // Arrange diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/AssetGroupFilteringTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/AssetGroupFilteringTest.cs index 79a5f1f1a6c4..eeb5a05f58b4 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/AssetGroupFilteringTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/AssetGroupFilteringTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Moq; @@ -14,6 +20,7 @@ namespace Microsoft.AspNetCore.StaticWebAssets.Tasks; /// UpdateExternallyDefinedStaticWebAssets, ComputeReferenceStaticWebAssetItems and /// DefineStaticWebAssets.ApplyGroupDefinitions. /// +[TestClass] public class AssetGroupFilteringTest : IDisposable { private readonly string _tempDir; @@ -44,7 +51,7 @@ public void Dispose() } } - [Fact] + [TestMethod] public void UpdateExternal_AssetWithGroups_MatchingDeclaration_IsIncluded() { var file = CreateTempFile("ext", "site.css", "body{}"); @@ -71,7 +78,7 @@ public void UpdateExternal_AssetWithGroups_MatchingDeclaration_IsIncluded() task.UpdatedAssets.Should().HaveCount(1); } - [Fact] + [TestMethod] public void UpdateExternal_AssetWithGroups_NoDeclarations_IsExcluded() { var file = CreateTempFile("ext", "site.css", "body{}"); @@ -91,7 +98,7 @@ public void UpdateExternal_AssetWithGroups_NoDeclarations_IsExcluded() task.UpdatedAssets.Should().HaveCount(0, "grouped assets should be excluded when no declarations exist"); } - [Fact] + [TestMethod] public void UpdateExternal_MultiGroup_PartialMatch_IsExcluded() { var file = CreateTempFile("ext", "site.css", "body{}"); @@ -118,7 +125,7 @@ public void UpdateExternal_MultiGroup_PartialMatch_IsExcluded() task.UpdatedAssets.Should().HaveCount(0, "AND-matching requires all entries satisfied"); } - [Fact] + [TestMethod] public void UpdateExternal_CascadingExclusion_RelatedAssetExcludedWithPrimary() { var primaryFile = CreateTempFile("ext", "css", "site.css", "body{}"); @@ -145,7 +152,7 @@ public void UpdateExternal_CascadingExclusion_RelatedAssetExcludedWithPrimary() task.UpdatedAssets.Should().HaveCount(0, "related asset should cascade-exclude with primary"); } - [Fact] + [TestMethod] public void UpdateExternal_EndpointFiltering_ExcludedAssetEndpointsRemoved() { var includedFile = CreateTempFile("ext", "app.js", "var x;"); @@ -185,7 +192,7 @@ public void UpdateExternal_EndpointFiltering_ExcludedAssetEndpointsRemoved() task.UpdatedEndpoints.Should().HaveCount(1, "only endpoints for included assets should remain"); } - [Fact] + [TestMethod] public void ComputeReference_GroupedFrameworkAsset_PreservesSourceType() { // Two grouped framework assets at the same target path @@ -216,7 +223,7 @@ public void ComputeReference_GroupedFrameworkAsset_PreservesSourceType() } } - [Fact] + [TestMethod] public void ComputeReference_NonGroupedFrameworkAsset_PreservesSourceType() { var asset = CreateReferenceAsset("framework.js", "FrameworkLib", "Framework", "js/framework.js", "All", "All"); @@ -240,7 +247,7 @@ public void ComputeReference_NonGroupedFrameworkAsset_PreservesSourceType() "non-grouped framework assets should also preserve SourceType=Framework"); } - [Fact] + [TestMethod] public void ApplyGroupDefinitions_SameOrderSameSourceId_ProducesError() { var file = CreateTempFile("wwwroot", "V5", "css", "site.css", "body{}"); @@ -275,7 +282,7 @@ public void ApplyGroupDefinitions_SameOrderSameSourceId_ProducesError() _errorMessages.Should().ContainMatch("*same Order*"); } - [Fact] + [TestMethod] public void ApplyGroupDefinitions_DifferentOrderSameSourceId_NoError() { var file = CreateTempFile("wwwroot", "V5", "css", "site.css", "body{}"); @@ -310,7 +317,7 @@ public void ApplyGroupDefinitions_DifferentOrderSameSourceId_NoError() _errorMessages.Should().BeEmpty(); } - [Fact] + [TestMethod] public void ApplyGroupDefinitions_MissingValue_ProducesError() { var file = CreateTempFile("wwwroot", "V4", "css", "site.css", "body{}"); @@ -334,7 +341,7 @@ public void ApplyGroupDefinitions_MissingValue_ProducesError() _errorMessages.Should().ContainSingle(m => m.Contains("missing required metadata 'Value'")); } - [Fact] + [TestMethod] public void ApplyGroupDefinitions_MissingSourceId_ProducesError() { var file = CreateTempFile("wwwroot", "V4", "css", "site.css", "body{}"); @@ -358,7 +365,7 @@ public void ApplyGroupDefinitions_MissingSourceId_ProducesError() _errorMessages.Should().ContainSingle(m => m.Contains("missing required metadata 'SourceId'")); } - [Fact] + [TestMethod] public void ApplyGroupDefinitions_InvalidOrder_ProducesError() { var file = CreateTempFile("wwwroot", "V4", "css", "site.css", "body{}"); @@ -382,7 +389,7 @@ public void ApplyGroupDefinitions_InvalidOrder_ProducesError() _errorMessages.Should().ContainSingle(m => m.Contains("invalid or missing 'Order'")); } - [Fact] + [TestMethod] public void ApplyGroupDefinitions_MissingIncludePattern_ProducesError() { var file = CreateTempFile("wwwroot", "V4", "css", "site.css", "body{}"); @@ -406,7 +413,7 @@ public void ApplyGroupDefinitions_MissingIncludePattern_ProducesError() _errorMessages.Should().ContainSingle(m => m.Contains("missing required metadata 'IncludePattern'")); } - [Fact] + [TestMethod] public void ApplyGroupDefinitions_SourceIdMismatch_DefinitionsIgnored() { var file = CreateTempFile("wwwroot", "V4", "css", "site.css", "body-v4{}"); @@ -437,7 +444,7 @@ public void ApplyGroupDefinitions_SourceIdMismatch_DefinitionsIgnored() asset.RelativePath.Should().Contain("V4", "RelativePath should not be transformed"); } - [Fact] + [TestMethod] public void ApplyGroupDefinitions_MultipleContentRootSuffix_Compose() { var file = CreateTempFile("wwwroot", "shared", "site.css", "body{}"); @@ -474,10 +481,10 @@ public void ApplyGroupDefinitions_MultipleContentRootSuffix_Compose() asset.ContentRoot.Should().Contain(Path.Combine("suffixA", "suffixB")); } - [Theory] - [InlineData(new[] { "BootstrapVersion=V4", "BootstrapVersion=V5" }, true)] - [InlineData(new[] { "BootstrapVersion=V4", "" }, false)] - [InlineData(new[] { "BootstrapVersion=V5", "BootstrapVersion=V5" }, false)] + [TestMethod] + [DataRow(new[] { "BootstrapVersion=V4", "BootstrapVersion=V5" }, true)] + [DataRow(new[] { "BootstrapVersion=V4", "" }, false)] + [DataRow(new[] { "BootstrapVersion=V5", "BootstrapVersion=V5" }, false)] public void AllAssetsHaveDistinctGroups_ReturnsExpectedResult(string[] groups, bool expected) { var assets = groups.Select((g, i) => CreateStaticWebAsset($"{(char)('a' + i)}.css", g)).ToList(); @@ -637,7 +644,7 @@ private DefineStaticWebAssets CreateDefineStaticWebAssetsTask( }; } - [Fact] + [TestMethod] public void ApplyGroupDefinitions_ContentRootSuffix_AdjustsContentRoot() { var file = CreateTempFile("wwwroot", "V4", "css", "site.css", "body-v4{}"); @@ -671,7 +678,7 @@ public void ApplyGroupDefinitions_ContentRootSuffix_AdjustsContentRoot() asset.AssetGroups.Should().Contain("BootstrapVersion=V4"); } - [Fact] + [TestMethod] public void ApplyGroupDefinitions_PatternOnly_NoAutoFileOnlyToken() { var file = CreateTempFile("wwwroot", "V4", "css", "site.css", "body-v4{}"); @@ -705,7 +712,7 @@ public void ApplyGroupDefinitions_PatternOnly_NoAutoFileOnlyToken() asset.ContentRoot.Should().Be(wwwrootPath, "ContentRoot unchanged when no ContentRootSuffix"); } - [Fact] + [TestMethod] public void ApplyGroupDefinitions_RelativePathPrefix_FileOnlyToken() { var file = CreateTempFile("wwwroot", "V4", "css", "site.css", "body-v4{}"); @@ -739,7 +746,7 @@ public void ApplyGroupDefinitions_RelativePathPrefix_FileOnlyToken() asset.AssetGroups.Should().Contain("BootstrapVersion=V4"); } - [Fact] + [TestMethod] public void ApplyGroupDefinitions_RelativePathPrefix_LiteralPrepend() { var file = CreateTempFile("wwwroot", "V4", "css", "site.css", "body-v4{}"); @@ -772,7 +779,7 @@ public void ApplyGroupDefinitions_RelativePathPrefix_LiteralPrepend() asset.ContentRoot.Should().Be(wwwrootPath, "ContentRoot unchanged when no ContentRootSuffix"); } - [Fact] + [TestMethod] public void ApplyGroupDefinitions_AllThreeOrthogonal() { var file = CreateTempFile("wwwroot", "V4", "css", "site.css", "body-v4{}"); @@ -808,7 +815,7 @@ public void ApplyGroupDefinitions_AllThreeOrthogonal() asset.AssetGroups.Should().Contain("BootstrapVersion=V4"); } - [Fact] + [TestMethod] public void ApplyGroupDefinitions_RelativePathPrefix_WithoutPattern_PrependsToOriginalPath() { var file = CreateTempFile("wwwroot", "css", "site.css", "body{}"); @@ -843,7 +850,7 @@ public void ApplyGroupDefinitions_RelativePathPrefix_WithoutPattern_PrependsToOr asset.AssetGroups.Should().Contain("Theme=Default"); } - [Fact] + [TestMethod] public void ApplyGroupDefinitions_ContentRootSuffix_MultipleGroups_EachGetsOwnContentRoot() { var fileV4 = CreateTempFile("wwwroot", "V4", "css", "site.css", "body-v4{}"); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/AssetToCompressTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/AssetToCompressTest.cs index c32b7b8dd3f7..babd0f1abecb 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/AssetToCompressTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/AssetToCompressTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks.Utils; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -10,6 +16,8 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; +[TestClass] + public class AssetToCompressTest : IDisposable { private readonly string _testDirectory; @@ -47,7 +55,7 @@ public void Dispose() } } - [Fact] + [TestMethod] public void TryFindInputFilePath_UsesRelatedAsset_WhenFileExists() { // Arrange @@ -64,7 +72,7 @@ public void TryFindInputFilePath_UsesRelatedAsset_WhenFileExists() _errorMessages.Should().BeEmpty(); } - [Fact] + [TestMethod] public void TryFindInputFilePath_FallsBackToRelatedAssetOriginalItemSpec_WhenRelatedAssetDoesNotExist() { // Arrange @@ -81,7 +89,7 @@ public void TryFindInputFilePath_FallsBackToRelatedAssetOriginalItemSpec_WhenRel _errorMessages.Should().BeEmpty(); } - [Fact] + [TestMethod] public void TryFindInputFilePath_ReturnsError_WhenNeitherPathExists() { // Arrange @@ -103,7 +111,7 @@ public void TryFindInputFilePath_ReturnsError_WhenNeitherPathExists() _errorMessages[0].Should().Contain(nonExistentPath2); } - [Fact] + [TestMethod] public void TryFindInputFilePath_PrefersRelatedAsset_OverRelatedAssetOriginalItemSpec_WhenBothExist() { // Arrange - create two files to simulate the scenario where both metadata values point to existing files @@ -126,7 +134,7 @@ public void TryFindInputFilePath_PrefersRelatedAsset_OverRelatedAssetOriginalIte _errorMessages.Should().BeEmpty(); } - [Fact] + [TestMethod] public void TryFindInputFilePath_HandlesEmptyRelatedAsset_AndUsesRelatedAssetOriginalItemSpec() { // Arrange @@ -143,7 +151,7 @@ public void TryFindInputFilePath_HandlesEmptyRelatedAsset_AndUsesRelatedAssetOri _errorMessages.Should().BeEmpty(); } - [Fact] + [TestMethod] public void TryFindInputFilePath_HandlesEsprojScenario_WhereOriginalItemSpecPointsToProjectFile() { // Arrange - simulate the esproj bug scenario where RelatedAssetOriginalItemSpec diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/CollectStaticWebAssetsToCopyMultiThreadingTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/CollectStaticWebAssetsToCopyMultiThreadingTest.cs index b1b72340d5f0..e651b193c59d 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/CollectStaticWebAssetsToCopyMultiThreadingTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/CollectStaticWebAssetsToCopyMultiThreadingTest.cs @@ -9,13 +9,13 @@ namespace Microsoft.AspNetCore.Razor.Tasks; -// Test parallelization is disabled assembly-wide via -// [assembly:CollectionBehavior(DisableTestParallelization = true)] in -// LegacyStaticWebAssetsV1IntegrationTest.cs, which already isolates the -// process-CWD mutation this test performs. +// This test mutates the process-wide current directory, so it must not run +// concurrently with other tests under MSTest's method-level parallelization. +[DoNotParallelize] +[TestClass] public class CollectStaticWebAssetsToCopyMultiThreadingTest { - [Fact] + [TestMethod] public void ResolvesOutputPathRelativeToTaskEnvironmentProjectDirectory() { var testRoot = Path.Combine(AppContext.BaseDirectory, nameof(CollectStaticWebAssetsToCopyMultiThreadingTest), Guid.NewGuid().ToString("N")); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeCssScopesTests.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeCssScopesTests.cs index 98dd095c3dbb..54ef5da1423f 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeCssScopesTests.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeCssScopesTests.cs @@ -1,15 +1,22 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Text.RegularExpressions; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace Microsoft.NET.Sdk.Razor.Test { + [TestClass] public class ComputeCssScopesTests { - [Fact] + [TestMethod] public void ComputesScopes_ComputesUniqueScopes_ForCssFiles() { // Arrange @@ -35,7 +42,7 @@ public void ComputesScopes_ComputesUniqueScopes_ForCssFiles() taskInstance.ScopedCss.Select(s => s.GetMetadata("CssScope")).Should().HaveCount(3).And.OnlyHaveUniqueItems(); } - [Fact] + [TestMethod] public void ComputesScopes_ScopeVariesByTargetName() { // Arrange @@ -61,7 +68,7 @@ public void ComputesScopes_ScopeVariesByTargetName() taskInstance.ScopedCss.Should().OnlyContain(newScoped => !existing.Contains(newScoped.GetMetadata("ScopedCss"))); } - [Fact] + [TestMethod] public void ComputesScopes_IsDeterministic() { // Arrange @@ -87,7 +94,7 @@ public void ComputesScopes_IsDeterministic() computed.Should().Equal(existing); } - [Fact] + [TestMethod] public void ComputesScopes_VariesByPath() { // Arrange @@ -110,7 +117,7 @@ public void ComputesScopes_VariesByPath() taskInstance.ScopedCss[0].GetMetadata("CssScope").Should().NotBe(taskInstance.ScopedCss[1].GetMetadata("CssScope")); } - [Fact] + [TestMethod] public void ComputesScopes_PreservesUserDefinedScopes() { // Arrange diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeEndpointsForReferenceStaticWebAssetsMultiThreadingTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeEndpointsForReferenceStaticWebAssetsMultiThreadingTest.cs index dcb3f60196f7..a88ca0dab1c8 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeEndpointsForReferenceStaticWebAssetsMultiThreadingTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeEndpointsForReferenceStaticWebAssetsMultiThreadingTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -10,9 +16,12 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; +[DoNotParallelize] +[TestClass] + public class ComputeEndpointsForReferenceStaticWebAssetsMultiThreadingTest { - [Fact] + [TestMethod] public void ProducesCorrectEndpointsWhenTaskEnvironmentProjectDirectoryDiffersFromProcessCurrentDirectory() { var testRoot = Path.Combine(AppContext.BaseDirectory, nameof(ComputeEndpointsForReferenceStaticWebAssetsMultiThreadingTest), Guid.NewGuid().ToString("N")); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeEndpointsForReferenceStaticWebAssetsTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeEndpointsForReferenceStaticWebAssetsTest.cs index e76a6966a269..b1f79a0dfb47 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeEndpointsForReferenceStaticWebAssetsTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeEndpointsForReferenceStaticWebAssetsTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -10,9 +16,11 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; +[TestClass] + public class ComputeEndpointsForReferenceStaticWebAssetsTest { - [Fact] + [TestMethod] public void IncludesEndpointsForAssetsFromCurrentProject() { var errorMessages = new List(); @@ -37,7 +45,7 @@ public void IncludesEndpointsForAssetsFromCurrentProject() task.Endpoints[0].GetMetadata("AssetFile").Should().Be(Path.GetFullPath(Path.Combine("wwwroot", "candidate.js"))); } - [Fact] + [TestMethod] public void UpdatesLabelAsNecessary_ForChosenEndpoints() { var errorMessages = new List(); @@ -66,7 +74,7 @@ public void UpdatesLabelAsNecessary_ForChosenEndpoints() properties[0].Value.Should().Be("base/label-value"); } - [Fact] + [TestMethod] public void FiltersOutEndpointsForAssetsNotFound() { var errorMessages = new List(); @@ -94,7 +102,7 @@ public void FiltersOutEndpointsForAssetsNotFound() task.Endpoints[0].GetMetadata("AssetFile").Should().Be(Path.GetFullPath(Path.Combine("wwwroot", "candidate.js"))); } - [Fact] + [TestMethod] public void AppliesBasePathWhenRouteStartsWithBasePathButNotAsPathSegment() { // This test verifies the fix for a bug where routes like "App1.styles.css" @@ -133,7 +141,7 @@ public void AppliesBasePathWhenRouteStartsWithBasePathButNotAsPathSegment() task.Endpoints[0].ItemSpec.Should().Be("App1/App1.styles.css"); } - [Fact] + [TestMethod] public void SkipsBasePathApplicationWhenRouteAlreadyHasBasePathAsPathSegment() { // This test verifies that routes already starting with "BasePath/" are correctly skipped diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeReferenceStaticWebAssetItemsTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeReferenceStaticWebAssetItemsTest.cs index 35fdeb12359b..bfde1b9a2ac1 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeReferenceStaticWebAssetItemsTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeReferenceStaticWebAssetItemsTest.cs @@ -1,17 +1,22 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable - +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Moq; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { + [TestClass] public class ComputeReferenceStaticWebAssetItemsTest { - [Fact] + [TestMethod] public void IncludesAssetsFromCurrentProjectAsReferencedAssets() { var errorMessages = new List(); @@ -37,7 +42,7 @@ public void IncludesAssetsFromCurrentProjectAsReferencedAssets() task.StaticWebAssets.Should().HaveCount(1); } - [Fact] + [TestMethod] public void IncludesPatternsFromCurrentProject() { var errorMessages = new List(); @@ -63,7 +68,7 @@ public void IncludesPatternsFromCurrentProject() task.DiscoveryPatterns.Should().HaveCount(1); } - [Fact] + [TestMethod] public void FiltersPatternsFromReferencedProjects() { var errorMessages = new List(); @@ -89,7 +94,7 @@ public void FiltersPatternsFromReferencedProjects() task.DiscoveryPatterns.Should().HaveCount(0); } - [Fact] + [TestMethod] public void PrefersSpecificKindAssetsOverAllKindAssets() { var errorMessages = new List(); @@ -120,7 +125,7 @@ public void PrefersSpecificKindAssetsOverAllKindAssets() task.StaticWebAssets[0].ItemSpec.Should().Be(Path.GetFullPath(Path.Combine("wwwroot", "candidate.other.js"))); } - [Fact] + [TestMethod] public void AllAssetGetsIgnoredWhenBuildAndPublishAssetsAreDefined() { var errorMessages = new List(); @@ -152,9 +157,9 @@ public void AllAssetGetsIgnoredWhenBuildAndPublishAssetsAreDefined() task.StaticWebAssets[0].ItemSpec.Should().Be(Path.GetFullPath(Path.Combine("wwwroot", "candidate.other.js"))); } - [Theory] - [InlineData("Build", "Publish")] - [InlineData("Publish", "Build")] + [TestMethod] + [DataRow("Build", "Publish")] + [DataRow("Publish", "Build")] public void FiltersAssetsForOppositeKind(string assetKind, string manifestKind) { var errorMessages = new List(); @@ -180,7 +185,7 @@ public void FiltersAssetsForOppositeKind(string assetKind, string manifestKind) task.StaticWebAssets.Should().HaveCount(0); } - [Fact] + [TestMethod] public void FiltersCurrentProjectOnlyAssetsInDefaultMode() { var errorMessages = new List(); @@ -206,7 +211,7 @@ public void FiltersCurrentProjectOnlyAssetsInDefaultMode() task.StaticWebAssets.Should().HaveCount(0); } - [Fact] + [TestMethod] public void IncludesReferenceAssetsInDefaultMode() { var errorMessages = new List(); @@ -232,7 +237,7 @@ public void IncludesReferenceAssetsInDefaultMode() task.StaticWebAssets.Should().HaveCount(1); } - [Fact] + [TestMethod] public void IncludesCurrentProjectAssetsInRootMode() { var errorMessages = new List(); @@ -258,7 +263,7 @@ public void IncludesCurrentProjectAssetsInRootMode() task.StaticWebAssets.Should().HaveCount(1); } - [Fact] + [TestMethod] public void FiltersReferenceOnlyAssetsInRootMode() { var errorMessages = new List(); @@ -284,7 +289,7 @@ public void FiltersReferenceOnlyAssetsInRootMode() task.StaticWebAssets.Should().HaveCount(0); } - [Fact] + [TestMethod] public void FiltersAssetsFromOtherProjects() { var errorMessages = new List(); @@ -310,7 +315,7 @@ public void FiltersAssetsFromOtherProjects() task.StaticWebAssets.Should().HaveCount(0); } - [Fact] + [TestMethod] public void FiltersAssetsFromPackages() { var errorMessages = new List(); @@ -336,7 +341,7 @@ public void FiltersAssetsFromPackages() task.StaticWebAssets.Should().HaveCount(0); } - [Fact] + [TestMethod] public void AppliesFrameworkPatternToDiscoveredAssets() { var errorMessages = new List(); @@ -369,7 +374,7 @@ public void AppliesFrameworkPatternToDiscoveredAssets() task.StaticWebAssets[1].GetMetadata("SourceType").Should().Be("Project"); } - [Fact] + [TestMethod] public void FrameworkPatternDoesNotAffectNonDiscoveredAssets() { var errorMessages = new List(); @@ -398,7 +403,7 @@ public void FrameworkPatternDoesNotAffectNonDiscoveredAssets() task.StaticWebAssets[0].GetMetadata("SourceType").Should().Be("Project"); } - [Fact] + [TestMethod] public void PreservesAssetGroupsOnFrameworkAssets() { var errorMessages = new List(); @@ -431,7 +436,8 @@ public void PreservesAssetGroupsOnFrameworkAssets() task.StaticWebAssets[0].GetMetadata("AssetGroups").Should().Be("MyGroup"); } - [Fact] + [TestMethod] + [DoNotParallelize] public void MakeReferencedAssetOriginalItemSpecAbsolute_ResolvesAgainstProjectDirectoryNotProcessCurrentDirectory() { var testRoot = Path.Combine(AppContext.BaseDirectory, nameof(ComputeReferenceStaticWebAssetItemsTest), Guid.NewGuid().ToString("N")); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeStaticWebAssetsForCurrentProjectTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeStaticWebAssetsForCurrentProjectTest.cs index 3ffa48fa7ced..9410b7b91e0b 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeStaticWebAssetsForCurrentProjectTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ComputeStaticWebAssetsForCurrentProjectTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Text.Json; using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; @@ -10,9 +16,10 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { + [TestClass] public class ComputeStaticWebAssetsForCurrentProjectTest { - [Fact] + [TestMethod] public void IncludesAssetsFromCurrentProject() { var errorMessages = new List(); @@ -37,7 +44,7 @@ public void IncludesAssetsFromCurrentProject() task.StaticWebAssets.Should().HaveCount(1); } - [Fact] + [TestMethod] public void PrefersSpecificKindAssetsOverAllKindAssets() { var errorMessages = new List(); @@ -67,7 +74,7 @@ public void PrefersSpecificKindAssetsOverAllKindAssets() task.StaticWebAssets[0].ItemSpec.Should().Be(Path.GetFullPath(Path.Combine("wwwroot", "candidate.other.js"))); } - [Fact] + [TestMethod] public void AllAssetGetsIgnoredWhenBuildAndPublishAssetsAreDefined() { var errorMessages = new List(); @@ -98,9 +105,9 @@ public void AllAssetGetsIgnoredWhenBuildAndPublishAssetsAreDefined() task.StaticWebAssets[0].ItemSpec.Should().Be(Path.GetFullPath(Path.Combine("wwwroot", "candidate.other.js"))); } - [Theory] - [InlineData("Build", "Publish")] - [InlineData("Publish", "Build")] + [TestMethod] + [DataRow("Build", "Publish")] + [DataRow("Publish", "Build")] public void FiltersAssetsForOppositeKind(string assetKind, string manifestKind) { var errorMessages = new List(); @@ -125,7 +132,7 @@ public void FiltersAssetsForOppositeKind(string assetKind, string manifestKind) task.StaticWebAssets.Should().HaveCount(0); } - [Fact] + [TestMethod] public void IncludesCurrentProjectOnlyAssetsInDefaultMode() { var errorMessages = new List(); @@ -150,7 +157,7 @@ public void IncludesCurrentProjectOnlyAssetsInDefaultMode() task.StaticWebAssets.Should().HaveCount(1); } - [Fact] + [TestMethod] public void FiltersReferenceAssetsInDefaultMode() { var errorMessages = new List(); @@ -175,7 +182,7 @@ public void FiltersReferenceAssetsInDefaultMode() task.StaticWebAssets.Should().HaveCount(0); } - [Fact] + [TestMethod] public void IncludesCurrentProjectAssetsInRootMode() { var errorMessages = new List(); @@ -200,7 +207,7 @@ public void IncludesCurrentProjectAssetsInRootMode() task.StaticWebAssets.Should().HaveCount(1); } - [Fact] + [TestMethod] public void FiltersReferenceOnlyAssetsInRootMode() { var errorMessages = new List(); @@ -225,7 +232,7 @@ public void FiltersReferenceOnlyAssetsInRootMode() task.StaticWebAssets.Should().HaveCount(0); } - [Fact] + [TestMethod] public void IncludesAssetsFromOtherProjects() { var errorMessages = new List(); @@ -250,7 +257,7 @@ public void IncludesAssetsFromOtherProjects() task.StaticWebAssets.Should().HaveCount(1); } - [Fact] + [TestMethod] public void IncludesAssetsFromPackages() { var errorMessages = new List(); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ConcatenateFilesTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ConcatenateFilesTest.cs index 71c9af0dda70..a6bf84bf262a 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ConcatenateFilesTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ConcatenateFilesTest.cs @@ -1,14 +1,22 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.AspNetCore.StaticWebAssets.Tasks; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace Microsoft.NET.Sdk.Razor.Test { + [TestClass] public class ConcatenateCssFilesTest { + public TestContext TestContext { get; set; } = null!; private static readonly string BundleContent = @"/* _content/Test/TestFiles/Generated/Counter.razor.rz.scp.css */ .counter { @@ -49,7 +57,7 @@ public class ConcatenateCssFilesTest } "; - [Fact] + [TestMethod] public void BundlesScopedCssFiles_ProducesEmpyBundleIfNoFilesAvailable() { // Arrange @@ -70,7 +78,7 @@ public void BundlesScopedCssFiles_ProducesEmpyBundleIfNoFilesAvailable() File.ReadAllText(expectedFile).Should().BeEmpty(); } - [Fact] + [TestMethod] public void BundlesScopedCssFiles_ProducesBundle() { // Arrange @@ -129,7 +137,7 @@ private static TaskItem CreateStaticAsset(string identity, string basePath, stri ["CopyToPublishDirectory"] = "PreserveNewest" }); - [Fact] + [TestMethod] public void BundlesScopedCssFiles_IncludesOtherBundles() { // Arrange @@ -167,21 +175,21 @@ public void BundlesScopedCssFiles_IncludesOtherBundles() actualContents.Should().Contain(BundleWithImportsContent); } - [Theory] - [InlineData("", "", "TestFiles/Generated/lib.bundle.scp.css")] - [InlineData("/", "/", "TestFiles/Generated/lib.bundle.scp.css")] - [InlineData("app", "_content", "../_content/TestFiles/Generated/lib.bundle.scp.css")] - [InlineData("app", "/_content", "../_content/TestFiles/Generated/lib.bundle.scp.css")] - [InlineData("app", "/_content/", "../_content/TestFiles/Generated/lib.bundle.scp.css")] - [InlineData("/app", "_content", "../_content/TestFiles/Generated/lib.bundle.scp.css")] - [InlineData("/app", "/_content", "../_content/TestFiles/Generated/lib.bundle.scp.css")] - [InlineData("/app", "/_content/", "../_content/TestFiles/Generated/lib.bundle.scp.css")] - [InlineData("app/", "_content", "../_content/TestFiles/Generated/lib.bundle.scp.css")] - [InlineData("app/", "/_content", "../_content/TestFiles/Generated/lib.bundle.scp.css")] - [InlineData("app/", "/_content/", "../_content/TestFiles/Generated/lib.bundle.scp.css")] - [InlineData("/company/app/", "_content", "../../_content/TestFiles/Generated/lib.bundle.scp.css")] - [InlineData("/company/app/", "/_content", "../../_content/TestFiles/Generated/lib.bundle.scp.css")] - [InlineData("/company/app/", "/_content/", "../../_content/TestFiles/Generated/lib.bundle.scp.css")] + [TestMethod] + [DataRow("", "", "TestFiles/Generated/lib.bundle.scp.css")] + [DataRow("/", "/", "TestFiles/Generated/lib.bundle.scp.css")] + [DataRow("app", "_content", "../_content/TestFiles/Generated/lib.bundle.scp.css")] + [DataRow("app", "/_content", "../_content/TestFiles/Generated/lib.bundle.scp.css")] + [DataRow("app", "/_content/", "../_content/TestFiles/Generated/lib.bundle.scp.css")] + [DataRow("/app", "_content", "../_content/TestFiles/Generated/lib.bundle.scp.css")] + [DataRow("/app", "/_content", "../_content/TestFiles/Generated/lib.bundle.scp.css")] + [DataRow("/app", "/_content/", "../_content/TestFiles/Generated/lib.bundle.scp.css")] + [DataRow("app/", "_content", "../_content/TestFiles/Generated/lib.bundle.scp.css")] + [DataRow("app/", "/_content", "../_content/TestFiles/Generated/lib.bundle.scp.css")] + [DataRow("app/", "/_content/", "../_content/TestFiles/Generated/lib.bundle.scp.css")] + [DataRow("/company/app/", "_content", "../../_content/TestFiles/Generated/lib.bundle.scp.css")] + [DataRow("/company/app/", "/_content", "../../_content/TestFiles/Generated/lib.bundle.scp.css")] + [DataRow("/company/app/", "/_content/", "../../_content/TestFiles/Generated/lib.bundle.scp.css")] public void BundlesScopedCssFiles_HandlesBasePathCombinationsCorrectly(string finalBasePath, string libraryBasePath, string expectedImport) { // Arrange @@ -224,7 +232,7 @@ public void BundlesScopedCssFiles_HandlesBasePathCombinationsCorrectly(string fi actualContents.Should().BeVisuallyEquivalentTo(expectedContent); } - [Fact] + [TestMethod] public void BundlesScopedCssFiles_BundlesFilesInOrder() { // Arrange @@ -257,7 +265,7 @@ public void BundlesScopedCssFiles_BundlesFilesInOrder() actualContents.Should().Contain(BundleContent); } - [Fact] + [TestMethod] public void BundlesScopedCssFiles_DoesNotOverrideBundleForSameContents() { // Arrange @@ -295,7 +303,7 @@ public void BundlesScopedCssFiles_DoesNotOverrideBundleForSameContents() lastModified.Should().BeSameDateAs(File.GetLastWriteTimeUtc(expectedFile)); } - [Fact] + [TestMethod] public async System.Threading.Tasks.Task BundlesScopedCssFiles_UpdatesBundleWhenContentsChange() { // Arrange @@ -338,7 +346,7 @@ public async System.Threading.Tasks.Task BundlesScopedCssFiles_UpdatesBundleWhen "TestFiles/Generated/FetchData.razor.rz.scp.css"), }; - await System.Threading.Tasks.Task.Delay(1000, TestContext.Current.CancellationToken); + await System.Threading.Tasks.Task.Delay(1000, TestContext.CancellationToken); taskInstance.Execute(); // Assert diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ContentTypeProviderTests.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ContentTypeProviderTests.cs index 88805b73dad2..9577c021f859 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ContentTypeProviderTests.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ContentTypeProviderTests.cs @@ -1,18 +1,26 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace Microsoft.NET.Sdk.StaticWebAssets.Tests.StaticWebAssets; +[TestClass] + public class ContentTypeProviderTests { private readonly TaskLoggingHelper _log = new TestTaskLoggingHelper(); - [Fact] + [TestMethod] public void GetContentType_ReturnsTextPlainForTextFiles() { // Arrange @@ -22,10 +30,10 @@ public void GetContentType_ReturnsTextPlainForTextFiles() var contentType = provider.ResolveContentTypeMapping(CreateContext("Fake-License.txt"), _log); // Assert - Assert.Equal("text/plain", contentType.MimeType); + Assert.AreEqual("text/plain", contentType.MimeType); } - [Fact] + [TestMethod] public void GetContentType_ReturnsMappingForRelativePath() { // Arrange @@ -35,7 +43,7 @@ public void GetContentType_ReturnsMappingForRelativePath() var contentType = provider.ResolveContentTypeMapping(CreateContext("Components/Pages/Counter.razor.js"), _log); // Assert - Assert.Equal("text/javascript", contentType.MimeType); + Assert.AreEqual("text/javascript", contentType.MimeType); } private StaticWebAssetGlobMatcher.MatchContext CreateContext(string v) @@ -47,7 +55,7 @@ private StaticWebAssetGlobMatcher.MatchContext CreateContext(string v) // wwwroot\exampleJsInterop.js.gz - [Fact] + [TestMethod] public void GetContentType_ReturnsMappingForCompressedRelativePath() { // Arrange @@ -57,10 +65,10 @@ public void GetContentType_ReturnsMappingForCompressedRelativePath() var contentType = provider.ResolveContentTypeMapping(CreateContext("wwwroot/exampleJsInterop.js.gz"), _log); // Assert - Assert.Equal("text/javascript", contentType.MimeType); + Assert.AreEqual("text/javascript", contentType.MimeType); } - [Fact] + [TestMethod] public void GetContentType_HandlesFingerprintedPaths() { // Arrange @@ -68,10 +76,10 @@ public void GetContentType_HandlesFingerprintedPaths() // Act var contentType = provider.ResolveContentTypeMapping(CreateContext("_content/RazorPackageLibraryDirectDependency/RazorPackageLibraryDirectDependency#[.{fingerprint}].bundle.scp.css.gz"), _log); // Assert - Assert.Equal("text/css", contentType.MimeType); + Assert.AreEqual("text/css", contentType.MimeType); } - [Fact] + [TestMethod] public void GetContentType_ReturnsDefaultForUnknownMappings() { // Arrange @@ -81,12 +89,12 @@ public void GetContentType_ReturnsDefaultForUnknownMappings() var contentType = provider.ResolveContentTypeMapping(CreateContext("something.unknown"), _log); // Assert - Assert.Null(contentType.MimeType); + Assert.IsNull(contentType.MimeType); } - [Theory] - [InlineData("something.unknown.gz", "application/x-gzip")] - [InlineData("something.unknown.br", "application/octet-stream")] + [TestMethod] + [DataRow("something.unknown.gz", "application/x-gzip")] + [DataRow("something.unknown.br", "application/octet-stream")] public void GetContentType_ReturnsGzipOrBrotliForUnknownCompressedMappings(string path, string expectedMapping) { // Arrange @@ -96,12 +104,12 @@ public void GetContentType_ReturnsGzipOrBrotliForUnknownCompressedMappings(strin var contentType = provider.ResolveContentTypeMapping(CreateContext(path), _log); // Assert - Assert.Equal(expectedMapping, contentType.MimeType); + Assert.AreEqual(expectedMapping, contentType.MimeType); } - [Theory] - [InlineData("Fake-License.txt.gz")] - [InlineData("Fake-License.txt.br")] + [TestMethod] + [DataRow("Fake-License.txt.gz")] + [DataRow("Fake-License.txt.br")] public void GetContentType_ReturnsTextPlainForCompressedTextFiles(string path) { // Arrange @@ -111,10 +119,10 @@ public void GetContentType_ReturnsTextPlainForCompressedTextFiles(string path) var contentType = provider.ResolveContentTypeMapping(CreateContext(path), _log); // Assert - Assert.Equal("text/plain", contentType.MimeType); + Assert.AreEqual("text/plain", contentType.MimeType); } - [Fact] + [TestMethod] public void GetContentType_CustomMappingOverridesBuiltInMapping() { // Arrange @@ -125,13 +133,13 @@ public void GetContentType_CustomMappingOverridesBuiltInMapping() var contentType = provider.ResolveContentTypeMapping(CreateContext("index.html"), _log); // Assert - Assert.Equal("text/html", contentType.MimeType); - Assert.Equal("no-store, must-revalidate, no-cache", contentType.Cache); - Assert.Equal("*.html", contentType.Pattern); - Assert.Equal(2, contentType.Priority); + Assert.AreEqual("text/html", contentType.MimeType); + Assert.AreEqual("no-store, must-revalidate, no-cache", contentType.Cache); + Assert.AreEqual("*.html", contentType.Pattern); + Assert.AreEqual(2, contentType.Priority); } - [Fact] + [TestMethod] public void GetContentType_CustomMappingOverridesBuiltInMappingForCompressedFiles() { // Arrange @@ -142,13 +150,13 @@ public void GetContentType_CustomMappingOverridesBuiltInMappingForCompressedFile var contentType = provider.ResolveContentTypeMapping(CreateContext("index.html.gz"), _log); // Assert - Assert.Equal("text/html", contentType.MimeType); - Assert.Equal("no-store, must-revalidate, no-cache", contentType.Cache); - Assert.Equal("*.html", contentType.Pattern); - Assert.Equal(2, contentType.Priority); + Assert.AreEqual("text/html", contentType.MimeType); + Assert.AreEqual("no-store, must-revalidate, no-cache", contentType.Cache); + Assert.AreEqual("*.html", contentType.Pattern); + Assert.AreEqual(2, contentType.Priority); } - [Fact] + [TestMethod] public void GetContentType_CustomJavaScriptMappingOverridesBuiltIn() { // Arrange @@ -159,10 +167,10 @@ public void GetContentType_CustomJavaScriptMappingOverridesBuiltIn() var contentType = provider.ResolveContentTypeMapping(CreateContext("app.js"), _log); // Assert - Assert.Equal("text/javascript", contentType.MimeType); - Assert.Equal("max-age=3600", contentType.Cache); - Assert.Equal("*.js", contentType.Pattern); - Assert.Equal(3, contentType.Priority); + Assert.AreEqual("text/javascript", contentType.MimeType); + Assert.AreEqual("max-age=3600", contentType.Cache); + Assert.AreEqual("*.js", contentType.Pattern); + Assert.AreEqual(3, contentType.Priority); } private class TestTaskLoggingHelper : TaskLoggingHelper diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DefineStaticWebAssetEndpointsTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DefineStaticWebAssetEndpointsTest.cs index af5c0dfeb870..9dd5f057063d 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DefineStaticWebAssetEndpointsTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DefineStaticWebAssetEndpointsTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Diagnostics.Metrics; using System.Diagnostics; using Microsoft.AspNetCore.StaticWebAssets.Tasks; @@ -15,11 +21,13 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; +[TestClass] + public class DefineStaticWebAssetEndpointsTest { - [Theory] - [InlineData(StaticWebAsset.SourceTypes.Discovered)] - [InlineData(StaticWebAsset.SourceTypes.Computed)] + [TestMethod] + [DataRow(StaticWebAsset.SourceTypes.Discovered)] + [DataRow(StaticWebAsset.SourceTypes.Computed)] public void DefinesEndpointsForAssets(string sourceType) { var errorMessages = new List(); @@ -86,7 +94,7 @@ public void DefinesEndpointsForAssets(string sourceType) ]); } - [Fact] + [TestMethod] public void CanDefineFingerprintedEndpoints() { var errorMessages = new List(); @@ -203,7 +211,7 @@ public void CanDefineFingerprintedEndpoints() ]); } - [Fact] + [TestMethod] public void CanDefineFingerprintedEndpoints_WithEmbeddedFingerprint() { var errorMessages = new List(); @@ -320,7 +328,7 @@ public void CanDefineFingerprintedEndpoints_WithEmbeddedFingerprint() ]); } - [Fact] + [TestMethod] public void DoesNotDefineNewEndpointsWhenAnExistingEndpointAlreadyExists() { var errorMessages = new List(); @@ -377,7 +385,7 @@ public void DoesNotDefineNewEndpointsWhenAnExistingEndpointAlreadyExists() endpoints.Should().BeEmpty(); } - [Fact] + [TestMethod] public void ResolvesContentType_ForCompressedAssets() { var errorMessages = new List(); @@ -430,7 +438,7 @@ public void ResolvesContentType_ForCompressedAssets() endpoint.ResponseHeaders.Should().ContainSingle(h => h.Name == "Content-Type" && h.Value == "application/x-gzip"); } - [Fact] + [TestMethod] public void ResolvesContentType_ForFingerprintedAssets() { var errorMessages = new List(); @@ -481,7 +489,7 @@ public void ResolvesContentType_ForFingerprintedAssets() endpoint.ResponseHeaders.Should().ContainSingle(h => h.Name == "Content-Type" && h.Value == "text/css"); } - [Fact] + [TestMethod] public void Produces_TheExpectedEndpoint_ForExternalAssets() { var errorMessages = new List(); @@ -661,9 +669,9 @@ private static TaskItem CreateAdditionalEndpointDefinition(string name, string p }); } - [Theory] - [InlineData("index.html", "index.html", "/")] - [InlineData("admin/index.html", "admin/index.html", "admin")] + [TestMethod] + [DataRow("index.html", "index.html", "/")] + [DataRow("admin/index.html", "admin/index.html", "admin")] public void AdditionalEndpointDefinitions_DefaultDocument_CreatesEndpointWithCapturedStem( string relativeSubPath, string expectedOriginalRoute, string expectedAdditionalRoute) { @@ -711,7 +719,7 @@ public void AdditionalEndpointDefinitions_DefaultDocument_CreatesEndpointWithCap additional.ResponseHeaders.Should().BeEquivalentTo(original.ResponseHeaders); } - [Fact] + [TestMethod] public void AdditionalEndpointDefinitions_SpaFallback_CreatesEndpointWithFallbackRoute() { var errorMessages = new List(); @@ -757,7 +765,7 @@ public void AdditionalEndpointDefinitions_SpaFallback_CreatesEndpointWithFallbac fallback.ResponseHeaders.Should().BeEquivalentTo(original.ResponseHeaders); } - [Fact] + [TestMethod] public void AdditionalEndpointDefinitions_DoesNotMatchNonMatchingRoutes() { var errorMessages = new List(); @@ -796,7 +804,7 @@ public void AdditionalEndpointDefinitions_DoesNotMatchNonMatchingRoutes() endpoints[0].Route.Should().Be("app.js"); } - [Fact] + [TestMethod] public void AdditionalEndpointDefinitions_BothRules_CreateMultipleAdditionalEndpoints() { var errorMessages = new List(); @@ -838,7 +846,7 @@ public void AdditionalEndpointDefinitions_BothRules_CreateMultipleAdditionalEndp endpoints.Should().Contain(e => e.Route == "{**fallback:nonfile}" && e.Order == "2147483647"); } - [Fact] + [TestMethod] public void AdditionalEndpointDefinitions_EmptyArray_NoAdditionalEndpoints() { var errorMessages = new List(); @@ -873,7 +881,7 @@ public void AdditionalEndpointDefinitions_EmptyArray_NoAdditionalEndpoints() endpoints[0].Route.Should().Be("index.html"); } - [Fact] + [TestMethod] public void ExistingEndpointsMatchingWorksWithNonFallbackTaskEnvironment() { // Verifies that the ExistingEndpoints deduplication logic works correctly @@ -907,7 +915,7 @@ public void ExistingEndpointsMatchingWorksWithNonFallbackTaskEnvironment() "the existing endpoint must be matched and deduplicated even with a non-Fallback TaskEnvironment"); } - [Fact] + [TestMethod] public void ProducesEndpointsCorrectlyWithNonFallbackTaskEnvironmentForPackageAsset() { // Verifies that Package-sourced assets get their BasePath prepended to the route diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DiscoverDefaultScopedCssItemsTests.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DiscoverDefaultScopedCssItemsTests.cs index e4e9a5c914ff..58e55d2e35f6 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DiscoverDefaultScopedCssItemsTests.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DiscoverDefaultScopedCssItemsTests.cs @@ -1,14 +1,21 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.AspNetCore.StaticWebAssets.Tasks; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; using Microsoft.Build.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace Microsoft.NET.Sdk.Razor.Test { + [TestClass] public class DiscoverDefaultScopedCssItemsTests { - [Fact] + [TestMethod] public void DiscoversScopedCssFiles_BasedOnTheirExtension() { // Arrange @@ -30,7 +37,7 @@ public void DiscoversScopedCssFiles_BasedOnTheirExtension() taskInstance.DiscoveredScopedCssInputs.Should().HaveCount(3); } - [Fact] + [TestMethod] public void DoesNotDiscoversScopedCssFilesForViews_IfFeatureIsUnsupported() { // Arrange @@ -52,7 +59,7 @@ public void DoesNotDiscoversScopedCssFilesForViews_IfFeatureIsUnsupported() taskInstance.DiscoveredScopedCssInputs.Should().BeEmpty(); } - [Fact] + [TestMethod] public void DiscoversScopedCssFilesForViews_BasedOnTheirExtension() { // Arrange @@ -75,7 +82,7 @@ public void DiscoversScopedCssFilesForViews_BasedOnTheirExtension() taskInstance.DiscoveredScopedCssInputs.Should().HaveCount(3); } - [Fact] + [TestMethod] public void DiscoversScopedCssFilesForViews_SkipsFilesWithScopedAttributeWithAFalseValue() { // Arrange diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DiscoverPrecompressedAssetsMultiThreadingTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DiscoverPrecompressedAssetsMultiThreadingTest.cs index 50b116d075b8..a1f5fe52ca9a 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DiscoverPrecompressedAssetsMultiThreadingTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DiscoverPrecompressedAssetsMultiThreadingTest.cs @@ -1,17 +1,26 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Moq; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; +[DoNotParallelize] +[TestClass] + public class DiscoverPrecompressedAssetsMultiThreadingTest { - [Fact] + [TestMethod] public void ResolvesContentRootRelativeToTaskEnvironmentProjectDirectory_NotProcessCurrentDirectory() { var testRoot = Path.Combine(AppContext.BaseDirectory, nameof(DiscoverPrecompressedAssetsMultiThreadingTest), Guid.NewGuid().ToString("N")); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DiscoverPrecompressedAssetsTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DiscoverPrecompressedAssetsTest.cs index d9b5e6cc44d6..cbf54cc01cf2 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DiscoverPrecompressedAssetsTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DiscoverPrecompressedAssetsTest.cs @@ -1,14 +1,22 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Moq; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; +[TestClass] + public class DiscoverPrecompressedAssetsTest { public string ItemSpec { get; } @@ -24,7 +32,7 @@ public DiscoverPrecompressedAssetsTest() OriginalItemSpec = Path.Combine(OutputBasePath, Guid.NewGuid().ToString("N") + ".tmp"); } - [Fact] + [TestMethod] public void DiscoversPrecompressedAssetsCorrectly() { var errorMessages = new List(); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DiscoverStaticWebAssetsTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DiscoverStaticWebAssetsTest.cs index f252022d1338..d408060146a3 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DiscoverStaticWebAssetsTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/DiscoverStaticWebAssetsTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -10,12 +16,13 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { + [TestClass] public class DiscoverStaticWebAssetsTest { private readonly Func _testResolveFileDetails = (string identity, string originalItemSpec) => (null, 10, new DateTimeOffset(2023, 10, 1, 0, 0, 0, TimeSpan.Zero)); - [Fact] + [TestMethod] public void DiscoversMatchingAssetsBasedOnPattern() { var errorMessages = new List(); @@ -62,9 +69,9 @@ public void DiscoversMatchingAssetsBasedOnPattern() asset.GetMetadata(nameof(StaticWebAsset.OriginalItemSpec)).Should().Be(Path.Combine("wwwroot", "candidate.js")); } - [Theory] - [InlineData("index.js", "index#[.{fingerprint}]?.js", "")] - [InlineData("css/site.css", "css/site#[.{fingerprint}]!.css", "#[.{fingerprint}]!")] + [TestMethod] + [DataRow("index.js", "index#[.{fingerprint}]?.js", "")] + [DataRow("css/site.css", "css/site#[.{fingerprint}]!.css", "#[.{fingerprint}]!")] public void FingerprintsContentWhenEnabled(string file, string expectedRelativePath, string expression) { var errorMessages = new List(); @@ -116,9 +123,9 @@ public void FingerprintsContentWhenEnabled(string file, string expectedRelativeP asset.GetMetadata(nameof(StaticWebAsset.OriginalItemSpec)).Should().Be(Path.Combine("wwwroot", file)); } - [Theory] - [InlineData("index.js")] - [InlineData("css/site.js")] + [TestMethod] + [DataRow("index.js")] + [DataRow("css/site.js")] public void DoesNotFingerprintsContentWhenNotEnabled(string candidate) { var errorMessages = new List(); @@ -166,9 +173,9 @@ public void DoesNotFingerprintsContentWhenNotEnabled(string candidate) asset.GetMetadata(nameof(StaticWebAsset.OriginalItemSpec)).Should().Be(Path.Combine("wwwroot", Path.Combine(candidate.Split('/')))); } - [Theory] - [InlineData("candidate.lib.module.js", "candidate#[.{fingerprint}]?.lib.module.js", "")] - [InlineData("library.candidate.lib.module.js", "library.candidate#[.{fingerprint}]!.lib.module.js", "#[.{fingerprint}]!")] + [TestMethod] + [DataRow("candidate.lib.module.js", "candidate#[.{fingerprint}]?.lib.module.js", "")] + [DataRow("library.candidate.lib.module.js", "library.candidate#[.{fingerprint}]!.lib.module.js", "#[.{fingerprint}]!")] public void FingerprintsContentUsingPatternsWhenMoreThanOneExtension(string fileName, string expectedRelativePath, string expression) { var errorMessages = new List(); @@ -217,8 +224,8 @@ public void FingerprintsContentUsingPatternsWhenMoreThanOneExtension(string file asset.GetMetadata(nameof(StaticWebAsset.OriginalItemSpec)).Should().Be(Path.Combine("wwwroot", fileName)); } - [Fact] - [Trait("Category", "FingerprintIdentity")] + [TestMethod] + [TestCategory("FingerprintIdentity")] public void ComputesIdentity_UsingFingerprintPattern_ForComputedAssets_WhenIdentityNeedsComputation() { // Arrange: simulate a packaged asset (outside content root) with a RelativePath inside the app @@ -280,7 +287,7 @@ public void ComputesIdentity_UsingFingerprintPattern_ForComputedAssets_WhenIdent asset.ItemSpec.Should().Be(expectedIdentity); } - [Fact] + [TestMethod] public void RespectsItemRelativePathWhenExplicitlySpecified() { var errorMessages = new List(); @@ -327,7 +334,7 @@ public void RespectsItemRelativePathWhenExplicitlySpecified() asset.GetMetadata(nameof(StaticWebAsset.OriginalItemSpec)).Should().Be(Path.Combine("wwwroot", "candidate.js")); } - [Fact] + [TestMethod] public void UsesTargetPathWhenFound() { var errorMessages = new List(); @@ -374,7 +381,7 @@ public void UsesTargetPathWhenFound() asset.GetMetadata(nameof(StaticWebAsset.OriginalItemSpec)).Should().Be(Path.Combine("wwwroot", "candidate.js")); } - [Fact] + [TestMethod] public void UsesLinkPathWhenFound() { var errorMessages = new List(); @@ -421,7 +428,7 @@ public void UsesLinkPathWhenFound() asset.GetMetadata(nameof(StaticWebAsset.OriginalItemSpec)).Should().Be(Path.Combine("wwwroot", "candidate.js")); } - [Fact] + [TestMethod] public void AutomaticallyDetectsAssetKindWhenMultipleAssetsTargetTheSameRelativePath() { var errorMessages = new List(); @@ -464,12 +471,12 @@ public void AutomaticallyDetectsAssetKindWhenMultipleAssetsTargetTheSameRelative publishAsset.GetMetadata(nameof(StaticWebAsset.CopyToPublishDirectory)).Should().Be("PreserveNewest"); } - [Theory] - [InlineData("Never", "Never", "Build", "Never", "Never", "Build")] - [InlineData("PreserveNewest", "PreserveNewest", "All", "PreserveNewest", "PreserveNewest", "All")] - [InlineData("Always", "Always", "All", "Always", "Always", "All")] - [InlineData("Never", "Always", "All", "Never", "Always", "All")] - [InlineData("Always", "Never", "Build", "Always", "Never", "Build")] + [TestMethod] + [DataRow("Never", "Never", "Build", "Never", "Never", "Build")] + [DataRow("PreserveNewest", "PreserveNewest", "All", "PreserveNewest", "PreserveNewest", "All")] + [DataRow("Always", "Always", "All", "Always", "Always", "All")] + [DataRow("Never", "Always", "All", "Never", "Always", "All")] + [DataRow("Always", "Never", "Build", "Always", "Never", "Build")] public void FailsDiscoveringAssetsWhenThereIsAConflict( string copyToOutputDirectoryFirst, string copyToPublishDirectoryFirst, @@ -519,18 +526,18 @@ public void FailsDiscoveringAssetsWhenThereIsAConflict( for path 'candidate.js'"); } - [Theory] - [InlineData("\\_content\\Path\\", "_content/Path")] - [InlineData("\\_content\\Path", "_content/Path")] - [InlineData("_content\\Path", "_content/Path")] - [InlineData("/_content/Path/", "_content/Path")] - [InlineData("/_content/Path", "_content/Path")] - [InlineData("_content/Path", "_content/Path")] - [InlineData("\\_content/Path\\", "_content/Path")] - [InlineData("/_content\\Path/", "_content/Path")] - [InlineData("", "/")] - [InlineData("/", "/")] - [InlineData("\\", "/")] + [TestMethod] + [DataRow("\\_content\\Path\\", "_content/Path")] + [DataRow("\\_content\\Path", "_content/Path")] + [DataRow("_content\\Path", "_content/Path")] + [DataRow("/_content/Path/", "_content/Path")] + [DataRow("/_content/Path", "_content/Path")] + [DataRow("_content/Path", "_content/Path")] + [DataRow("\\_content/Path\\", "_content/Path")] + [DataRow("/_content\\Path/", "_content/Path")] + [DataRow("", "/")] + [DataRow("/", "/")] + [DataRow("\\", "/")] public void NormalizesBasePath(string givenPath, string expectedPath) { var errorMessages = new List(); @@ -583,8 +590,8 @@ public static TheoryData NormalizesContentRootData } } - [Theory] - [MemberData(nameof(NormalizesContentRootData))] + [TestMethod] + [DynamicData(nameof(NormalizesContentRootData))] public void NormalizesContentRoot(string contentRoot, string expected) { var errorMessages = new List(); @@ -618,7 +625,7 @@ public void NormalizesContentRoot(string contentRoot, string expected) asset.GetMetadata(nameof(StaticWebAsset.ContentRoot)).Should().Be(expected); } - [Fact] + [TestMethod] public void DefineStaticWebAssetsCache_UpToDate() { // Arrange @@ -627,10 +634,10 @@ public void DefineStaticWebAssetsCache_UpToDate() cache.Update([], [], [], inputHashes); // Assert - Assert.True(cache.IsUpToDate()); + Assert.IsTrue(cache.IsUpToDate()); } - [Fact] + [TestMethod] public void DefineStaticWebAssetsCache_UpToDate_WithAssets() { // Arrange @@ -640,13 +647,13 @@ public void DefineStaticWebAssetsCache_UpToDate_WithAssets() cache.Update([], [], [], inputHashes); // Assert - Assert.True(cache.IsUpToDate()); + Assert.IsTrue(cache.IsUpToDate()); } - [Theory] - [InlineData(UpdatedHash.GlobalProperties)] - [InlineData(UpdatedHash.FingerprintPatterns)] - [InlineData(UpdatedHash.Overrides)] + [TestMethod] + [DataRow(UpdatedHash.GlobalProperties)] + [DataRow(UpdatedHash.FingerprintPatterns)] + [DataRow(UpdatedHash.Overrides)] public void DefineStaticWebAssetsCache_Recomputes_All_WhenPropertiesChange(UpdatedHash updated) { // Arrange @@ -666,13 +673,13 @@ public void DefineStaticWebAssetsCache_Recomputes_All_WhenPropertiesChange(Updat break; } - Assert.False(cache.IsUpToDate()); - Assert.Same(inputHashes, cache.OutOfDateInputs()); - Assert.Empty(cache.CachedAssets); - Assert.Empty(cache.CachedCopyCandidates); + Assert.IsFalse(cache.IsUpToDate()); + Assert.AreSame(inputHashes, cache.OutOfDateInputs()); + Assert.IsEmpty(cache.CachedAssets); + Assert.IsEmpty(cache.CachedCopyCandidates); } - [Fact] + [TestMethod] public void DefineStaticWebAssetsCache_PartialUpdate_WhenOnlySome_InputsChange() { // Arrange @@ -683,14 +690,14 @@ public void DefineStaticWebAssetsCache_PartialUpdate_WhenOnlySome_InputsChange() cache.Update([], [], [], inputHashes); // Assert - Assert.False(cache.IsUpToDate()); - Assert.NotSame(inputHashes, cache.OutOfDateInputs()); - var input1 = Assert.Single(cache.OutOfDateInputs()); + Assert.IsFalse(cache.IsUpToDate()); + Assert.AreNotSame(inputHashes, cache.OutOfDateInputs()); + var input1 = Assert.ContainsSingle(cache.OutOfDateInputs()); var ouput = cache.GetComputedOutputs(); - var input2 = Assert.Single(ouput.Assets); + var input2 = Assert.ContainsSingle(ouput.Assets); } - [Fact] + [TestMethod] public void DefineStaticWebAssetsCache_PartialUpdate_NewAssetsCanBeAddedToTheCache() { // Arrange @@ -703,18 +710,18 @@ public void DefineStaticWebAssetsCache_PartialUpdate_NewAssetsCanBeAddedToTheCac cache.AppendAsset("input1", newAsset, newAssetItem); // Assert - Assert.False(cache.IsUpToDate()); - Assert.NotSame(inputHashes, cache.OutOfDateInputs()); - var input1 = Assert.Single(cache.OutOfDateInputs()); + Assert.IsFalse(cache.IsUpToDate()); + Assert.AreNotSame(inputHashes, cache.OutOfDateInputs()); + var input1 = Assert.ContainsSingle(cache.OutOfDateInputs()); Assert.Contains("input1", cache.CachedAssets.Keys); var ouput = cache.GetComputedOutputs(); - Assert.Equal(2, ouput.Assets.Count); - Assert.Equal("input2", ouput.Assets[0].ItemSpec); - Assert.Equal("input1", ouput.Assets[1].ItemSpec); + Assert.HasCount(2, ouput.Assets); + Assert.AreEqual("input2", ouput.Assets[0].ItemSpec); + Assert.AreEqual("input1", ouput.Assets[1].ItemSpec); } - [Fact] + [TestMethod] public void DefineStaticWebAssetsCache_CanRoundtripManifest() { var manifestPath = Path.Combine(Environment.CurrentDirectory, "CanRoundtripManifest.json"); @@ -739,12 +746,12 @@ public void DefineStaticWebAssetsCache_CanRoundtripManifest() cache.WriteCacheManifest(); var otherManifest = DefineStaticWebAssets.DefineStaticWebAssetsCache.ReadOrCreateCache(CreateLogger(), manifestPath); - Assert.Equal(cache.InputHashes, otherManifest.InputHashes); - Assert.Equal(cache.CachedAssets.Count, otherManifest.CachedAssets.Count); - Assert.Equal(cache.CachedAssets["input2"].Identity, otherManifest.CachedAssets["input2"].Identity); - Assert.Equal(cache.CachedAssets["input2"].RelativePath, otherManifest.CachedAssets["input2"].RelativePath); - Assert.Equal(cache.CachedAssets["input1"].Identity, otherManifest.CachedAssets["input1"].Identity); - Assert.Equal(cache.CachedAssets["input1"].RelativePath, otherManifest.CachedAssets["input1"].RelativePath); + otherManifest.InputHashes.Should().BeEquivalentTo(cache.InputHashes); + Assert.HasCount(cache.CachedAssets.Count, otherManifest.CachedAssets); + Assert.AreEqual(cache.CachedAssets["input2"].Identity, otherManifest.CachedAssets["input2"].Identity); + Assert.AreEqual(cache.CachedAssets["input2"].RelativePath, otherManifest.CachedAssets["input2"].RelativePath); + Assert.AreEqual(cache.CachedAssets["input1"].Identity, otherManifest.CachedAssets["input1"].Identity); + Assert.AreEqual(cache.CachedAssets["input1"].RelativePath, otherManifest.CachedAssets["input1"].RelativePath); } finally { @@ -752,7 +759,7 @@ public void DefineStaticWebAssetsCache_CanRoundtripManifest() } } - [Fact] + [TestMethod] public void ComputesRelativePath_ForDiscoveredAssetsWithFullPath() { var errorMessages = new List(); @@ -792,7 +799,7 @@ public void ComputesRelativePath_ForDiscoveredAssetsWithFullPath() task.Assets[1].GetMetadata(nameof(StaticWebAsset.BasePath)).Should().Be("_content/Microsoft.AspNetCore.Components.CustomElements"); } - [Fact] + [TestMethod] public void ComputesRelativePath_WorksForItemsWithRelativePaths() { var errorMessages = new List(); @@ -832,7 +839,8 @@ public void ComputesRelativePath_WorksForItemsWithRelativePaths() task.Assets[1].GetMetadata(nameof(StaticWebAsset.BasePath)).Should().Be("_content/Microsoft.AspNetCore.Components.CustomElements"); } - [LinuxOnlyFact] + [TestMethod] + [OSCondition(OperatingSystems.Linux)] public void ComputesRelativePath_ForAssets_ExplicitPaths() { var errorMessages = new List(); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/FilterStaticWebAssetEndpointsTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/FilterStaticWebAssetEndpointsTest.cs index 2cf9ee746d4e..dd5f929841fe 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/FilterStaticWebAssetEndpointsTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/FilterStaticWebAssetEndpointsTest.cs @@ -1,17 +1,24 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Moq; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests.StaticWebAssets; +[TestClass] public class FilterStaticWebAssetEndpointsTest { - [Fact] + [TestMethod] public void CanFilterEndpoints_ByAssetFile() { var assets = new[] { @@ -55,7 +62,7 @@ public void CanFilterEndpoints_ByAssetFile() filteredEndpoints.Should().BeEquivalentTo(expectedEndpoints); } - [Fact] + [TestMethod] public void CanFilterEndpoints_ByProperty() { var assets = new[] { @@ -91,7 +98,7 @@ public void CanFilterEndpoints_ByProperty() filteredEndpoints.Should().AllSatisfy(e => e.EndpointProperties.Should().ContainSingle(p => p.Name == "fingerprint")); } - [Fact] + [TestMethod] public void CanFilterEndpoints_ByResponseHeader() { var assets = new[] { @@ -128,7 +135,7 @@ public void CanFilterEndpoints_ByResponseHeader() filteredEndpoints.Should().AllSatisfy(e => e.ResponseHeaders.Should().ContainSingle(p => p.Name == "Content-Type" && p.Value == "text/html")); } - [Fact] + [TestMethod] public void CanFilterEndpoints_Standalone() { var assets = new[] { @@ -160,7 +167,7 @@ public void CanFilterEndpoints_Standalone() filteredEndpoints.Where(e => e.Route == "other.fingerprint.js").Should().ContainSingle(); } - [Fact] + [TestMethod] public void CanFilterEndpoints_BySelector() { var assets = new[] { @@ -198,7 +205,7 @@ public void CanFilterEndpoints_BySelector() filteredEndpoints[0].Route.Should().Be(endpoints[0].Route); } - [Fact] + [TestMethod] public void CanFilterEndpoints_ByMultipleCriteria() { var assets = new[] { diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/FilterStaticWebAssetGroupsTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/FilterStaticWebAssetGroupsTest.cs index fdf35b4dc2e3..0b2d4abf387f 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/FilterStaticWebAssetGroupsTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/FilterStaticWebAssetGroupsTest.cs @@ -1,14 +1,22 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Moq; namespace Microsoft.AspNetCore.StaticWebAssets.Tasks; +[TestClass] + public class FilterStaticWebAssetGroupsTest : IDisposable { private readonly string _tempDir; @@ -38,7 +46,7 @@ public void Dispose() } } - [Fact] + [TestMethod] public void ConcreteGroupSatisfied_AssetIncluded() { var asset1 = CreateAssetItem("app.js", "MyLib", ""); @@ -57,7 +65,7 @@ public void ConcreteGroupSatisfied_AssetIncluded() task.SurvivingEndpoints.Should().HaveCount(2); } - [Fact] + [TestMethod] public void ConcreteGroupUnsatisfied_AssetExcluded() { var asset = CreateAssetItem("server.js", "MyLib", "ServerRendering=true"); @@ -73,7 +81,7 @@ public void ConcreteGroupUnsatisfied_AssetExcluded() task.SurvivingEndpoints.Should().HaveCount(0, "endpoint for excluded asset should be removed"); } - [Fact] + [TestMethod] public void DeferredGroupInFinalPass_Errors() { var asset = CreateAssetItem("server.js", "MyLib", "ServerRendering=true"); @@ -90,7 +98,7 @@ public void DeferredGroupInFinalPass_Errors() .Which.Should().Contain("Deferred"); } - [Fact] + [TestMethod] public void SkipDeferred_DeferredGroupsSkipped_AssetPassesThrough() { var asset = CreateAssetItem("server.js", "MyLib", "ServerRendering=true"); @@ -107,7 +115,7 @@ public void SkipDeferred_DeferredGroupsSkipped_AssetPassesThrough() task.SurvivingEndpoints.Should().HaveCount(1); } - [Fact] + [TestMethod] public void CascadingExclusion_RelatedAssetsExcludedWithPrimary() { var primary = CreateAssetItem("server.js", "MyLib", "ServerRendering=true"); @@ -126,7 +134,7 @@ public void CascadingExclusion_RelatedAssetsExcludedWithPrimary() task.SurvivingEndpoints.Should().HaveCount(0, "endpoints for both excluded assets should be removed"); } - [Fact] + [TestMethod] public void CascadingExclusion_RelatedAssetPathResolvedAgainstTaskEnvironment() { var primary = CreateAssetItem("server.js", "MyLib", "ServerRendering=true"); @@ -146,7 +154,7 @@ public void CascadingExclusion_RelatedAssetPathResolvedAgainstTaskEnvironment() task.SurvivingEndpoints.Should().HaveCount(0); } - [Fact] + [TestMethod] public void EndpointsFiltered_ForExcludedAssets() { var includedAsset = CreateAssetItem("app.js", "MyLib", ""); @@ -168,7 +176,7 @@ public void EndpointsFiltered_ForExcludedAssets() task.SurvivingEndpoints[0].ItemSpec.Should().Be("app.js"); } - [Fact] + [TestMethod] public void SkipDeferred_NonDeferredGroupsStillEvaluated() { // An asset has both a non-deferred group requirement and a deferred group requirement. @@ -192,7 +200,7 @@ public void SkipDeferred_NonDeferredGroupsStillEvaluated() "non-deferred BootstrapVersion is satisfied; deferred ServerRendering is skipped"); } - [Fact] + [TestMethod] public void NullStaticWebAssetGroups_PassesThrough() { var asset = CreateAssetItem("app.js", "MyLib", ""); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/FingerprintPatternMatcherTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/FingerprintPatternMatcherTest.cs index 964c3086cce6..472461199e05 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/FingerprintPatternMatcherTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/FingerprintPatternMatcherTest.cs @@ -1,18 +1,26 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace Microsoft.NET.Sdk.StaticWebAssets.Tests.StaticWebAssets; +[TestClass] + public class FingerprintPatternMatcherTest { private readonly TaskLoggingHelper _log = new TestTaskLoggingHelper(); - [Fact] + [TestMethod] public void AppendFingerprintPattern_AlreadyContainsFingerprint_ReturnsIdentity() { // Arrange @@ -22,10 +30,10 @@ public void AppendFingerprintPattern_AlreadyContainsFingerprint_ReturnsIdentity( var result = new FingerprintPatternMatcher(_log, []).AppendFingerprintPattern(CreateMatchContext(relativePath), "Identity"); // Assert - Assert.Equal(relativePath, result); + Assert.AreEqual(relativePath, result); } - [Fact] + [TestMethod] public void AppendFingerprintPattern_AppendsPattern_AtTheEndOfTheFileName() { // Arrange @@ -36,10 +44,10 @@ public void AppendFingerprintPattern_AppendsPattern_AtTheEndOfTheFileName() var result = new FingerprintPatternMatcher(_log, []).AppendFingerprintPattern(CreateMatchContext(relativePath), "Identity"); // Assert - Assert.Equal(expected, result); + Assert.AreEqual(expected, result); } - [Fact] + [TestMethod] public void AppendFingerprintPattern_AppendsPattern_AtTheEndOfTheFileName_WhenFileNameContainsDots() { // Arrange @@ -48,10 +56,10 @@ public void AppendFingerprintPattern_AppendsPattern_AtTheEndOfTheFileName_WhenFi // Act var result = new FingerprintPatternMatcher(_log, []).AppendFingerprintPattern(CreateMatchContext(relativePath), "Identity"); // Assert - Assert.Equal(expected, result); + Assert.AreEqual(expected, result); } - [Fact] + [TestMethod] public void AppendFingerprintPattern_AppendsPattern_AtTheEndOfTheFileName_WhenFileDoesNotHaveExtension() { // Arrange @@ -60,10 +68,10 @@ public void AppendFingerprintPattern_AppendsPattern_AtTheEndOfTheFileName_WhenFi // Act var result = new FingerprintPatternMatcher(_log, []).AppendFingerprintPattern(CreateMatchContext(relativePath), "Identity"); // Assert - Assert.Equal(expected, result); + Assert.AreEqual(expected, result); } - [Fact] + [TestMethod] public void AppendFingerprintPattern_AppendsPattern_AtTheRightLocation_WhenACustomPatternIsProvided() { // Arrange @@ -77,7 +85,7 @@ public void AppendFingerprintPattern_AppendsPattern_AtTheRightLocation_WhenACust .AppendFingerprintPattern(CreateMatchContext(relativePath), "Identity"); // Assert - Assert.Equal(expected, result); + Assert.AreEqual(expected, result); } private StaticWebAssetGlobMatcher.MatchContext CreateMatchContext(string path) diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GeneratePackageAssetsManifestFileTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GeneratePackageAssetsManifestFileTest.cs index 1840d0fe9c66..1ed30cccf405 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GeneratePackageAssetsManifestFileTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GeneratePackageAssetsManifestFileTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Text.Json; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -10,6 +16,8 @@ namespace Microsoft.AspNetCore.StaticWebAssets.Tasks; +[TestClass] + public class GeneratePackageAssetsManifestFileTest : IDisposable { private readonly string _tempDir; @@ -36,7 +44,7 @@ public void Dispose() } } - [Fact] + [TestMethod] public void EmptyAssets_DoesNotGenerateManifestFile() { var manifestPath = Path.Combine(_tempDir, "empty.json"); @@ -55,7 +63,7 @@ public void EmptyAssets_DoesNotGenerateManifestFile() File.Exists(manifestPath).Should().BeFalse(); } - [Fact] + [TestMethod] public void Assets_SerializedWithCorrectPackagePaths() { var file = CreateTempFile("wwwroot", "css", "site.css", "body{}"); @@ -77,7 +85,7 @@ public void Assets_SerializedWithCorrectPackagePaths() manifestAsset.AssetRole.Should().Be("Primary"); } - [Fact] + [TestMethod] public void RelatedAsset_RemappedToPackageRelativePath() { var primaryFile = CreateTempFile("wwwroot", "css", "site.css", "body{}"); @@ -108,7 +116,7 @@ public void RelatedAsset_RemappedToPackageRelativePath() relatedAsset.RelatedAsset.Should().Be(primaryAssetPath); } - [Fact] + [TestMethod] public void Endpoints_AssetFileRemappedToPackageRelativePath() { var file = CreateTempFile("wwwroot", "js", "app.js", "var x;"); @@ -138,7 +146,7 @@ public void Endpoints_AssetFileRemappedToPackageRelativePath() ep.AssetFile.Should().Be(manifest.Assets.Keys.Single()); } - [Fact] + [TestMethod] public void FrameworkPattern_TagsMatchingAssetsAsFramework() { var fwFile = CreateTempFile("wwwroot", "js", "framework.js", "fw"); @@ -163,7 +171,7 @@ public void FrameworkPattern_TagsMatchingAssetsAsFramework() nonFwManifestAsset.SourceType.Should().Be("Package"); } - [Fact] + [TestMethod] public void AssetGroups_PreservedInManifest() { var file = CreateTempFile("wwwroot", "css", "site.css", "body{}"); @@ -180,7 +188,7 @@ public void AssetGroups_PreservedInManifest() manifest.Assets.Values.Single().AssetGroups.Should().Be("BootstrapVersion=V5"); } - [Fact] + [TestMethod] public void RelatedAsset_Unmapped_ProducesError() { // Symmetric to Endpoints_UnmappedAssetFile_ProducesError: exercises the @@ -214,7 +222,7 @@ public void RelatedAsset_Unmapped_ProducesError() "the manifest must not be written when a referential integrity error is detected"); } - [Fact] + [TestMethod] public void RoundTrip_GenerateThenRead_RelatedAssetResolvesToConsumerAbsolutePath() { // End-to-end cross-boundary test. Proves the contract between @@ -290,7 +298,7 @@ public void RoundTrip_GenerateThenRead_RelatedAssetResolvesToConsumerAbsolutePat "no producer-side build-time path may leak through the manifest to the consumer"); } - [Fact] + [TestMethod] public void Endpoints_UnmappedAssetFile_ProducesError() { var file = CreateTempFile("wwwroot", "js", "app.js", "var x;"); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GeneratePackageAssetsTargetsFileTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GeneratePackageAssetsTargetsFileTest.cs index 62c9d1363b72..c8418ffbe8c5 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GeneratePackageAssetsTargetsFileTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GeneratePackageAssetsTargetsFileTest.cs @@ -1,14 +1,22 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Xml.Linq; using Microsoft.Build.Framework; using Moq; namespace Microsoft.AspNetCore.StaticWebAssets.Tasks; +[TestClass] + public class GeneratePackageAssetsTargetsFileTest : IDisposable { private readonly string _tempDir; @@ -35,7 +43,7 @@ public void Dispose() } } - [Fact] + [TestMethod] public void GeneratesValidXml_WithStaticWebAssetPackageManifestItem() { var task = CreateTask(); @@ -70,7 +78,7 @@ public void GeneratesValidXml_WithStaticWebAssetPackageManifestItem() packageRootElement.Should().NotBeNull(); } - [Fact] + [TestMethod] public void Incremental_FileNotRewritten_WhenContentUnchanged() { var task = CreateTask(); @@ -96,7 +104,7 @@ public void Incremental_FileNotRewritten_WhenContentUnchanged() secondWriteTime.Should().Be(firstWriteTime); } - [Fact] + [TestMethod] public void CustomPackagePathPrefix_ReflectedInContentRoot() { var task = CreateTask(packagePathPrefix: "custom/assets"); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetEndpointsManifestTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetEndpointsManifestTest.cs index a278a732193a..f5599e5dac1e 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetEndpointsManifestTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetEndpointsManifestTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Text.Json; using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; @@ -11,9 +17,11 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests.StaticWebAssets; +[TestClass] + public class GenerateStaticWebAssetEndpointsManifestTest { - [Fact] + [TestMethod] public void GeneratesManifest_ForEndpointsWithTokens() { StaticWebAssetEndpoint[] expectedEndpoints = @@ -217,7 +225,7 @@ public void GeneratesManifest_ForEndpointsWithTokens() } } - [Fact] + [TestMethod] public void ExcludesEndpoints_BasedOnExclusionPatterns() { // Arrange @@ -253,11 +261,11 @@ public void ExcludesEndpoints_BasedOnExclusionPatterns() // Assert new FileInfo(path).Should().Exist(); new FileInfo(exclusionCachePath).Should().Exist(); - + var manifest = File.ReadAllText(path); var json = JsonSerializer.Deserialize(manifest); json.Should().NotBeNull(); - + // Only styles.css endpoint should remain as others match _content/MyApp/** json.Endpoints.Should().HaveCount(1); json.Endpoints[0].Route.Should().Contain("styles.css"); @@ -276,7 +284,7 @@ public void ExcludesEndpoints_BasedOnExclusionPatterns() } } - [Fact] + [TestMethod] public void SkipsRegeneration_WhenExclusionPatternsUnchanged() { // Arrange @@ -350,7 +358,7 @@ public void SkipsRegeneration_WhenExclusionPatternsUnchanged() } } - [Fact] + [TestMethod] public void RegeneratesManifest_WhenExclusionPatternsChange() { // Arrange @@ -406,7 +414,7 @@ public void RegeneratesManifest_WhenExclusionPatternsChange() // Assert - File should be regenerated var secondWriteTime = File.GetLastWriteTimeUtc(endpointsManifestPath); secondWriteTime.Should().BeAfter(firstWriteTime); - + // Verify cache file was updated var cacheContent = File.ReadAllText(exclusionCachePath); cacheContent.Should().Contain("different/**"); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetEndpointsPropsFileTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetEndpointsPropsFileTest.cs index 4f72196dbe0d..a3609dc8cd18 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetEndpointsPropsFileTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetEndpointsPropsFileTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Net; using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; @@ -12,9 +18,11 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests.StaticWebAssets; +[TestClass] + public class GenerateStaticWebAssetEndpointsPropsFileTest { - [Fact] + [TestMethod] public void Generates_ValidEndpointsDefinitions() { // Arrange @@ -107,7 +115,7 @@ public void Generates_ValidEndpointsDefinitions() } } - [Fact] + [TestMethod] public void Fails_WhenEndpointWithoutAssetExists() { // Arrange @@ -160,7 +168,8 @@ public void Fails_WhenEndpointWithoutAssetExists() errorMessages[0].Should().Be($"""The asset file '{Path.GetFullPath(Path.Combine("wwwroot", "js", "sample.js"))}' specified in the endpoint '{Path.Combine("js","sample.js").Replace('\\', '/')}' does not exist."""); } - [Fact] + [TestMethod] + [DoNotParallelize] public void Execute_RelativeTargetPropsFilePath_ResolvesAgainstProjectDirectory_NotProcessCurrentDirectory() { WithDecoyCwdAndProjectDirectory((projectDir, spawnDir) => diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsDevelopmentManifestTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsDevelopmentManifestTest.cs index e2afd6e0097d..e16a9d7c3203 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsDevelopmentManifestTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsDevelopmentManifestTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Moq; @@ -10,9 +16,10 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { + [TestClass] public class GenerateStaticWebAssetsDevelopmentManifestTest { - [Fact] + [TestMethod] public void SkipsManifestGenerationWhen_ThereAreNoAssetsNorDiscoveryPatterns() { // Arrange @@ -36,7 +43,7 @@ public void SkipsManifestGenerationWhen_ThereAreNoAssetsNorDiscoveryPatterns() messages.Should().HaveCount(1); } - [Fact] + [TestMethod] public void ComputeDevelopmentManifest_IncludesBuildAssets() { // Arrange @@ -65,10 +72,10 @@ public void ComputeDevelopmentManifest_IncludesBuildAssets() manifest.Should().BeEquivalentTo(expectedManifest); } - [Theory] - [InlineData("#[.{fingerprint}]?", "index.html", "optional.html")] - [InlineData("#[.{fingerprint}]!", "index.fingerprint.html", "preferred.html")] - [InlineData("#[.{fingerprint}]", "index.fingerprint.html", "required.html")] + [TestMethod] + [DataRow("#[.{fingerprint}]?", "index.html", "optional.html")] + [DataRow("#[.{fingerprint}]!", "index.fingerprint.html", "preferred.html")] + [DataRow("#[.{fingerprint}]", "index.fingerprint.html", "required.html")] public void ComputeDevelopmentManifest_ReplacesAssetTokens(string fingerprintExpression, string path, string fileName) { // Arrange @@ -97,10 +104,10 @@ public void ComputeDevelopmentManifest_ReplacesAssetTokens(string fingerprintExp manifest.Should().BeEquivalentTo(expectedManifest); } - [Theory] - [InlineData("#[.{fingerprint}]?", "index.html", "optional.html")] - [InlineData("#[.{fingerprint}]!", "index.fingerprint.html", "preferred.html")] - [InlineData("#[.{fingerprint}]", "index.fingerprint.html", "required.html")] + [TestMethod] + [DataRow("#[.{fingerprint}]?", "index.html", "optional.html")] + [DataRow("#[.{fingerprint}]!", "index.fingerprint.html", "preferred.html")] + [DataRow("#[.{fingerprint}]", "index.fingerprint.html", "required.html")] public void ComputeDevelopmentManifest_ReplacesAssetTokens_FileExists(string fingerprintExpression, string path, string subPath) { // Arrange @@ -141,7 +148,7 @@ public void ComputeDevelopmentManifest_ReplacesAssetTokens_FileExists(string fin } } - [Fact] + [TestMethod] public void ComputeDevelopmentManifest_UsesIdentitySubpath_WhenFileExists_AndContentRoot_IsPrefix() { // Arrange @@ -188,7 +195,7 @@ public void ComputeDevelopmentManifest_UsesIdentitySubpath_WhenFileExists_AndCon } } - [Fact] + [TestMethod] public void ComputeDevelopmentManifest_UsesRelativePath_ReplacesAssetTokens_WhenFileDoesNotExist_AtIdentity() { // Arrange @@ -224,7 +231,7 @@ public void ComputeDevelopmentManifest_UsesRelativePath_ReplacesAssetTokens_When manifest.Should().BeEquivalentTo(expectedManifest); } - [Fact] + [TestMethod] public void ComputeDevelopmentManifest_IncludesAllAssets() { // Arrange @@ -253,7 +260,7 @@ public void ComputeDevelopmentManifest_IncludesAllAssets() manifest.Should().BeEquivalentTo(expectedManifest); } - [Fact] + [TestMethod] public void ComputeDevelopmentManifest_ExcludesPublishAssets() { // Arrange @@ -280,7 +287,7 @@ public void ComputeDevelopmentManifest_ExcludesPublishAssets() manifest.Should().BeEquivalentTo(expectedManifest); } - [Fact] + [TestMethod] public void ComputeDevelopmentManifest_ExcludesReferenceAssets() { // Arrange @@ -308,7 +315,7 @@ public void ComputeDevelopmentManifest_ExcludesReferenceAssets() manifest.Should().BeEquivalentTo(expectedManifest); } - [Fact] + [TestMethod] public void ComputeDevelopmentManifest_PrefersBuildAssetsOverAllAssets() { // Arrange @@ -353,7 +360,7 @@ public void ComputeDevelopmentManifest_PrefersBuildAssetsOverAllAssets() } } - [Fact] + [TestMethod] public void ComputeDevelopmentManifest_UsesIdentityWhenContentRootStartsByIdentity() { // Arrange @@ -399,7 +406,7 @@ public void ComputeDevelopmentManifest_UsesIdentityWhenContentRootStartsByIdenti } } - [Fact] + [TestMethod] public void ComputeDevelopmentManifest_UsesRelativePathContentRootDoesNotStartByIdentity() { // Arrange @@ -431,7 +438,7 @@ public void ComputeDevelopmentManifest_UsesRelativePathContentRootDoesNotStartBy manifest.Should().BeEquivalentTo(expectedManifest); } - [Fact] + [TestMethod] public void ComputeDevelopmentManifest_MapsPatternsFromCurrentProject() { // Arrange @@ -461,7 +468,7 @@ public void ComputeDevelopmentManifest_MapsPatternsFromCurrentProject() manifest.Should().BeEquivalentTo(expectedManifest); } - [Fact] + [TestMethod] public void ComputeDevelopmentManifest_MapsPatternsFromOtherProjects() { // Arrange @@ -492,7 +499,7 @@ public void ComputeDevelopmentManifest_MapsPatternsFromOtherProjects() manifest.Should().BeEquivalentTo(expectedManifest); } - [Fact] + [TestMethod] public void ComputeDevelopmentManifest_CanMapMultiplePatternsOnSameNode() { // Arrange @@ -529,7 +536,7 @@ public void ComputeDevelopmentManifest_CanMapMultiplePatternsOnSameNode() manifest.Should().BeEquivalentTo(expectedManifest); } - [Fact] + [TestMethod] public void ComputeDevelopmentManifest_CanMapMultiplePatternsOnSameNodeWithDifferentContentRoots() { // Arrange @@ -567,7 +574,7 @@ public void ComputeDevelopmentManifest_CanMapMultiplePatternsOnSameNodeWithDiffe manifest.Should().BeEquivalentTo(expectedManifest); } - [Fact] + [TestMethod] public void ComputeDevelopmentManifest_MultipleAssetsSameContentRoot() { // Arrange @@ -603,7 +610,7 @@ public void ComputeDevelopmentManifest_MultipleAssetsSameContentRoot() manifest.Should().BeEquivalentTo(expectedManifest); } - [Fact] + [TestMethod] public void ComputeDevelopmentManifest_DifferentCasingEndUpInDifferentNodes() { // Arrange @@ -639,7 +646,7 @@ public void ComputeDevelopmentManifest_DifferentCasingEndUpInDifferentNodes() manifest.Should().BeEquivalentTo(expectedManifest); } - [Fact] + [TestMethod] public void ComputeDevelopmentManifest_UsesBasePathForAssetsFromDifferentProjects() { // Arrange diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsManifestMultiThreadingTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsManifestMultiThreadingTest.cs index a1626d6a3f20..9266ab9ebbbf 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsManifestMultiThreadingTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsManifestMultiThreadingTest.cs @@ -9,13 +9,13 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; -// Test parallelization is disabled assembly-wide via -// [assembly:CollectionBehavior(DisableTestParallelization = true)] in -// LegacyStaticWebAssetsV1IntegrationTest.cs, which already isolates the -// process-CWD mutation this test performs. +// This test mutates the process-wide current directory, so it must not run +// concurrently with other tests under MSTest's method-level parallelization. +[DoNotParallelize] +[TestClass] public class GenerateStaticWebAssetsManifestMultiThreadingTest { - [Fact] + [TestMethod] public void WritesManifestAndCacheRelativeToTaskEnvironmentProjectDirectory_NotProcessCurrentDirectory() { // Layout: place project and decoy in disjoint subtrees so that the same diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsManifestTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsManifestTest.cs index 63899799ee8e..8bd884e9d8d6 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsManifestTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsManifestTest.cs @@ -1,14 +1,21 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Moq; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { + [TestClass] public class GenerateStaticWebAssetsManifestTest { public GenerateStaticWebAssetsManifestTest() @@ -19,7 +26,7 @@ public GenerateStaticWebAssetsManifestTest() public string TempFilePath { get; } - [Fact] + [TestMethod] public void CanGenerateEmptyManifest() { var errorMessages = new List(); @@ -63,7 +70,7 @@ public void CanGenerateEmptyManifest() manifest.Source.Should().Be("MyProject"); } - [Fact] + [TestMethod] public void GeneratesManifestWithAssets() { var errorMessages = new List(); @@ -171,8 +178,8 @@ public static TheoryData> GeneratesManifestFailsWhenInval } } - [Theory] - [MemberData(nameof(GeneratesManifestFailsWhenInvalidAssetsAreProvidedData))] + [TestMethod] + [DynamicData(nameof(GeneratesManifestFailsWhenInvalidAssetsAreProvidedData))] public void GeneratesManifestFailsWhenInvalidAssetsAreProvided(Action change) { var errorMessages = new List(); @@ -249,8 +256,8 @@ public static TheoryData GeneratesManifestFailsW } } - [Theory] - [MemberData(nameof(GeneratesManifestFailsWhenTwoAssetsEndUpOnTheSamePathData))] + [TestMethod] + [DynamicData(nameof(GeneratesManifestFailsWhenTwoAssetsEndUpOnTheSamePathData))] public void GeneratesManifestFailsWhenTwoAssetsEndUpOnTheSamePath(StaticWebAsset first, StaticWebAsset second) { var errorMessages = new List(); @@ -286,7 +293,7 @@ public void GeneratesManifestFailsWhenTwoAssetsEndUpOnTheSamePath(StaticWebAsset } - [Fact] + [TestMethod] public void GeneratesManifestWithReferencedProjectConfigurations() { var errorMessages = new List(); @@ -323,7 +330,7 @@ public void GeneratesManifestWithReferencedProjectConfigurations() newProjectConfig.Should().Be(projectReference); } - [Fact] + [TestMethod] public void GeneratesManifestWithDiscoveryPatterns() { var errorMessages = new List(); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsPropsFileMultiThreadingTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsPropsFileMultiThreadingTest.cs index e7d560866cf8..5fd5af8a9659 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsPropsFileMultiThreadingTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsPropsFileMultiThreadingTest.cs @@ -10,9 +10,13 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; +// This test mutates the process-wide current directory, so it must not run +// concurrently with other tests under MSTest's method-level parallelization. +[DoNotParallelize] +[TestClass] public class GenerateStaticWebAssetsPropsFileMultiThreadingTest { - [Fact] + [TestMethod] public void WritesPropsFileRelativeToTaskEnvironmentProjectDirectory_NotProcessCurrentDirectory() { var testRoot = Path.Combine(AppContext.BaseDirectory, nameof(GenerateStaticWebAssetsPropsFileMultiThreadingTest), Guid.NewGuid().ToString("N")); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsPropsFileTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsPropsFileTest.cs index ccbcefc18867..2a06566c1d55 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsPropsFileTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateStaticWebAssetsPropsFileTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -11,9 +17,10 @@ namespace Microsoft.NET.Sdk.Razor.Test { + [TestClass] public class GenerateStaticWebAssetsPropsFileTest { - [Fact] + [TestMethod] public void Fails_WhenStaticWebAsset_DoesNotContainSourceType() { // Arrange @@ -46,7 +53,7 @@ public void Fails_WhenStaticWebAsset_DoesNotContainSourceType() errorMessages.Should().ContainSingle(message => message == expectedError); } - [Fact] + [TestMethod] public void Fails_WhenStaticWebAsset_DoesNotContainSourceId() { // Arrange @@ -79,7 +86,7 @@ public void Fails_WhenStaticWebAsset_DoesNotContainSourceId() errorMessages.Should().ContainSingle(message => message == expectedError); } - [Fact] + [TestMethod] public void Fails_WhenStaticWebAsset_DoesNotContainContentRoot() { // Arrange @@ -112,7 +119,7 @@ public void Fails_WhenStaticWebAsset_DoesNotContainContentRoot() errorMessages.Should().ContainSingle(message => message == expectedError); } - [Fact] + [TestMethod] public void Fails_WhenStaticWebAsset_DoesNotContainBasePath() { // Arrange @@ -145,7 +152,7 @@ public void Fails_WhenStaticWebAsset_DoesNotContainBasePath() errorMessages.Should().ContainSingle(message => message == expectedError); } - [Fact] + [TestMethod] public void Fails_WhenStaticWebAsset_DoesNotContainRelativePath() { // Arrange @@ -186,7 +193,7 @@ public void Fails_WhenStaticWebAsset_DoesNotContainRelativePath() errorMessages.Should().ContainSingle(message => message == expectedError); } - [Fact] + [TestMethod] public void Fails_WhenStaticWebAsset_HasInvalidSourceType() { // Arrange @@ -246,7 +253,7 @@ public void Fails_WhenStaticWebAsset_HasInvalidSourceType() errorMessages.Should().ContainSingle(message => message == expectedError); } - [Fact] + [TestMethod] public void Fails_WhenStaticWebAsset_HaveDifferentSourceId() { // Arrange @@ -307,7 +314,7 @@ public void Fails_WhenStaticWebAsset_HaveDifferentSourceId() errorMessages.Should().ContainSingle(message => message == expectedError); } - [Fact] + [TestMethod] public void WritesPropsFile_WhenThereIsAtLeastOneStaticAsset() { // Arrange @@ -388,7 +395,7 @@ public void WritesPropsFile_WhenThereIsAtLeastOneStaticAsset() } } - [Fact] + [TestMethod] public void WritesIndividualItems_WithTheirRespectiveBaseAndRelativePaths() { // Arrange @@ -497,9 +504,9 @@ public void WritesIndividualItems_WithTheirRespectiveBaseAndRelativePaths() var result = task.Execute(); // Assert - Assert.True(result); + Assert.IsTrue(result); var document = File.ReadAllText(file); - Assert.Equal(expectedDocument, document, ignoreLineEndingDifferences: true); + Assert.AreEqual(expectedDocument.ReplaceLineEndings(), document.ReplaceLineEndings()); } finally { @@ -510,7 +517,7 @@ public void WritesIndividualItems_WithTheirRespectiveBaseAndRelativePaths() } } - [Fact] + [TestMethod] public void WritesFrameworkSourceType_WhenAssetMatchesFrameworkPattern() { // Arrange @@ -620,9 +627,9 @@ public void WritesFrameworkSourceType_WhenAssetMatchesFrameworkPattern() var result = task.Execute(); // Assert - Assert.True(result); + Assert.IsTrue(result); var document = File.ReadAllText(file); - Assert.Equal(expectedDocument, document, ignoreLineEndingDifferences: true); + Assert.AreEqual(expectedDocument.ReplaceLineEndings(), document.ReplaceLineEndings()); } finally { @@ -633,7 +640,7 @@ public void WritesFrameworkSourceType_WhenAssetMatchesFrameworkPattern() } } - [Fact] + [TestMethod] public void WritesAllAsPackage_WhenFrameworkPatternIsNull() { // Arrange @@ -692,7 +699,7 @@ public void WritesAllAsPackage_WhenFrameworkPatternIsNull() } } - [Fact] + [TestMethod] public void WritesFrameworkSourceType_WithMultiplePatterns() { // Arrange @@ -799,7 +806,7 @@ public void WritesFrameworkSourceType_WithMultiplePatterns() } } - [Fact] + [TestMethod] public void WritesAllAsPackage_WhenFrameworkPatternMatchesNothing() { // Arrange diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateV1StaticWebAssetsManifestTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateV1StaticWebAssetsManifestTest.cs index cf209c460cc0..de2ee9d92ab8 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateV1StaticWebAssetsManifestTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/GenerateV1StaticWebAssetsManifestTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -10,9 +16,10 @@ namespace Microsoft.NET.Sdk.Razor.Test { + [TestClass] public class GenerateV1StaticWebAssetsManifestTest { - [Fact] + [TestMethod] public void ReturnsError_WhenBasePathIsMissing() { // Arrange @@ -42,7 +49,7 @@ public void ReturnsError_WhenBasePathIsMissing() errorMessages.Should().ContainSingle(message => message == expectedError); } - [Fact] + [TestMethod] public void ReturnsError_WhenContentRootIsMissing() { // Arrange @@ -72,7 +79,7 @@ public void ReturnsError_WhenContentRootIsMissing() errorMessages.Should().ContainSingle(message => message == expectedError); } - [Fact] + [TestMethod] public void AllowsMultipleContentRootsWithSameBasePath_ForTheSameSourceId() { // Arrange @@ -124,7 +131,7 @@ public void AllowsMultipleContentRootsWithSameBasePath_ForTheSameSourceId() } } - [Fact] + [TestMethod] public void Generates_EmptyManifest_WhenNoItems_Passed() { // Arrange @@ -159,7 +166,7 @@ public void Generates_EmptyManifest_WhenNoItems_Passed() } } - [Fact] + [TestMethod] public void Generates_Manifest_WhenContentRootsAvailable() { // Arrange @@ -204,7 +211,7 @@ public void Generates_Manifest_WhenContentRootsAvailable() } } - [Fact] + [TestMethod] public void SkipsAdditionalElements_WithSameBasePathAndSameContentRoot() { // Arrange diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/Globbing/PathTokenizerTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/Globbing/PathTokenizerTest.cs index ed77b13265c1..03af8c66f0da 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/Globbing/PathTokenizerTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/Globbing/PathTokenizerTest.cs @@ -2,132 +2,140 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace Microsoft.AspNetCore.StaticWebAssets.Tasks.Test; +[TestClass] + public class PathTokenizerTest { - [Fact] + [TestMethod] public void RootSeparator_ProducesEmptySegment() { var path = "/a/b/c"; var tokenizer = new PathTokenizer(path.AsMemory().Span); var segments = new List(); var collection = tokenizer.Fill(segments); - Assert.Equal("a", collection[0]); - Assert.Equal("b", collection[1]); - Assert.Equal("c", collection[2]); + Assert.AreEqual("a", collection[0].ToString()); + Assert.AreEqual("b", collection[1].ToString()); + Assert.AreEqual("c", collection[2].ToString()); } - [Fact] + [TestMethod] public void NonRootSeparator_ProducesInitialSegment() { var path = "a/b/c"; var tokenizer = new PathTokenizer(path.AsMemory().Span); var segments = new List(); var collection = tokenizer.Fill(segments); - Assert.Equal("a", collection[0]); - Assert.Equal("b", collection[1]); - Assert.Equal("c", collection[2]); + Assert.AreEqual("a", collection[0].ToString()); + Assert.AreEqual("b", collection[1].ToString()); + Assert.AreEqual("c", collection[2].ToString()); } - [Fact] + [TestMethod] public void NonRootSeparator_MatchesMultipleCharacters() { var path = "aa/b/c"; var tokenizer = new PathTokenizer(path.AsMemory().Span); var segments = new List(); var collection = tokenizer.Fill(segments); - Assert.Equal("aa", collection[0]); - Assert.Equal("b", collection[1]); - Assert.Equal("c", collection[2]); + Assert.AreEqual("aa", collection[0].ToString()); + Assert.AreEqual("b", collection[1].ToString()); + Assert.AreEqual("c", collection[2].ToString()); } - [Fact] + [TestMethod] public void NonRootSeparator_HandlesConsecutivePathSeparators() { var path = "aa//b/c"; var tokenizer = new PathTokenizer(path.AsMemory().Span); var segments = new List(); var collection = tokenizer.Fill(segments); - Assert.Equal("aa", collection[0]); - Assert.Equal("b", collection[1]); - Assert.Equal("c", collection[2]); + Assert.AreEqual("aa", collection[0].ToString()); + Assert.AreEqual("b", collection[1].ToString()); + Assert.AreEqual("c", collection[2].ToString()); } - [Fact] + [TestMethod] public void NonRootSeparator_HandlesFinalPathSeparator() { var path = "aa/b/c/"; var tokenizer = new PathTokenizer(path.AsMemory().Span); var segments = new List(); var collection = tokenizer.Fill(segments); - Assert.Equal("aa", collection[0]); - Assert.Equal("b", collection[1]); - Assert.Equal("c", collection[2]); + Assert.AreEqual("aa", collection[0].ToString()); + Assert.AreEqual("b", collection[1].ToString()); + Assert.AreEqual("c", collection[2].ToString()); } - [Fact] + [TestMethod] public void NonRootSeparator_HandlesAlternativePathSeparators() { var path = "aa\\b\\c\\"; var tokenizer = new PathTokenizer(path.AsMemory().Span); var segments = new List(); var collection = tokenizer.Fill(segments); - Assert.Equal("aa", collection[0]); - Assert.Equal("b", collection[1]); - Assert.Equal("c", collection[2]); + Assert.AreEqual("aa", collection[0].ToString()); + Assert.AreEqual("b", collection[1].ToString()); + Assert.AreEqual("c", collection[2].ToString()); } - [Fact] + [TestMethod] public void NonRootSeparator_HandlesMixedPathSeparators() { var path = "aa/b\\c/"; var tokenizer = new PathTokenizer(path.AsMemory().Span); var segments = new List(); var collection = tokenizer.Fill(segments); - Assert.Equal("aa", collection[0]); - Assert.Equal("b", collection[1]); - Assert.Equal("c", collection[2]); + Assert.AreEqual("aa", collection[0].ToString()); + Assert.AreEqual("b", collection[1].ToString()); + Assert.AreEqual("c", collection[2].ToString()); } - [Fact] + [TestMethod] public void Ignores_EmpySegments() { var path = "aa//b//c"; var tokenizer = new PathTokenizer(path.AsMemory().Span); var segments = new List(); var collection = tokenizer.Fill(segments); - Assert.Equal("aa", collection[0]); - Assert.Equal("b", collection[1]); - Assert.Equal("c", collection[2]); + Assert.AreEqual("aa", collection[0].ToString()); + Assert.AreEqual("b", collection[1].ToString()); + Assert.AreEqual("c", collection[2].ToString()); } - [Fact] + [TestMethod] public void Ignores_DotSegments() { var path = "./aa/./b/./c/."; var tokenizer = new PathTokenizer(path.AsMemory().Span); var segments = new List(); var collection = tokenizer.Fill(segments); - Assert.Equal("aa", collection[0]); - Assert.Equal("b", collection[1]); - Assert.Equal("c", collection[2]); + Assert.AreEqual("aa", collection[0].ToString()); + Assert.AreEqual("b", collection[1].ToString()); + Assert.AreEqual("c", collection[2].ToString()); } - [Fact] + [TestMethod] public void Ignores_DotDotSegments() { var path = "../aa/../b/../c/.."; var tokenizer = new PathTokenizer(path.AsMemory().Span); var segments = new List(); var collection = tokenizer.Fill(segments); - Assert.Equal("aa", collection[0]); - Assert.Equal("b", collection[1]); - Assert.Equal("c", collection[2]); + Assert.AreEqual("aa", collection[0].ToString()); + Assert.AreEqual("b", collection[1].ToString()); + Assert.AreEqual("c", collection[2].ToString()); } } diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/Globbing/StaticWebAssetGlobMatcherTest.Compatibility.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/Globbing/StaticWebAssetGlobMatcherTest.Compatibility.cs index f68ea9169c4f..b75a3531bad1 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/Globbing/StaticWebAssetGlobMatcherTest.Compatibility.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/Globbing/StaticWebAssetGlobMatcherTest.Compatibility.cs @@ -1,11 +1,18 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. namespace Microsoft.AspNetCore.StaticWebAssets.Tasks.Test; public partial class StaticWebAssetGlobMatcherTest { - [Fact] + [TestMethod] public void MatchingFileIsFound() { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -13,11 +20,11 @@ public void MatchingFileIsFound() var globMatcher = matcher.Build(); var match = globMatcher.Match("alpha.txt"); - Assert.True(match.IsMatch); - Assert.Equal("alpha.txt", match.Pattern); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("alpha.txt", match.Pattern); } - [Fact] + [TestMethod] public void MismatchedFileIsIgnored() { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -25,10 +32,10 @@ public void MismatchedFileIsIgnored() var globMatcher = matcher.Build(); var match = globMatcher.Match("omega.txt"); - Assert.False(match.IsMatch); + Assert.IsFalse(match.IsMatch); } - [Fact] + [TestMethod] public void FolderNamesAreTraversed() { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -36,16 +43,16 @@ public void FolderNamesAreTraversed() var globMatcher = matcher.Build(); var match = globMatcher.Match("beta/alpha.txt"); - Assert.True(match.IsMatch); - Assert.Equal("beta/alpha.txt", match.Pattern); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("beta/alpha.txt", match.Pattern); } - [Theory] - [InlineData(@"beta/alpha.txt", @"beta/alpha.txt")] - [InlineData(@"beta\alpha.txt", @"beta/alpha.txt")] - [InlineData(@"beta/alpha.txt", @"beta\alpha.txt")] - [InlineData(@"beta\alpha.txt", @"beta\alpha.txt")] - [InlineData(@"\beta\alpha.txt", @"beta/alpha.txt")] + [TestMethod] + [DataRow(@"beta/alpha.txt", @"beta/alpha.txt")] + [DataRow(@"beta\alpha.txt", @"beta/alpha.txt")] + [DataRow(@"beta/alpha.txt", @"beta\alpha.txt")] + [DataRow(@"beta\alpha.txt", @"beta\alpha.txt")] + [DataRow(@"\beta\alpha.txt", @"beta/alpha.txt")] public void SlashPolarityIsIgnored(string includePattern, string filePath) { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -53,18 +60,18 @@ public void SlashPolarityIsIgnored(string includePattern, string filePath) var globMatcher = matcher.Build(); var match = globMatcher.Match(filePath); - Assert.True(match.IsMatch); - //Assert.Equal("beta/alpha.txt", match.Pattern); + Assert.IsTrue(match.IsMatch); + //Assert.AreEqual("beta/alpha.txt", match.Pattern); } - [Theory] - [InlineData(@"alpha.*", new[] { "alpha.txt" })] - [InlineData(@"*", new[] { "alpha.txt", "beta.txt", "gamma.dat" })] - [InlineData(@"*et*", new[] { "beta.txt" })] - [InlineData(@"*.*", new[] { "alpha.txt", "beta.txt", "gamma.dat" })] - [InlineData(@"b*et*x", new string[0])] - [InlineData(@"*.txt", new[] { "alpha.txt", "beta.txt" })] - [InlineData(@"b*et*t", new[] { "beta.txt" })] + [TestMethod] + [DataRow(@"alpha.*", new[] { "alpha.txt" })] + [DataRow(@"*", new[] { "alpha.txt", "beta.txt", "gamma.dat" })] + [DataRow(@"*et*", new[] { "beta.txt" })] + [DataRow(@"*.*", new[] { "alpha.txt", "beta.txt", "gamma.dat" })] + [DataRow(@"b*et*x", new string[0])] + [DataRow(@"*.txt", new[] { "alpha.txt", "beta.txt" })] + [DataRow(@"b*et*t", new[] { "beta.txt" })] public void CanPatternMatch(string includes, string[] expected) { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -75,16 +82,16 @@ public void CanPatternMatch(string includes, string[] expected) .Where(file => globMatcher.Match(file).IsMatch) .ToArray(); - Assert.Equal(expected, matches); + Assert.AreSequenceEqual(expected, matches); } - [Theory] - [InlineData(@"12345*5678", new string[0])] - [InlineData(@"1234*5678", new[] { "12345678" })] - [InlineData(@"12*23*", new string[0])] - [InlineData(@"12*3456*78", new[] { "12345678" })] - [InlineData(@"*45*56", new string[0])] - [InlineData(@"*67*78", new string[0])] + [TestMethod] + [DataRow(@"12345*5678", new string[0])] + [DataRow(@"1234*5678", new[] { "12345678" })] + [DataRow(@"12*23*", new string[0])] + [DataRow(@"12*3456*78", new[] { "12345678" })] + [DataRow(@"*45*56", new string[0])] + [DataRow(@"*67*78", new string[0])] public void PatternBeginAndEndCantOverlap(string includes, string[] expected) { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -95,18 +102,18 @@ public void PatternBeginAndEndCantOverlap(string includes, string[] expected) .Where(file => globMatcher.Match(file).IsMatch) .ToArray(); - Assert.Equal(expected, matches); + Assert.AreSequenceEqual(expected, matches); } - [Theory] - [InlineData(@"*alpha*/*", new[] { "alpha/hello.txt" })] - [InlineData(@"/*/*", new[] { "alpha/hello.txt", "beta/hello.txt", "gamma/hello.txt" })] - [InlineData(@"*/*", new[] { "alpha/hello.txt", "beta/hello.txt", "gamma/hello.txt" })] - [InlineData(@"/*.*/*", new string[] { })] - [InlineData(@"*.*/*", new string[] { })] - [InlineData(@"/*mm*/*", new[] { "gamma/hello.txt" })] - [InlineData(@"*mm*/*", new[] { "gamma/hello.txt" })] - [InlineData(@"/*alpha*/*", new[] { "alpha/hello.txt" })] + [TestMethod] + [DataRow(@"*alpha*/*", new[] { "alpha/hello.txt" })] + [DataRow(@"/*/*", new[] { "alpha/hello.txt", "beta/hello.txt", "gamma/hello.txt" })] + [DataRow(@"*/*", new[] { "alpha/hello.txt", "beta/hello.txt", "gamma/hello.txt" })] + [DataRow(@"/*.*/*", new string[] { })] + [DataRow(@"*.*/*", new string[] { })] + [DataRow(@"/*mm*/*", new[] { "gamma/hello.txt" })] + [DataRow(@"*mm*/*", new[] { "gamma/hello.txt" })] + [DataRow(@"/*alpha*/*", new[] { "alpha/hello.txt" })] public void PatternMatchingWorksInFolders(string includes, string[] expected) { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -117,19 +124,19 @@ public void PatternMatchingWorksInFolders(string includes, string[] expected) .Where(file => globMatcher.Match(file).IsMatch) .ToArray(); - Assert.Equal(expected, matches); + Assert.AreSequenceEqual(expected, matches); } - [Theory] - [InlineData(@"", new string[] { })] - [InlineData(@"./", new string[] { "alpha/hello.txt", "beta/hello.txt", "gamma/hello.txt" })] - [InlineData(@"./alpha/hello.txt", new string[] { "alpha/hello.txt" })] - [InlineData(@"./**/hello.txt", new string[] { "alpha/hello.txt", "beta/hello.txt", "gamma/hello.txt" })] - [InlineData(@"././**/hello.txt", new string[] { "alpha/hello.txt", "beta/hello.txt", "gamma/hello.txt" })] - [InlineData(@"././**/./hello.txt", new string[] { "alpha/hello.txt", "beta/hello.txt", "gamma/hello.txt" })] - [InlineData(@"././**/./**/hello.txt", new string[] { "alpha/hello.txt", "beta/hello.txt", "gamma/hello.txt" })] - [InlineData(@"./*mm*/hello.txt", new string[] { "gamma/hello.txt" })] - [InlineData(@"./*mm*/*", new string[] { "gamma/hello.txt" })] + [TestMethod] + [DataRow(@"", new string[] { })] + [DataRow(@"./", new string[] { "alpha/hello.txt", "beta/hello.txt", "gamma/hello.txt" })] + [DataRow(@"./alpha/hello.txt", new string[] { "alpha/hello.txt" })] + [DataRow(@"./**/hello.txt", new string[] { "alpha/hello.txt", "beta/hello.txt", "gamma/hello.txt" })] + [DataRow(@"././**/hello.txt", new string[] { "alpha/hello.txt", "beta/hello.txt", "gamma/hello.txt" })] + [DataRow(@"././**/./hello.txt", new string[] { "alpha/hello.txt", "beta/hello.txt", "gamma/hello.txt" })] + [DataRow(@"././**/./**/hello.txt", new string[] { "alpha/hello.txt", "beta/hello.txt", "gamma/hello.txt" })] + [DataRow(@"./*mm*/hello.txt", new string[] { "gamma/hello.txt" })] + [DataRow(@"./*mm*/*", new string[] { "gamma/hello.txt" })] public void PatternMatchingCurrent(string includePattern, string[] matchesExpected) { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -140,10 +147,10 @@ public void PatternMatchingCurrent(string includePattern, string[] matchesExpect .Where(file => globMatcher.Match(file).IsMatch) .ToArray(); - Assert.Equal(matchesExpected, matches); + Assert.AreSequenceEqual(matchesExpected, matches); } - [Fact] + [TestMethod] public void StarDotStarIsSameAsStar() { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -154,10 +161,10 @@ public void StarDotStarIsSameAsStar() .Where(file => globMatcher.Match(file).IsMatch) .ToArray(); - Assert.Equal(new[] { "alpha.txt", "alpha.", ".txt" }, matches); + Assert.AreSequenceEqual(new[] { "alpha.txt", "alpha.", ".txt" }, matches); } - [Fact] + [TestMethod] public void IncompletePatternsDoNotInclude() { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -168,10 +175,10 @@ public void IncompletePatternsDoNotInclude() .Where(file => globMatcher.Match(file).IsMatch) .ToArray(); - Assert.Equal(new[] { "one/x.txt", "two/x.txt" }, matches); + Assert.AreSequenceEqual(new[] { "one/x.txt", "two/x.txt" }, matches); } - [Fact] + [TestMethod] public void IncompletePatternsDoNotExclude() { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -183,10 +190,10 @@ public void IncompletePatternsDoNotExclude() .Where(file => globMatcher.Match(file).IsMatch) .ToArray(); - Assert.Equal(new[] { "one/x.txt", "two/x.txt" }, matches); + Assert.AreSequenceEqual(new[] { "one/x.txt", "two/x.txt" }, matches); } - [Fact] + [TestMethod] public void TrailingRecursiveWildcardMatchesAllFiles() { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -197,10 +204,10 @@ public void TrailingRecursiveWildcardMatchesAllFiles() .Where(file => globMatcher.Match(file).IsMatch) .ToArray(); - Assert.Equal(new[] { "one/x.txt", "one/x/y.txt" }, matches); + Assert.AreSequenceEqual(new[] { "one/x.txt", "one/x/y.txt" }, matches); } - [Fact] + [TestMethod] public void LeadingRecursiveWildcardMatchesAllLeadingPaths() { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -211,10 +218,10 @@ public void LeadingRecursiveWildcardMatchesAllLeadingPaths() .Where(file => globMatcher.Match(file).IsMatch) .ToArray(); - Assert.Equal(new[] { "one/x.cs", "two/x.cs", "one/two/x.cs", "x.cs" }, matches); + Assert.AreSequenceEqual(new[] { "one/x.cs", "two/x.cs", "one/two/x.cs", "x.cs" }, matches); } - [Fact] + [TestMethod] public void InnerRecursiveWildcardMustStartWithAndEndWith() { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -225,10 +232,10 @@ public void InnerRecursiveWildcardMustStartWithAndEndWith() .Where(file => globMatcher.Match(file).IsMatch) .ToArray(); - Assert.Equal(new[] { "one/x.cs", "one/two/x.cs" }, matches); + Assert.AreSequenceEqual(new[] { "one/x.cs", "one/two/x.cs" }, matches); } - [Fact] + [TestMethod] public void ExcludeMayEndInDirectoryName() { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -240,10 +247,10 @@ public void ExcludeMayEndInDirectoryName() .Where(file => globMatcher.Match(file).IsMatch) .ToArray(); - Assert.Equal(new[] { "one/x.cs", "two/x.cs", "x.cs" }, matches); + Assert.AreSequenceEqual(new[] { "one/x.cs", "two/x.cs", "x.cs" }, matches); } - [Fact] + [TestMethod] public void RecursiveWildcardSurroundingContainsWith() { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -254,10 +261,10 @@ public void RecursiveWildcardSurroundingContainsWith() .Where(file => globMatcher.Match(file).IsMatch) .ToArray(); - Assert.Equal(new[] { "x/1", "1/x/2", "1/x", "x" }, matches); + Assert.AreSequenceEqual(new[] { "x/1", "1/x/2", "1/x", "x" }, matches); } - [Fact] + [TestMethod] public void SequentialFoldersMayBeRequired() { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -268,10 +275,10 @@ public void SequentialFoldersMayBeRequired() .Where(file => globMatcher.Match(file).IsMatch) .ToArray(); - Assert.Equal(new[] { "a/b/1/2/2/3/x", "a/b/a/1/2/4/2/3/b" }, matches); + Assert.AreSequenceEqual(new[] { "a/b/1/2/2/3/x", "a/b/a/1/2/4/2/3/b" }, matches); } - [Fact] + [TestMethod] public void RecursiveAloneIncludesEverything() { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -282,10 +289,10 @@ public void RecursiveAloneIncludesEverything() .Where(file => globMatcher.Match(file).IsMatch) .ToArray(); - Assert.Equal(new[] { "1/2/2/3/x", "1/2/3/y" }, matches); + Assert.AreSequenceEqual(new[] { "1/2/2/3/x", "1/2/3/y" }, matches); } - [Fact] + [TestMethod] public void ExcludeCanHaveSurroundingRecursiveWildcards() { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -297,6 +304,6 @@ public void ExcludeCanHaveSurroundingRecursiveWildcards() .Where(file => globMatcher.Match(file).IsMatch) .ToArray(); - Assert.Equal(new[] { "1", "1/2" }, matches); + Assert.AreSequenceEqual(new[] { "1", "1/2" }, matches); } } diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/Globbing/StaticWebAssetGlobMatcherTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/Globbing/StaticWebAssetGlobMatcherTest.cs index fb2746fb1ce5..fdf5b6700ac6 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/Globbing/StaticWebAssetGlobMatcherTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/Globbing/StaticWebAssetGlobMatcherTest.cs @@ -2,11 +2,17 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace Microsoft.AspNetCore.StaticWebAssets.Tasks.Test; // Set of things to test: @@ -25,20 +31,21 @@ namespace Microsoft.AspNetCore.StaticWebAssets.Tasks.Test; // Recursive wildcard at the beginning '**/a' // Recursive wildcard at the end 'a/**' // Recursive wildcard in the middle 'a/**/c' +[TestClass] public partial class StaticWebAssetGlobMatcherTest { - [Theory] - [InlineData("**/*.razor.js", "Components/Pages/RegularComponent.razor.js", "Components/Pages/RegularComponent.razor.js")] - [InlineData("**/*.razor.js", "Components/User.Profile.Details.razor.js", "Components/User.Profile.Details.razor.js")] - [InlineData("**/*.razor.js", "Components/Area/Sub/Feature/User.Profile.Details.razor.js", "Components/Area/Sub/Feature/User.Profile.Details.razor.js")] - [InlineData("**/*.razor.js", "Components/Area/Sub/Feature/Deep.Component.Name.With.Many.Parts.razor.js", "Components/Area/Sub/Feature/Deep.Component.Name.With.Many.Parts.razor.js")] - [InlineData("**/*.cshtml.js", "Pages/Shared/_Host.cshtml.js", "Pages/Shared/_Host.cshtml.js")] - [InlineData("**/*.cshtml.js", "Areas/Admin/Pages/Dashboard.cshtml.js", "Areas/Admin/Pages/Dashboard.cshtml.js")] - [InlineData("*.lib.module.js", "Widget.lib.module.js", "Widget.lib.module.js")] - [InlineData("*.razor.css", "Component.razor.css", "Component.razor.css")] - [InlineData("*.cshtml.css", "View.cshtml.css", "View.cshtml.css")] - [InlineData("*.modules.json", "app.modules.json", "app.modules.json")] - [InlineData("*.lib.module.js", "Rcl.Client.Feature.lib.module.js", "Rcl.Client.Feature.lib.module.js")] + [TestMethod] + [DataRow("**/*.razor.js", "Components/Pages/RegularComponent.razor.js", "Components/Pages/RegularComponent.razor.js")] + [DataRow("**/*.razor.js", "Components/User.Profile.Details.razor.js", "Components/User.Profile.Details.razor.js")] + [DataRow("**/*.razor.js", "Components/Area/Sub/Feature/User.Profile.Details.razor.js", "Components/Area/Sub/Feature/User.Profile.Details.razor.js")] + [DataRow("**/*.razor.js", "Components/Area/Sub/Feature/Deep.Component.Name.With.Many.Parts.razor.js", "Components/Area/Sub/Feature/Deep.Component.Name.With.Many.Parts.razor.js")] + [DataRow("**/*.cshtml.js", "Pages/Shared/_Host.cshtml.js", "Pages/Shared/_Host.cshtml.js")] + [DataRow("**/*.cshtml.js", "Areas/Admin/Pages/Dashboard.cshtml.js", "Areas/Admin/Pages/Dashboard.cshtml.js")] + [DataRow("*.lib.module.js", "Widget.lib.module.js", "Widget.lib.module.js")] + [DataRow("*.razor.css", "Component.razor.css", "Component.razor.css")] + [DataRow("*.cshtml.css", "View.cshtml.css", "View.cshtml.css")] + [DataRow("*.modules.json", "app.modules.json", "app.modules.json")] + [DataRow("*.lib.module.js", "Rcl.Client.Feature.lib.module.js", "Rcl.Client.Feature.lib.module.js")] public void Can_Match_WellKnownExistingPatterns(string pattern, string path, string expectedStem) { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -46,11 +53,11 @@ public void Can_Match_WellKnownExistingPatterns(string pattern, string path, str var globMatcher = matcher.Build(); var match = globMatcher.Match(path); - Assert.True(match.IsMatch); - Assert.Equal(pattern, match.Pattern); - Assert.Equal(expectedStem, match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual(pattern, match.Pattern); + Assert.AreEqual(expectedStem, match.Stem); } - [Fact] + [TestMethod] public void CanMatchLiterals() { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -58,12 +65,12 @@ public void CanMatchLiterals() var globMatcher = matcher.Build(); var match = globMatcher.Match("a"); - Assert.True(match.IsMatch); - Assert.Equal("a", match.Pattern); - Assert.Equal("a", match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("a", match.Pattern); + Assert.AreEqual("a", match.Stem); } - [Fact] + [TestMethod] public void CanMatchMultipleLiterals() { var matcher = new StaticWebAssetGlobMatcherBuilder(); @@ -71,228 +78,228 @@ public void CanMatchMultipleLiterals() var globMatcher = matcher.Build(); var match = globMatcher.Match("a/b"); - Assert.True(match.IsMatch); - Assert.Equal("a/b", match.Pattern); - Assert.Equal("b", match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("a/b", match.Pattern); + Assert.AreEqual("b", match.Stem); } - [Fact] + [TestMethod] public void CanMatchExtensions() { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns("*.a"); var globMatcher = matcher.Build(); var match = globMatcher.Match("a.a"); - Assert.True(match.IsMatch); - Assert.Equal("*.a", match.Pattern); - Assert.Equal("a.a", match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("*.a", match.Pattern); + Assert.AreEqual("a.a", match.Stem); } - [Fact] + [TestMethod] public void MatchesLongerExtensionsFirst() { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns("*.a", "*.b.a"); var globMatcher = matcher.Build(); var match = globMatcher.Match("c.b.a"); - Assert.True(match.IsMatch); - Assert.Equal("*.b.a", match.Pattern); - Assert.Equal("c.b.a", match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("*.b.a", match.Pattern); + Assert.AreEqual("c.b.a", match.Stem); } - [Fact] + [TestMethod] public void CanMatchExtensionsAtTheBeginning() { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns("*.a/b"); var globMatcher = matcher.Build(); var match = globMatcher.Match("c.a/b"); - Assert.True(match.IsMatch); - Assert.Equal("*.a/b", match.Pattern); - Assert.Equal("b", match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("*.a/b", match.Pattern); + Assert.AreEqual("b", match.Stem); } - [Fact] + [TestMethod] public void CanMatchExtensionsAtTheEnd() { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns("a/*.b"); var globMatcher = matcher.Build(); var match = globMatcher.Match("a/c.b"); - Assert.True(match.IsMatch); - Assert.Equal("a/*.b", match.Pattern); - Assert.Equal("c.b", match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("a/*.b", match.Pattern); + Assert.AreEqual("c.b", match.Stem); } - [Fact] + [TestMethod] public void CanMatchExtensionsInMiddle() { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns("a/*.b/c"); var globMatcher = matcher.Build(); var match = globMatcher.Match("a/d.b/c"); - Assert.True(match.IsMatch); - Assert.Equal("a/*.b/c", match.Pattern); - Assert.Equal("c", match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("a/*.b/c", match.Pattern); + Assert.AreEqual("c", match.Stem); } - [Theory] - [InlineData("a*")] - [InlineData("*a")] - [InlineData("?")] - [InlineData("*?")] - [InlineData("?*")] - [InlineData("**a")] - [InlineData("a**")] - [InlineData("**?")] - [InlineData("?**")] + [TestMethod] + [DataRow("a*")] + [DataRow("*a")] + [DataRow("?")] + [DataRow("*?")] + [DataRow("?*")] + [DataRow("**a")] + [DataRow("a**")] + [DataRow("**?")] + [DataRow("?**")] public void CanMatchComplexSegments(string pattern) { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns(pattern); var globMatcher = matcher.Build(); var match = globMatcher.Match("a"); - Assert.True(match.IsMatch); - Assert.Equal(pattern, match.Pattern); - Assert.Equal("a", match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual(pattern, match.Pattern); + Assert.AreEqual("a", match.Stem); } - [Theory] - [InlineData("a?", "aa", true)] - [InlineData("a?", "a", false)] - [InlineData("a?", "aaa", false)] - [InlineData("?a", "aa", true)] - [InlineData("?a", "a", false)] - [InlineData("?a", "aaa", false)] - [InlineData("a?a", "aaa", true)] - [InlineData("a?a", "aba", true)] - [InlineData("a?a", "abaa", false)] - [InlineData("a?a", "ab", false)] + [TestMethod] + [DataRow("a?", "aa", true)] + [DataRow("a?", "a", false)] + [DataRow("a?", "aaa", false)] + [DataRow("?a", "aa", true)] + [DataRow("?a", "a", false)] + [DataRow("?a", "aaa", false)] + [DataRow("a?a", "aaa", true)] + [DataRow("a?a", "aba", true)] + [DataRow("a?a", "abaa", false)] + [DataRow("a?a", "ab", false)] public void QuestionMarksMatchSingleCharacter(string pattern, string input, bool expectedMatchResult) { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns(pattern); var globMatcher = matcher.Build(); var match = globMatcher.Match(input); - Assert.Equal(expectedMatchResult, match.IsMatch); + Assert.AreEqual(expectedMatchResult, match.IsMatch); if(expectedMatchResult) { - Assert.Equal(pattern, match.Pattern); - Assert.Equal(input, match.Stem); + Assert.AreEqual(pattern, match.Pattern); + Assert.AreEqual(input, match.Stem); } else { - Assert.Null(match.Pattern); - Assert.Null(match.Stem); + Assert.IsNull(match.Pattern); + Assert.IsNull(match.Stem); } } - [Theory] - [InlineData("a??", "aaa", true)] - [InlineData("a??", "aa", false)] - [InlineData("a??", "aaaa", false)] - [InlineData("?a?", "aaa", true)] - [InlineData("?a?", "aa", false)] - [InlineData("?a?", "aaaa", false)] - [InlineData("??a", "aaa", true)] - [InlineData("??a", "aa", false)] - [InlineData("??a", "aaaa", false)] - [InlineData("a??a", "aaaa", true)] - [InlineData("a??a", "aaba", true)] - [InlineData("a??a", "aabaa", false)] - [InlineData("a??a", "aba", false)] + [TestMethod] + [DataRow("a??", "aaa", true)] + [DataRow("a??", "aa", false)] + [DataRow("a??", "aaaa", false)] + [DataRow("?a?", "aaa", true)] + [DataRow("?a?", "aa", false)] + [DataRow("?a?", "aaaa", false)] + [DataRow("??a", "aaa", true)] + [DataRow("??a", "aa", false)] + [DataRow("??a", "aaaa", false)] + [DataRow("a??a", "aaaa", true)] + [DataRow("a??a", "aaba", true)] + [DataRow("a??a", "aabaa", false)] + [DataRow("a??a", "aba", false)] public void MultipleQuestionMarksMatchExactlyTheNumberOfCharacters(string pattern, string input, bool expectedMatchResult) { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns(pattern); var globMatcher = matcher.Build(); var match = globMatcher.Match(input); - Assert.Equal(expectedMatchResult, match.IsMatch); + Assert.AreEqual(expectedMatchResult, match.IsMatch); if (expectedMatchResult) { - Assert.Equal(pattern, match.Pattern); - Assert.Equal(input, match.Stem); + Assert.AreEqual(pattern, match.Pattern); + Assert.AreEqual(input, match.Stem); } else { - Assert.Null(match.Pattern); - Assert.Null(match.Stem); + Assert.IsNull(match.Pattern); + Assert.IsNull(match.Stem); } } - [Theory] - [InlineData("a*", "a", true)] - [InlineData("a*", "aa", true)] - [InlineData("a*", "aaa", true)] - [InlineData("a*", "aaaa", true)] - [InlineData("a*", "aaaaa", true)] - [InlineData("a*", "aaaaaa", true)] - [InlineData("*a", "a", true)] - [InlineData("*a", "aa", true)] - [InlineData("*a", "aaa", true)] - [InlineData("*a", "aaaa", true)] - [InlineData("*a", "aaaaa", true)] - [InlineData("a*a", "a", false)] - [InlineData("a*a", "aa", true)] - [InlineData("a*a", "aaa", true)] - [InlineData("a*a", "aaaaa", true)] - [InlineData("a*a", "aaaaaa", true)] - [InlineData("a*a", "aba", true)] - [InlineData("a*a", "abaa", true)] - [InlineData("a*a", "abba", true)] - [InlineData("a*b", "ab", true)] + [TestMethod] + [DataRow("a*", "a", true)] + [DataRow("a*", "aa", true)] + [DataRow("a*", "aaa", true)] + [DataRow("a*", "aaaa", true)] + [DataRow("a*", "aaaaa", true)] + [DataRow("a*", "aaaaaa", true)] + [DataRow("*a", "a", true)] + [DataRow("*a", "aa", true)] + [DataRow("*a", "aaa", true)] + [DataRow("*a", "aaaa", true)] + [DataRow("*a", "aaaaa", true)] + [DataRow("a*a", "a", false)] + [DataRow("a*a", "aa", true)] + [DataRow("a*a", "aaa", true)] + [DataRow("a*a", "aaaaa", true)] + [DataRow("a*a", "aaaaaa", true)] + [DataRow("a*a", "aba", true)] + [DataRow("a*a", "abaa", true)] + [DataRow("a*a", "abba", true)] + [DataRow("a*b", "ab", true)] public void WildCardsMatchZeroOrMoreCharacters(string pattern, string input, bool expectedMatchResult) { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns(pattern); var globMatcher = matcher.Build(); var match = globMatcher.Match(input); - Assert.Equal(expectedMatchResult, match.IsMatch); + Assert.AreEqual(expectedMatchResult, match.IsMatch); if (expectedMatchResult) { - Assert.Equal(pattern, match.Pattern); - Assert.Equal(input, match.Stem); + Assert.AreEqual(pattern, match.Pattern); + Assert.AreEqual(input, match.Stem); } else { - Assert.Null(match.Pattern); - Assert.Null(match.Stem); + Assert.IsNull(match.Pattern); + Assert.IsNull(match.Stem); } } - [Theory] - [InlineData("*?a", "a", false)] - [InlineData("*?a", "aa", true)] - [InlineData("*?a", "aaa", true)] - [InlineData("*?a", "aaaa", true)] - [InlineData("*?a", "aaaaa", true)] - [InlineData("*?a", "aaaaaa", true)] - [InlineData("*??a", "aa", false)] - [InlineData("*??a", "aaa", true)] - [InlineData("*???a", "aaa", false)] - [InlineData("*???a", "aaaa", true)] - [InlineData("*????a", "aaaa", false)] - [InlineData("*????a", "aaaaa", true)] - [InlineData("*?????a", "aaaaa", false)] - [InlineData("*?????a", "aaaaaa", true)] - [InlineData("*??????a", "aaaaaa", false)] - [InlineData("*??????a", "aaaaaaa", true)] - [InlineData("a*?", "a", false)] - [InlineData("a*?", "aa", true)] - [InlineData("a*?", "aaa", true)] - [InlineData("a*?", "aaaa", true)] - [InlineData("a*?", "aaaaa", true)] - [InlineData("a*?", "aaaaaa", true)] - [InlineData("a*??", "aa", false)] - [InlineData("a*??", "aaa", true)] - [InlineData("a*???", "aaa", false)] - [InlineData("a*???", "aaaa", true)] - [InlineData("a*????", "aaaa", false)] - [InlineData("a*????", "aaaaa", true)] - [InlineData("a*?????", "aaaaa", false)] - [InlineData("a*?????", "aaaaaa", true)] - [InlineData("a*??????", "aaaaaa", false)] - [InlineData("a*??????", "aaaaaaa", true)] + [TestMethod] + [DataRow("*?a", "a", false)] + [DataRow("*?a", "aa", true)] + [DataRow("*?a", "aaa", true)] + [DataRow("*?a", "aaaa", true)] + [DataRow("*?a", "aaaaa", true)] + [DataRow("*?a", "aaaaaa", true)] + [DataRow("*??a", "aa", false)] + [DataRow("*??a", "aaa", true)] + [DataRow("*???a", "aaa", false)] + [DataRow("*???a", "aaaa", true)] + [DataRow("*????a", "aaaa", false)] + [DataRow("*????a", "aaaaa", true)] + [DataRow("*?????a", "aaaaa", false)] + [DataRow("*?????a", "aaaaaa", true)] + [DataRow("*??????a", "aaaaaa", false)] + [DataRow("*??????a", "aaaaaaa", true)] + [DataRow("a*?", "a", false)] + [DataRow("a*?", "aa", true)] + [DataRow("a*?", "aaa", true)] + [DataRow("a*?", "aaaa", true)] + [DataRow("a*?", "aaaaa", true)] + [DataRow("a*?", "aaaaaa", true)] + [DataRow("a*??", "aa", false)] + [DataRow("a*??", "aaa", true)] + [DataRow("a*???", "aaa", false)] + [DataRow("a*???", "aaaa", true)] + [DataRow("a*????", "aaaa", false)] + [DataRow("a*????", "aaaaa", true)] + [DataRow("a*?????", "aaaaa", false)] + [DataRow("a*?????", "aaaaaa", true)] + [DataRow("a*??????", "aaaaaa", false)] + [DataRow("a*??????", "aaaaaaa", true)] public void SingleWildcardPrecededOrSucceededByQuestionMarkRequireMinimumNumberOfCharacters(string pattern, string input, bool expectedMatchResult) { @@ -300,112 +307,112 @@ public void SingleWildcardPrecededOrSucceededByQuestionMarkRequireMinimumNumberO matcher.AddIncludePatterns(pattern); var globMatcher = matcher.Build(); var match = globMatcher.Match(input); - Assert.Equal(expectedMatchResult, match.IsMatch); + Assert.AreEqual(expectedMatchResult, match.IsMatch); if (expectedMatchResult) { - Assert.Equal(pattern, match.Pattern); - Assert.Equal(input, match.Stem); + Assert.AreEqual(pattern, match.Pattern); + Assert.AreEqual(input, match.Stem); } else { - Assert.Null(match.Pattern); - Assert.Null(match.Stem); + Assert.IsNull(match.Pattern); + Assert.IsNull(match.Stem); } } - [Fact] + [TestMethod] public void CanMatchWildCard() { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns("*"); var globMatcher = matcher.Build(); var match = globMatcher.Match("a"); - Assert.True(match.IsMatch); - Assert.Equal("*", match.Pattern); - Assert.Equal("a", match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("*", match.Pattern); + Assert.AreEqual("a", match.Stem); } - [Fact] + [TestMethod] public void CanMatchWildCardAtTheBeginning() { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns("*/a"); var globMatcher = matcher.Build(); var match = globMatcher.Match("c/a"); - Assert.True(match.IsMatch); - Assert.Equal("*/a", match.Pattern); - Assert.Equal("a", match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("*/a", match.Pattern); + Assert.AreEqual("a", match.Stem); } - [Fact] + [TestMethod] public void CanMatchWildCardAtTheEnd() { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns("a/*"); var globMatcher = matcher.Build(); var match = globMatcher.Match("a/c"); - Assert.True(match.IsMatch); - Assert.Equal("a/*", match.Pattern); - Assert.Equal("c", match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("a/*", match.Pattern); + Assert.AreEqual("c", match.Stem); } - [Fact] + [TestMethod] public void CanMatchWildCardInMiddle() { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns("a/*/c"); var globMatcher = matcher.Build(); var match = globMatcher.Match("a/b/c"); - Assert.True(match.IsMatch); - Assert.Equal("a/*/c", match.Pattern); - Assert.Equal("c", match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("a/*/c", match.Pattern); + Assert.AreEqual("c", match.Stem); } - [Fact] + [TestMethod] public void CanMatchRecursiveWildCard() { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns("**"); var globMatcher = matcher.Build(); var match = globMatcher.Match("a/b/c"); - Assert.True(match.IsMatch); - Assert.Equal("**", match.Pattern); - Assert.Equal("a/b/c", match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("**", match.Pattern); + Assert.AreEqual("a/b/c", match.Stem); } - [Fact] + [TestMethod] public void CanMatchRecursiveWildCardAtTheBeginning() { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns("**/a"); var globMatcher = matcher.Build(); var match = globMatcher.Match("c/b/a"); - Assert.True(match.IsMatch); - Assert.Equal("**/a", match.Pattern); - Assert.Equal("c/b/a", match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("**/a", match.Pattern); + Assert.AreEqual("c/b/a", match.Stem); } - [Fact] + [TestMethod] public void CanMatchRecursiveWildCardAtTheEnd() { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns("a/**"); var globMatcher = matcher.Build(); var match = globMatcher.Match("a/b/c"); - Assert.True(match.IsMatch); - Assert.Equal("a/**", match.Pattern); - Assert.Equal("b/c", match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("a/**", match.Pattern); + Assert.AreEqual("b/c", match.Stem); } - [Fact] + [TestMethod] public void CanMatchRecursiveWildCardInMiddle() { var matcher = new StaticWebAssetGlobMatcherBuilder(); matcher.AddIncludePatterns("a/**/c"); var globMatcher = matcher.Build(); var match = globMatcher.Match("a/b/c"); - Assert.True(match.IsMatch); - Assert.Equal("a/**/c", match.Pattern); - Assert.Equal("b/c", match.Stem); + Assert.IsTrue(match.IsMatch); + Assert.AreEqual("a/**/c", match.Pattern); + Assert.AreEqual("b/c", match.Stem); } } diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/MergeConfigurationPropertiesMultiThreadingTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/MergeConfigurationPropertiesMultiThreadingTest.cs index 4e7872590751..e5b9ef277e71 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/MergeConfigurationPropertiesMultiThreadingTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/MergeConfigurationPropertiesMultiThreadingTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -14,9 +20,11 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; // [assembly:CollectionBehavior(DisableTestParallelization = true)] in // LegacyStaticWebAssetsV1IntegrationTest.cs, which already isolates the // process-CWD mutation this test performs. +[DoNotParallelize] +[TestClass] public class MergeConfigurationPropertiesMultiThreadingTest { - [Fact] + [TestMethod] public void ResolvesProjectReferencePathRelativeToTaskEnvironmentProjectDirectory_NotProcessCurrentDirectory() { // Scope of this test: verify that the *ProjectReferences* side of the path-equality check diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/MergeConfigurationPropertiesTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/MergeConfigurationPropertiesTest.cs index a19ca4bd7a1c..039c9593ef5e 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/MergeConfigurationPropertiesTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/MergeConfigurationPropertiesTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -10,9 +16,10 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { + [TestClass] public class MergeConfigurationPropertiesTest { - [Fact] + [TestMethod] public void MergesProjectConfigurationWithProjectReferenceWhenMatchingReferenceFound() { var errorMessages = new List(); @@ -51,7 +58,7 @@ public void MergesProjectConfigurationWithProjectReferenceWhenMatchingReferenceF config.GetMetadata("AdditionalPublishPropertiesToRemove").Should().Be("TargetFramework;RuntimeIdentifier"); } - [Fact] + [TestMethod] public void MergesProjectConfigurationWithProjectReference_UsesOSCasingForMatching() { var errorMessages = new List(); @@ -80,7 +87,7 @@ public void MergesProjectConfigurationWithProjectReference_UsesOSCasingForMatchi result.Should().Be(OperatingSystem.IsWindows()); } - [Fact] + [TestMethod] public void FailswhenProjectReferenceNotFound() { var errorMessages = new List(); @@ -103,7 +110,7 @@ public void FailswhenProjectReferenceNotFound() result.Should().Be(false); } - [Fact] + [TestMethod] public void MergesProjectConfigurationRespectsSetTargetFramework() { var errorMessages = new List(); @@ -142,7 +149,7 @@ public void MergesProjectConfigurationRespectsSetTargetFramework() config.GetMetadata("AdditionalPublishPropertiesToRemove").Should().Be(""); } - [Fact] + [TestMethod] public void MergesProjectConfigurationRespectsSetPlatform() { var errorMessages = new List(); @@ -181,7 +188,7 @@ public void MergesProjectConfigurationRespectsSetPlatform() config.GetMetadata("AdditionalPublishPropertiesToRemove").Should().Be(""); } - [Fact] + [TestMethod] public void MergesProjectConfigurationRespectsSetConfiguration() { var errorMessages = new List(); @@ -220,7 +227,7 @@ public void MergesProjectConfigurationRespectsSetConfiguration() config.GetMetadata("AdditionalPublishPropertiesToRemove").Should().Be(""); } - [Fact] + [TestMethod] public void MergesProjectConfigurationRespectsGlobalPropertiesToRemove() { var errorMessages = new List(); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/OverrideHtmlAssetPlaceholdersTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/OverrideHtmlAssetPlaceholdersTest.cs index 31e709b85f12..ae436c29563f 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/OverrideHtmlAssetPlaceholdersTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/OverrideHtmlAssetPlaceholdersTest.cs @@ -1,24 +1,32 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using System.Text.RegularExpressions; namespace Microsoft.AspNetCore.Razor.Tasks; +[TestClass] + public class OverrideHtmlAssetPlaceholdersTest { - [Theory] - [InlineData( + [TestMethod] + [DataRow( """ """, true, "main.js" )] - [InlineData( + [DataRow( """ @@ -26,66 +34,66 @@ public class OverrideHtmlAssetPlaceholdersTest true, "main.js" )] - [InlineData( + [DataRow( """ """, true, "main.js" )] - [InlineData( + [DataRow( """ """, true, "./main.js" )] - [InlineData( + [DataRow( """ """, true, "./folder/folder/file.name.something.js" )] - [InlineData( + [DataRow( """ """, true, "main.suffix.js" )] - [InlineData( + [DataRow( """ """, true, "/root/main.suffix.js" )] - [InlineData( + [DataRow( """ """, false )] - [InlineData( + [DataRow( """ """, false )] - [InlineData( + [DataRow( """ """, false )] - [InlineData( + [DataRow( """

main#[.{fingerprint}].js

""", false )] - [InlineData( + [DataRow( """ """, true )] - [InlineData( + [DataRow( """ """, true )] - [InlineData( + [DataRow( """ """, true )] - [InlineData( + [DataRow( """ """, false )] - [InlineData( + [DataRow( """ """, @@ -177,97 +185,97 @@ public void ValidateAssetsRegex(string input, bool shouldMatch, string fileName )] public void ValidateImportMapRegex(string input, bool shouldMatch) { - Assert.Equal(shouldMatch, OverrideHtmlAssetPlaceholders._importMapRegex.Match(input).Success); + Assert.AreEqual(shouldMatch, OverrideHtmlAssetPlaceholders._importMapRegex.Match(input).Success); } - [Theory] - [InlineData( + [TestMethod] + [DataRow( """ """, true )] - [InlineData( + [DataRow( """ """, true )] - [InlineData( + [DataRow( """ """, true )] - [InlineData( + [DataRow( """ """, false )] - [InlineData( + [DataRow( """ """, false )] - [InlineData( + [DataRow( """ " """, false )] - [InlineData( + [DataRow( """ " """, false )] - [InlineData( + [DataRow( """ """, false )] - [InlineData( + [DataRow( """ """, true, "webassembly" )] - [InlineData( + [DataRow( """ """, true, "webassembly" )] - [InlineData( + [DataRow( """ """, false )] - [InlineData( + [DataRow( """ """, false )] - [InlineData( + [DataRow( """ """, false )] - [InlineData( + [DataRow( """ m.Contains("Unsupported package manifest version")); } - [Fact] + [TestMethod] public void MissingIntermediateOutputPath_ProducesError() { var packageRoot = SetupPackageRoot("MyLib", @@ -421,7 +429,7 @@ private static KeyValuePair CreateManifestAsset( // A package author disables the auto-generated .targets and manually provides // their own .targets that still registers a StaticWebAssetPackageManifest item. // The consumer's ReadPackageAssetsManifest should still work correctly. - [Fact] + [TestMethod] public void CustomTargetsOverride_ManualManifestItem_WorksCorrectly() { // Setup: simulate a package that has its manifest at a custom location @@ -449,7 +457,7 @@ public void CustomTargetsOverride_ManualManifestItem_WorksCorrectly() // Scenario 7: Multiple packages contributing manifests to the same consumer // Two packages each provide a StaticWebAssetPackageManifest item. // Group filtering should be applied independently per SourceId. - [Fact] + [TestMethod] public void MultiplePackages_IndependentGroupFilteringPerSourceId() { // Package A: has grouped assets (BootstrapVersion=V5) diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ReadStaticWebAssetsManifestFileMultiThreadingTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ReadStaticWebAssetsManifestFileMultiThreadingTest.cs index 3aaec445d111..d70c21a38790 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ReadStaticWebAssetsManifestFileMultiThreadingTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ReadStaticWebAssetsManifestFileMultiThreadingTest.cs @@ -9,13 +9,13 @@ namespace Microsoft.AspNetCore.Razor.Tasks; -// Test parallelization is disabled assembly-wide via -// [assembly:CollectionBehavior(DisableTestParallelization = true)] in -// LegacyStaticWebAssetsV1IntegrationTest.cs, which already isolates the -// process-CWD mutation this test performs. +// This test mutates the process-wide current directory, so it must not run +// concurrently with other tests under MSTest's method-level parallelization. +[DoNotParallelize] +[TestClass] public class ReadStaticWebAssetsManifestFileMultiThreadingTest { - [Fact] + [TestMethod] public void ReadsManifestRelativeToTaskEnvironmentProjectDirectory() { var testRoot = Path.Combine(AppContext.BaseDirectory, nameof(ReadStaticWebAssetsManifestFileMultiThreadingTest), Guid.NewGuid().ToString("N")); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ReadStaticWebAssetsManifestFileTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ReadStaticWebAssetsManifestFileTest.cs index b2294e9bf571..3945e8d2486e 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ReadStaticWebAssetsManifestFileTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ReadStaticWebAssetsManifestFileTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Text.Json; using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; @@ -10,6 +16,7 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { + [TestClass] public class ReadStaticWebAssetsManifestFileTest { public ReadStaticWebAssetsManifestFileTest() @@ -20,7 +27,7 @@ public ReadStaticWebAssetsManifestFileTest() public string TempFilePath { get; } - [Fact] + [TestMethod] public void CanReadManifestWithoutProperties() { var errorMessages = new List(); @@ -48,7 +55,7 @@ public void CanReadManifestWithoutProperties() task.ReferencedProjectsConfiguration.Should().BeEmpty(); } - [Fact] + [TestMethod] public void CanReadEmptyManifest() { var errorMessages = new List(); @@ -87,7 +94,7 @@ public void CanReadEmptyManifest() task.ReferencedProjectsConfiguration.Should().BeEmpty(); } - [Fact] + [TestMethod] public void ConvertsAssetsToTaskItems() { var errorMessages = new List(); @@ -202,7 +209,7 @@ public void ConvertsAssetsToTaskItems() .BeEquivalentTo("""[{"Name":"Content-Length","Value":"__content-length__"},{"Name":"Content-Type","Value":"text/css"},{"Name":"ETag","Value":"__etag__"},{"Name":"Last-Modified","Value":"__last-modified__"}]"""); } - [Fact] + [TestMethod] public void ConvertsReferencedProjectsConfigurationsToTaskItems() { var errorMessages = new List(); @@ -266,7 +273,7 @@ public void ConvertsReferencedProjectsConfigurationsToTaskItems() projectConfiguration.GetMetadata(nameof(StaticWebAssetsManifest.ReferencedProjectConfiguration.AdditionalBuildPropertiesToRemove)).Should().BeEquivalentTo(";WebPublishProfileFile"); } - [Fact] + [TestMethod] public void ConvertsDiscoveryPatternsToTaskItems() { var errorMessages = new List(); @@ -322,7 +329,7 @@ public void ConvertsDiscoveryPatternsToTaskItems() discoveryPattern.GetMetadata(nameof(StaticWebAssetsDiscoveryPattern.Pattern)).Should().BeEquivalentTo("**"); } - [Fact] + [TestMethod] public void ReturnsErrorwhenManifestDoesNotExist() { var errorMessages = new List(); @@ -348,7 +355,7 @@ public void ReturnsErrorwhenManifestDoesNotExist() task.ReferencedProjectsConfiguration.Should().BeNull(); } - [Fact] + [TestMethod] public void ReturnsErrorWhenManifestPathIsEmpty() { var errorMessages = new List(); @@ -375,7 +382,7 @@ public void ReturnsErrorWhenManifestPathIsEmpty() task.ReferencedProjectsConfiguration.Should().BeNull(); } - [Fact] + [TestMethod] public void ReturnsErrorwhenManifestIsMalformed() { var errorMessages = new List(); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ResolveAllScopedCssAssetsTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ResolveAllScopedCssAssetsTest.cs index f6261ae15561..ed251ae21631 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ResolveAllScopedCssAssetsTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ResolveAllScopedCssAssetsTest.cs @@ -1,14 +1,21 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.AspNetCore.StaticWebAssets.Tasks; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; using Microsoft.Build.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace Microsoft.NET.Sdk.Razor.Test { + [TestClass] public class ResolveAllScopedCssAssetsTest { - [Fact] + [TestMethod] public void ResolveAllScopedCssAssets_IgnoresRegularCssFiles() { // Arrange @@ -36,7 +43,7 @@ public void ResolveAllScopedCssAssets_IgnoresRegularCssFiles() taskInstance.ScopedCssAssets.Should().NotContain(scopedCssAsset => scopedCssAsset.ItemSpec == "site.css"); } - [Fact] + [TestMethod] public void ResolveAllScopedCssAssets_DetectsScopedCssFiles() { // Arrange @@ -64,7 +71,7 @@ public void ResolveAllScopedCssAssets_DetectsScopedCssFiles() taskInstance.ScopedCssAssets.Should().Contain(scopedCssAsset => scopedCssAsset.ItemSpec == "TestFiles/Pages/Counter.razor.rz.scp.css"); } - [Fact] + [TestMethod] public void ResolveAllScopedCssAssets_DetectsScopedCssProjectBundleFiles() { // Arrange @@ -92,7 +99,7 @@ public void ResolveAllScopedCssAssets_DetectsScopedCssProjectBundleFiles() taskInstance.ScopedCssProjectBundles.Should().Contain(scopedCssBundle => scopedCssBundle.ItemSpec == "Folder/Project.bundle.scp.css"); } - [Fact] + [TestMethod] public void ResolveAllScopedCssAssets_IgnoresScopedCssApplicationBundleFiles() { // Arrange diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ResolveCompressedAssetsTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ResolveCompressedAssetsTest.cs index f35921164312..33dc00d201c4 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ResolveCompressedAssetsTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ResolveCompressedAssetsTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Diagnostics.Metrics; using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; @@ -13,6 +19,8 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; +[TestClass] + public class ResolveCompressedAssetsTest { private readonly List _errorMessages; @@ -35,7 +43,7 @@ public ResolveCompressedAssetsTest() .Callback(args => _errorMessages.Add(args.Message)); } - [Fact] + [TestMethod] public void ResolvesExplicitlyProvidedAssets() { // Arrange @@ -63,7 +71,7 @@ public void ResolvesExplicitlyProvidedAssets() task.AssetsToCompress[1].ItemSpec.Should().EndWith(".br"); } - [Fact] + [TestMethod] public void InfersPreCompressedAssetsCorrectly() { @@ -131,7 +139,7 @@ public void InfersPreCompressedAssetsCorrectly() task.AssetsToCompress.TakeWhile(a => a != null).Should().HaveCount(0); } - [Fact] + [TestMethod] public void ResolvesAssetsMatchingIncludePattern() { // Arrange @@ -156,7 +164,7 @@ public void ResolvesAssetsMatchingIncludePattern() task.AssetsToCompress[1].ItemSpec.Should().EndWith(".br"); } - [Fact] + [TestMethod] public void ResolvesAssets_WithFingerprint_MatchingIncludePattern() { // Arrange @@ -194,7 +202,7 @@ public void ResolvesAssets_WithFingerprint_MatchingIncludePattern() relativePath.Should().EndWith("#[.{fingerprint=v1}]"); } - [Fact] + [TestMethod] public void ExcludesAssetsMatchingExcludePattern() { // Arrange @@ -218,7 +226,7 @@ public void ExcludesAssetsMatchingExcludePattern() task.AssetsToCompress.Should().HaveCount(0); } - [Fact] + [TestMethod] public void DeduplicatesAssetsResolvedBothExplicitlyAndFromPattern() { // Arrange @@ -247,9 +255,9 @@ public void DeduplicatesAssetsResolvedBothExplicitlyAndFromPattern() buildTask.AssetsToCompress[1].ItemSpec.Should().EndWith(".br"); } - [Theory] - [InlineData("gzip", ".gz", "brotli", ".br")] - [InlineData("brotli", ".br", "gzip", ".gz")] + [TestMethod] + [DataRow("gzip", ".gz", "brotli", ".br")] + [DataRow("brotli", ".br", "gzip", ".gz")] public void IgnoresAssetsCompressedInPreviousTaskRun( string phase1Format, string phase1Ext, string _, string phase2Ext) { @@ -295,7 +303,7 @@ public void IgnoresAssetsCompressedInPreviousTaskRun( task2.AssetsToCompress[0].ItemSpec.Should().EndWith(phase2Ext); } - [Fact] + [TestMethod] public void ProducesDistinctIdentities_ForGroupVariantsWithIdenticalContent() { // Arrange — two assets that differ only in AssetGroups but have the same diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ResolveFingerprintedStaticWebAssetEndpointsForAssetsTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ResolveFingerprintedStaticWebAssetEndpointsForAssetsTest.cs index a27049b45841..4917cdabb5d9 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ResolveFingerprintedStaticWebAssetEndpointsForAssetsTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ResolveFingerprintedStaticWebAssetEndpointsForAssetsTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -10,11 +16,13 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests.StaticWebAssets; +[TestClass] + public class ResolveFingerprintedStaticWebAssetEndpointsForAssetsTest { - [Theory] - [InlineData("candidate#[.{fingerprint}]?.js", "candidate.js")] - [InlineData("candidate#[.{fingerprint}]!.js", "candidate.asdf1234.js")] + [TestMethod] + [DataRow("candidate#[.{fingerprint}]?.js", "candidate.js")] + [DataRow("candidate#[.{fingerprint}]!.js", "candidate.asdf1234.js")] public void Standalone_Selects_EndpointMatching_FilePath(string pattern, string expectedRoute) { var now = DateTime.Now; @@ -57,7 +65,7 @@ public void Standalone_Selects_EndpointMatching_FilePath(string pattern, string endpoint.Route.Should().Be(expectedRoute); } - [Fact] + [TestMethod] public void StandaloneFails_MatchingEndpointNotFound() { var now = DateTime.Now; @@ -95,9 +103,9 @@ public void StandaloneFails_MatchingEndpointNotFound() result.Should().BeFalse(); } - [Theory] - [InlineData("candidate#[.{fingerprint}]?.js", "candidate.asdf1234.js")] - [InlineData("candidate#[.{fingerprint}]!.js", "candidate.asdf1234.js")] + [TestMethod] + [DataRow("candidate#[.{fingerprint}]?.js", "candidate.asdf1234.js")] + [DataRow("candidate#[.{fingerprint}]!.js", "candidate.asdf1234.js")] public void Hosted_AlwaysPrefers_FingerprintedEndpoint(string pattern, string expectedRoute) { var now = DateTime.Now; @@ -140,7 +148,7 @@ public void Hosted_AlwaysPrefers_FingerprintedEndpoint(string pattern, string ex endpoint.Route.Should().Be(expectedRoute); } - [Fact] + [TestMethod] public void Hosted_FallsBackToNonFingerprintedEndpoint_WhenFingerprintedVersionNotAvailable() { var now = DateTime.Now; @@ -183,7 +191,7 @@ public void Hosted_FallsBackToNonFingerprintedEndpoint_WhenFingerprintedVersionN endpoint.Route.Should().Be("candidate.js"); } - [Fact] + [TestMethod] public void Hosted_FailsWhen_DoesnotFindMatchingEndpoint() { var now = DateTime.Now; diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/RewriteCssTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/RewriteCssTest.cs index 3665a85814bc..49654b5d7ab5 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/RewriteCssTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/RewriteCssTest.cs @@ -1,24 +1,32 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.AspNetCore.StaticWebAssets.Tasks; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; +[TestClass] + public class RewriteCssTest { - [Fact] + [TestMethod] public void HandlesEmptyFile() { // Arrange/act var result = RewriteCss.AddScopeToSelectors("file.css", string.Empty, "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(string.Empty, result); + Assert.IsEmpty(errors); + Assert.AreEqual(string.Empty, result); } - [Fact] + [TestMethod] public void AddsScopeAfterSelector() { // Arrange/act @@ -27,13 +35,13 @@ public void AddsScopeAfterSelector() ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" .myclass[TestScope] { color: red; } ", result); } - [Fact] + [TestMethod] public void HandlesMultipleSelectors() { // Arrange/act @@ -46,8 +54,8 @@ public void HandlesMultipleSelectors() ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" .first[TestScope], .second[TestScope] { color: red; } .third[TestScope] { color: blue; } :root[TestScope] { color: green; } @@ -56,7 +64,7 @@ public void HandlesMultipleSelectors() ", result); } - [Fact] + [TestMethod] public void HandlesComplexSelectors() { // Arrange/act @@ -65,13 +73,13 @@ public void HandlesComplexSelectors() ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" .first div > li[TestScope], body .second:not(.fancy)[attr~=whatever][TestScope] { color: red; } ", result); } - [Fact] + [TestMethod] public void HandlesSpacesAndCommentsWithinSelectors() { // Arrange/act @@ -80,13 +88,13 @@ public void HandlesSpacesAndCommentsWithinSelectors() ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" .first /* space at end {} */ div[TestScope] , .myclass[TestScope] /* comment at end */ { color: red; } ", result); } - [Fact] + [TestMethod] public void HandlesPseudoClasses() { // Arrange/act @@ -100,8 +108,8 @@ public void HandlesPseudoClasses() ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" a:fake-pseudo-class[TestScope] { color: red; } a:focus b:hover[TestScope] { color: green; } tr:nth-child(4n + 1)[TestScope] { color: blue; } @@ -111,7 +119,7 @@ public void HandlesPseudoClasses() ", result); } - [Fact] + [TestMethod] public void HandlesPseudoElements() { // Arrange/act @@ -126,8 +134,8 @@ public void HandlesPseudoElements() ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" a[TestScope]::before { content: ""✋""; } a[TestScope]::after::placeholder { content: ""🐯""; } custom-element[TestScope]::part(foo) { content: ""🤷‍""; } @@ -138,7 +146,7 @@ public void HandlesPseudoElements() ", result); } - [Fact] + [TestMethod] public void HandlesSingleColonPseudoElements() { // Arrange/act @@ -152,8 +160,8 @@ public void HandlesSingleColonPseudoElements() ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" a[TestScope]:after { content: ""x""; } a[TestScope]:before { content: ""x""; } a[TestScope]:first-letter { content: ""x""; } @@ -163,7 +171,7 @@ public void HandlesSingleColonPseudoElements() ", result); } - [Fact] + [TestMethod] public void RespectsDeepCombinator() { // Arrange/act @@ -173,14 +181,14 @@ public void RespectsDeepCombinator() ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" .first[TestScope] .second { color: red; } a[TestScope] b, c[TestScope] d { color: blue; } ", result); } - [Fact] + [TestMethod] public void RespectsDeepCombinatorWithDirectDescendant() { // Arrange/act @@ -190,14 +198,14 @@ public void RespectsDeepCombinatorWithDirectDescendant() ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" a[TestScope] > b { color: red; } c[TestScope] > d { color: blue; } ", result); } - [Fact] + [TestMethod] public void RespectsDeepCombinatorWithAdjacentSibling() { // Arrange/act @@ -207,14 +215,14 @@ public void RespectsDeepCombinatorWithAdjacentSibling() ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" a[TestScope] + b { color: red; } c[TestScope] + d { color: blue; } ", result); } - [Fact] + [TestMethod] public void RespectsDeepCombinatorWithGeneralSibling() { // Arrange/act @@ -224,14 +232,14 @@ public void RespectsDeepCombinatorWithGeneralSibling() ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" a[TestScope] ~ b { color: red; } c[TestScope] ~ d { color: blue; } ", result); } - [Fact] + [TestMethod] public void IgnoresMultipleDeepCombinators() { // Arrange/act @@ -240,13 +248,13 @@ public void IgnoresMultipleDeepCombinators() ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" .first[TestScope] .second ::deep .third { color:red; } ", result); } - [Fact] + [TestMethod] public void RespectsDeepCombinatorWithSpacesAndComments() { // Arrange/act @@ -257,15 +265,15 @@ public void RespectsDeepCombinatorWithSpacesAndComments() ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" .a .b[TestScope] /* comment ::deep 1 */ /* comment ::deep 2 */ .c /* ::deep */ .d { color: red; } [TestScope] * { color: blue; } /* Leading deep combinator */ another[TestScope] { color: green } /* Trailing deep combinator */ ", result); } - [Fact] + [TestMethod] public void HandlesAtBlocks() { // Arrange/act @@ -280,8 +288,8 @@ .another .thing { ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" .myclass[TestScope] { color: red; } @media only screen and (max-width: 600px) { @@ -292,7 +300,7 @@ .another .thing[TestScope] { ", result); } - [Fact] + [TestMethod] public void AddsScopeToKeyframeNames() { // Arrange/act @@ -301,13 +309,13 @@ @keyframes my-animation { /* whatever */ } ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" @keyframes my-animation-TestScope { /* whatever */ } ", result); } - [Fact] + [TestMethod] public void RewritesAnimationNamesWhenMatchingKnownKeyframes() { // Arrange/act @@ -327,8 +335,8 @@ @keyframes unused-animation { /* whatever */ } ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" .myclass[TestScope] { color: red; animation: /* ignore comment */ my-animation-TestScope 1s infinite; @@ -344,7 +352,7 @@ @keyframes unused-animation-TestScope { /* whatever */ } ", result); } - [Fact] + [TestMethod] public void RewritesMultipleAnimationNames() { // Arrange/act @@ -356,8 +364,8 @@ @keyframes different-animation { } ", "TestScope", out var errors); // Assert - Assert.Empty(errors); - Assert.Equal(@" + Assert.IsEmpty(errors); + Assert.AreEqual(@" .myclass1[TestScope] { animation-name: my-animation-TestScope , different-animation-TestScope } .myclass2[TestScope] { animation: 4s linear 0s alternate my-animation-TestScope infinite, different-animation-TestScope 0s } @keyframes my-animation-TestScope { } @@ -365,7 +373,7 @@ @keyframes different-animation-TestScope { } ", result); } - [Fact] + [TestMethod] public void RejectsImportStatements() { // Arrange/act @@ -380,10 +388,11 @@ public void RejectsImportStatements() ", "TestScope", out var errors); // Assert - Assert.Collection(errors, - error => Assert.Equal("file.css(2,5): @import rules are not supported within scoped CSS files because the loading order would be undefined. @import may only be placed in non-scoped CSS files.", error.ToString()), - error => Assert.Equal("file.css(3,5): @import rules are not supported within scoped CSS files because the loading order would be undefined. @import may only be placed in non-scoped CSS files.", error.ToString()), - error => Assert.Equal("file.css(4,5): @import rules are not supported within scoped CSS files because the loading order would be undefined. @import may only be placed in non-scoped CSS files.", error.ToString()), - error => Assert.Equal("file.css(5,5): @import rules are not supported within scoped CSS files because the loading order would be undefined. @import may only be placed in non-scoped CSS files.", error.ToString())); + var errorList = errors.ToList(); + Assert.HasCount(4, errorList); + Assert.AreEqual("file.css(2,5): @import rules are not supported within scoped CSS files because the loading order would be undefined. @import may only be placed in non-scoped CSS files.", errorList[0].ToString()); + Assert.AreEqual("file.css(3,5): @import rules are not supported within scoped CSS files because the loading order would be undefined. @import may only be placed in non-scoped CSS files.", errorList[1].ToString()); + Assert.AreEqual("file.css(4,5): @import rules are not supported within scoped CSS files because the loading order would be undefined. @import may only be placed in non-scoped CSS files.", errorList[2].ToString()); + Assert.AreEqual("file.css(5,5): @import rules are not supported within scoped CSS files because the loading order would be undefined. @import may only be placed in non-scoped CSS files.", errorList[3].ToString()); } } diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetEndpointTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetEndpointTest.cs index 9b5178f5a2b3..13303ee2adc7 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetEndpointTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetEndpointTest.cs @@ -1,25 +1,33 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; +[TestClass] + public class StaticWebAssetEndpointTest { - [Theory] - [InlineData("App1/css/app.css", "App1")] - [InlineData("App1", "App1")] - [InlineData("App1/css/styles/app.css", "App1/css")] - [InlineData("App1/css/app.css", "")] - [InlineData("", "")] - [InlineData("App1\\css\\app.css", "App1")] - [InlineData("App1/css\\app.css", "App1")] - [InlineData("App1/App1.lib.module.js", "App1")] - [InlineData("app1/css/app.css", "App1")] - [InlineData("APP1/css/app.css", "app1")] + [TestMethod] + [DataRow("App1/css/app.css", "App1")] + [DataRow("App1", "App1")] + [DataRow("App1/css/styles/app.css", "App1/css")] + [DataRow("App1/css/app.css", "")] + [DataRow("", "")] + [DataRow("App1\\css\\app.css", "App1")] + [DataRow("App1/css\\app.css", "App1")] + [DataRow("App1/App1.lib.module.js", "App1")] + [DataRow("app1/css/app.css", "App1")] + [DataRow("APP1/css/app.css", "app1")] public void RouteHasPathPrefix_ReturnsTrue_WhenRouteStartsWithPrefixAsPathSegment(string route, string prefix) { var routeSegments = new List(); @@ -30,13 +38,13 @@ public void RouteHasPathPrefix_ReturnsTrue_WhenRouteStartsWithPrefixAsPathSegmen result.Should().BeTrue(); } - [Theory] - [InlineData("App1.styles.css", "App1")] - [InlineData("App1", "App1/css/app.css")] - [InlineData("App1/js/app.js", "App1/css")] - [InlineData("App12/css/app.css", "App1")] - [InlineData("App1Bundle/app.js", "App1")] - [InlineData("App1.lib.module.js", "App1")] + [TestMethod] + [DataRow("App1.styles.css", "App1")] + [DataRow("App1", "App1/css/app.css")] + [DataRow("App1/js/app.js", "App1/css")] + [DataRow("App12/css/app.css", "App1")] + [DataRow("App1Bundle/app.js", "App1")] + [DataRow("App1.lib.module.js", "App1")] public void RouteHasPathPrefix_ReturnsFalse_WhenRouteDoesNotStartWithPrefixAsPathSegment(string route, string prefix) { var routeSegments = new List(); @@ -47,7 +55,7 @@ public void RouteHasPathPrefix_ReturnsFalse_WhenRouteDoesNotStartWithPrefixAsPat result.Should().BeFalse(); } - [Fact] + [TestMethod] public void RouteHasPathPrefix_ReusesSegmentLists() { var routeSegments = new List(); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetEndpointToAssetFileDictionaryTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetEndpointToAssetFileDictionaryTest.cs index c02e62162cda..ed5b730795e1 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetEndpointToAssetFileDictionaryTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetEndpointToAssetFileDictionaryTest.cs @@ -9,6 +9,7 @@ namespace Microsoft.AspNetCore.StaticWebAssets.Tasks; +[TestClass] public class StaticWebAssetEndpointToAssetFileDictionaryTest { // ToAssetFileDictionary keys are absolute filesystem paths (endpoint.AssetFile, typically @@ -22,7 +23,8 @@ public class StaticWebAssetEndpointToAssetFileDictionaryTest // This test is Windows-only because OSPath.PathComparer is OrdinalIgnoreCase only on // Windows; on Linux/macOS it is StringComparer.Ordinal (matching the case-sensitive // filesystem), which is observationally identical to the default Dictionary comparer. - [PlatformSpecificFact(TestPlatforms.Windows)] + [TestMethod] + [OSCondition(OperatingSystems.Windows)] public void GroupsEndpoints_ByPath_CaseInsensitively_OnWindows() { var upperCased = MakeEndpointItem("C:\\Repo\\WWWRoot\\site.css", "/_content/lib/site.css"); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetPathPatternTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetPathPatternTest.cs index 2f0033ac99b5..12bdc5ed121f 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetPathPatternTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetPathPatternTest.cs @@ -1,16 +1,24 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Globalization; using Microsoft.AspNetCore.StaticWebAssets.Tasks; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests.StaticWebAssets; +[TestClass] + public class StaticWebAssetPathPatternTest { - [Fact] + [TestMethod] public void CanParse_PathWithNoExpressions() { var pattern = StaticWebAssetPathPattern.Parse("css/site.css", "MyApp"); @@ -21,10 +29,10 @@ public void CanParse_PathWithNoExpressions() new (){ Parts = [ new() { Name = "css/site.css".AsMemory(), IsLiteral = true }] } ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_ComplexFingerprintExpression_Middle() { var pattern = StaticWebAssetPathPattern.Parse("css/site#[.{fingerprint}].css", "MyApp"); @@ -38,10 +46,10 @@ public void CanParse_ComplexFingerprintExpression_Middle() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_ComplexFingerprintExpression_Start() { var pattern = StaticWebAssetPathPattern.Parse("#[.{fingerprint}].css", "MyApp"); @@ -54,10 +62,10 @@ public void CanParse_ComplexFingerprintExpression_Start() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_ComplexFingerprintExpression_End() { var pattern = StaticWebAssetPathPattern.Parse("site#[.{fingerprint}]", "MyApp"); @@ -70,10 +78,10 @@ public void CanParse_ComplexFingerprintExpression_End() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_ComplexFingerprintExpression_Only() { var pattern = StaticWebAssetPathPattern.Parse("#[.{fingerprint}]", "MyApp"); @@ -85,10 +93,10 @@ public void CanParse_ComplexFingerprintExpression_Only() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_ComplexFingerprintExpression_Multiple() { var pattern = StaticWebAssetPathPattern.Parse("css/site#[.{fingerprint}]-#[.{version}].css", "MyApp"); @@ -104,10 +112,10 @@ public void CanParse_ComplexFingerprintExpression_Multiple() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_ComplexFingerprintExpression_ConsecutiveExpressions() { var pattern = StaticWebAssetPathPattern.Parse("css/site#[.{fingerprint}]#[.{version}].css", "MyApp"); @@ -122,10 +130,10 @@ public void CanParse_ComplexFingerprintExpression_ConsecutiveExpressions() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_SimpleFingerprintExpression_Start() { var pattern = StaticWebAssetPathPattern.Parse("#[{fingerprint}].css", "MyApp"); @@ -138,10 +146,10 @@ public void CanParse_SimpleFingerprintExpression_Start() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_SimpleFingerprintExpression_Middle() { var pattern = StaticWebAssetPathPattern.Parse("css/site#[{fingerprint}].css", "MyApp"); @@ -155,10 +163,10 @@ public void CanParse_SimpleFingerprintExpression_Middle() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_SimpleFingerprintExpression_End() { var pattern = StaticWebAssetPathPattern.Parse("site#[{fingerprint}]", "MyApp"); @@ -171,10 +179,10 @@ public void CanParse_SimpleFingerprintExpression_End() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_SimpleFingerprintExpression_Only() { var pattern = StaticWebAssetPathPattern.Parse("#[{fingerprint}]", "MyApp"); @@ -186,10 +194,10 @@ public void CanParse_SimpleFingerprintExpression_Only() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_SimpleFingerprintExpression_WithEmbeddedValues() { var pattern = StaticWebAssetPathPattern.Parse("#[{fingerprint=value}]", "MyApp"); @@ -201,10 +209,10 @@ public void CanParse_SimpleFingerprintExpression_WithEmbeddedValues() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_ComplexExpression_MultipleVariables() { var pattern = StaticWebAssetPathPattern.Parse("css/site#[.{fingerprint}-{version}].css", "MyApp"); @@ -223,10 +231,10 @@ public void CanParse_ComplexExpression_MultipleVariables() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_ComplexExpression_MultipleConsecutiveVariables() { var pattern = StaticWebAssetPathPattern.Parse("css/site#[.{fingerprint}{version}].css", "MyApp"); @@ -244,10 +252,10 @@ public void CanParse_ComplexExpression_MultipleConsecutiveVariables() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_ComplexExpression_StartsWithVariable() { var pattern = StaticWebAssetPathPattern.Parse("#[{fingerprint}.]css", "MyApp"); @@ -260,10 +268,10 @@ public void CanParse_ComplexExpression_StartsWithVariable() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_OptionalExpressions_End() { var pattern = StaticWebAssetPathPattern.Parse("site#[.{fingerprint}]?", "MyApp"); @@ -276,10 +284,10 @@ public void CanParse_OptionalExpressions_End() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_OptionalPreferredExpressions() { var pattern = StaticWebAssetPathPattern.Parse("site#[.{fingerprint}]!", "MyApp"); @@ -292,10 +300,10 @@ public void CanParse_OptionalPreferredExpressions() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_OptionalExpressions_Start() { var pattern = StaticWebAssetPathPattern.Parse("#[.{fingerprint}]?site", "MyApp"); @@ -308,10 +316,10 @@ public void CanParse_OptionalExpressions_Start() }] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_OptionalExpressions_Middle() { var pattern = StaticWebAssetPathPattern.Parse("site#[.{fingerprint}]?site", "MyApp"); @@ -325,10 +333,10 @@ public void CanParse_OptionalExpressions_Middle() }] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_OptionalExpressions_Only() { var pattern = StaticWebAssetPathPattern.Parse("#[.{fingerprint}]?", "MyApp"); @@ -340,10 +348,10 @@ public void CanParse_OptionalExpressions_Only() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_MultipleOptionalExpressions() { var pattern = StaticWebAssetPathPattern.Parse("#[.{fingerprint}]?site#[.{version}]?", "MyApp"); @@ -357,10 +365,10 @@ public void CanParse_MultipleOptionalExpressions() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanParse_ConsecutiveOptionalExpressions() { var pattern = StaticWebAssetPathPattern.Parse("#[.{fingerprint}]?#[.{version}]?", "MyApp"); @@ -373,10 +381,10 @@ public void CanParse_ConsecutiveOptionalExpressions() ] }; - Assert.Equal(expected, pattern); + Assert.AreEqual(expected, pattern); } - [Fact] + [TestMethod] public void CanReplaceTokens_PathWithNoExpressions() { var pattern = StaticWebAssetPathPattern.Parse("css/site.css", "MyApp"); @@ -386,10 +394,10 @@ public void CanReplaceTokens_PathWithNoExpressions() }; var (path, _) = pattern.ReplaceTokens(tokens, CreateTestResolver()); - Assert.Equal("css/site.css", path); + Assert.AreEqual("css/site.css", path); } - [Fact] + [TestMethod] public void CanReplaceTokens_ComplexFingerprintExpression_Middle() { var pattern = StaticWebAssetPathPattern.Parse("css/site#[.{fingerprint}].css", "MyApp"); @@ -399,10 +407,10 @@ public void CanReplaceTokens_ComplexFingerprintExpression_Middle() }; var (path, _) = pattern.ReplaceTokens(tokens, CreateTestResolver()); - Assert.Equal("css/site.asdf1234.css", path); + Assert.AreEqual("css/site.asdf1234.css", path); } - [Fact] + [TestMethod] public void CanReplaceTokens_ComplexFingerprintExpression_Start() { var pattern = StaticWebAssetPathPattern.Parse("#[.{fingerprint}].css", "MyApp"); @@ -412,10 +420,10 @@ public void CanReplaceTokens_ComplexFingerprintExpression_Start() }; var (path, _) = pattern.ReplaceTokens(tokens, CreateTestResolver()); - Assert.Equal(".asdf1234.css", path); + Assert.AreEqual(".asdf1234.css", path); } - [Fact] + [TestMethod] public void CanReplaceTokens_ComplexFingerprintExpression_End() { var pattern = StaticWebAssetPathPattern.Parse("site#[.{fingerprint}]", "MyApp"); @@ -425,10 +433,10 @@ public void CanReplaceTokens_ComplexFingerprintExpression_End() }; var (path, _) = pattern.ReplaceTokens(tokens, CreateTestResolver()); - Assert.Equal("site.asdf1234", path); + Assert.AreEqual("site.asdf1234", path); } - [Fact] + [TestMethod] public void CanReplaceTokens_ComplexFingerprintExpression_Only() { var pattern = StaticWebAssetPathPattern.Parse("#[.{fingerprint}]", "MyApp"); @@ -438,10 +446,10 @@ public void CanReplaceTokens_ComplexFingerprintExpression_Only() }; var (path, _) = pattern.ReplaceTokens(tokens, CreateTestResolver()); - Assert.Equal(".asdf1234", path); + Assert.AreEqual(".asdf1234", path); } - [Fact] + [TestMethod] public void CanReplaceTokens_ComplexFingerprintExpression_Multiple() { var pattern = StaticWebAssetPathPattern.Parse("css/site#[.{fingerprint}]-#[.{version}].css", "MyApp"); @@ -453,10 +461,10 @@ public void CanReplaceTokens_ComplexFingerprintExpression_Multiple() tokens, CreateTestResolver(new Dictionary(StringComparer.OrdinalIgnoreCase) { ["version"] = "v1" })); - Assert.Equal("css/site.asdf1234-.v1.css", path); + Assert.AreEqual("css/site.asdf1234-.v1.css", path); } - [Fact] + [TestMethod] public void CanReplaceTokens_ComplexFingerprintExpression_ConsecutiveExpressions() { var pattern = StaticWebAssetPathPattern.Parse("css/site#[.{fingerprint}]#[.{version}].css", "MyApp"); @@ -468,10 +476,10 @@ public void CanReplaceTokens_ComplexFingerprintExpression_ConsecutiveExpressions tokens, CreateTestResolver(new Dictionary(StringComparer.OrdinalIgnoreCase) { ["version"] = "v1" })); - Assert.Equal("css/site.asdf1234.v1.css", path); + Assert.AreEqual("css/site.asdf1234.v1.css", path); } - [Fact] + [TestMethod] public void CanReplaceTokens_SimpleFingerprintExpression_Start() { var pattern = StaticWebAssetPathPattern.Parse("#[{fingerprint}].css", "MyApp"); @@ -481,10 +489,10 @@ public void CanReplaceTokens_SimpleFingerprintExpression_Start() }; var (path, _) = pattern.ReplaceTokens(tokens, CreateTestResolver()); - Assert.Equal("asdf1234.css", path); + Assert.AreEqual("asdf1234.css", path); } - [Fact] + [TestMethod] public void CanReplaceTokens_SimpleFingerprintExpression_Middle() { var pattern = StaticWebAssetPathPattern.Parse("css/site#[{fingerprint}].css", "MyApp"); @@ -494,10 +502,10 @@ public void CanReplaceTokens_SimpleFingerprintExpression_Middle() }; var (path, _) = pattern.ReplaceTokens(tokens, CreateTestResolver()); - Assert.Equal("css/siteasdf1234.css", path); + Assert.AreEqual("css/siteasdf1234.css", path); } - [Fact] + [TestMethod] public void CanReplaceTokens_SimpleFingerprintExpression_End() { var pattern = StaticWebAssetPathPattern.Parse("site#[{fingerprint}]", "MyApp"); @@ -507,10 +515,10 @@ public void CanReplaceTokens_SimpleFingerprintExpression_End() }; var (path, _) = pattern.ReplaceTokens(tokens, CreateTestResolver()); - Assert.Equal("siteasdf1234", path); + Assert.AreEqual("siteasdf1234", path); } - [Fact] + [TestMethod] public void CanReplaceTokens_SimpleFingerprintExpression_Only() { var pattern = StaticWebAssetPathPattern.Parse("#[{fingerprint}]", "MyApp"); @@ -520,10 +528,10 @@ public void CanReplaceTokens_SimpleFingerprintExpression_Only() }; var (path, _) = pattern.ReplaceTokens(tokens, CreateTestResolver()); - Assert.Equal("asdf1234", path); + Assert.AreEqual("asdf1234", path); } - [Fact] + [TestMethod] public void CanReplaceTokens_SimpleFingerprintExpression_WithEmbeddedValues() { var pattern = StaticWebAssetPathPattern.Parse("#[{fingerprint=embedded}]", "MyApp"); @@ -533,10 +541,10 @@ public void CanReplaceTokens_SimpleFingerprintExpression_WithEmbeddedValues() }; var (path, _) = pattern.ReplaceTokens(tokens, CreateTestResolver()); - Assert.Equal("embedded", path); + Assert.AreEqual("embedded", path); } - [Fact] + [TestMethod] public void CanReplaceTokens_ComplexExpression_MultipleVariables() { var pattern = StaticWebAssetPathPattern.Parse("css/site#[.{fingerprint}-{version}].css", "MyApp"); @@ -548,10 +556,10 @@ public void CanReplaceTokens_ComplexExpression_MultipleVariables() tokens, CreateTestResolver(new Dictionary(StringComparer.OrdinalIgnoreCase) { ["version"] = "v1" })); - Assert.Equal("css/site.asdf1234-v1.css", path); + Assert.AreEqual("css/site.asdf1234-v1.css", path); } - [Fact] + [TestMethod] public void CanReplaceTokens_ComplexExpression_MultipleConsecutiveVariables() { var pattern = StaticWebAssetPathPattern.Parse("css/site#[.{fingerprint}{version}].css", "MyApp"); @@ -563,10 +571,10 @@ public void CanReplaceTokens_ComplexExpression_MultipleConsecutiveVariables() tokens, CreateTestResolver(new Dictionary(StringComparer.OrdinalIgnoreCase) { ["version"] = "v1" })); - Assert.Equal("css/site.asdf1234v1.css", path); + Assert.AreEqual("css/site.asdf1234v1.css", path); } - [Fact] + [TestMethod] public void CanReplaceTokens_ComplexExpression_StartsWithVariable() { var pattern = StaticWebAssetPathPattern.Parse("#[{fingerprint}.]css", "MyApp"); @@ -576,19 +584,19 @@ public void CanReplaceTokens_ComplexExpression_StartsWithVariable() }; var (path, _) = pattern.ReplaceTokens(tokens, CreateTestResolver()); - Assert.Equal("asdf1234.css", path); + Assert.AreEqual("asdf1234.css", path); } - [Fact] + [TestMethod] public void CanReplaceTokens_ThrowsException_IfRequiredExpressionIsValue() { var pattern = StaticWebAssetPathPattern.Parse("css/site#[.{fingerprint}].css", "MyApp"); var tokens = new StaticWebAsset(); - var exception = Assert.Throws(() => pattern.ReplaceTokens(tokens, CreateTestResolver())); - Assert.Equal("Token 'fingerprint' not provided for 'css/site#[.{fingerprint}].css'.", exception.Message); + var exception = Assert.ThrowsExactly(() => pattern.ReplaceTokens(tokens, CreateTestResolver())); + Assert.AreEqual("Token 'fingerprint' not provided for 'css/site#[.{fingerprint}].css'.", exception.Message); } - [Fact] + [TestMethod] public void CanReplaceTokens_ThrowsException_MultipleTokenComplexExpression_MissingAtLeastOneValue() { var pattern = StaticWebAssetPathPattern.Parse("css/site#[.{fingerprint}-{version}].css", "MyApp"); @@ -596,21 +604,21 @@ public void CanReplaceTokens_ThrowsException_MultipleTokenComplexExpression_Miss { Fingerprint = "asdf1234" }; - var exception = Assert.Throws(() => pattern.ReplaceTokens(tokens, CreateTestResolver())); - Assert.Equal("Token 'version' not provided for 'css/site#[.{fingerprint}-{version}].css'.", exception.Message); + var exception = Assert.ThrowsExactly(() => pattern.ReplaceTokens(tokens, CreateTestResolver())); + Assert.AreEqual("Token 'version' not provided for 'css/site#[.{fingerprint}-{version}].css'.", exception.Message); } - [Fact] + [TestMethod] public void CanReplaceTokens_OptionalExpression_OmittedWhenValueNotProvided() { var pattern = StaticWebAssetPathPattern.Parse("site#[.{fingerprint}]?", "MyApp"); var tokens = new StaticWebAsset(); var (path, _) = pattern.ReplaceTokens(tokens, CreateTestResolver()); - Assert.Equal("site", path); + Assert.AreEqual("site", path); } - [Fact] + [TestMethod] public void CanReplaceTokens_OptionalMultipleTokenComplexExpression_OmittedWhenMissingAtLeastOneValue() { var pattern = StaticWebAssetPathPattern.Parse("site#[.{fingerprint}.{version}]?", "MyApp"); @@ -620,28 +628,28 @@ public void CanReplaceTokens_OptionalMultipleTokenComplexExpression_OmittedWhenM }; var (path, _) = pattern.ReplaceTokens(tokens, CreateTestResolver()); - Assert.Equal("site", path); + Assert.AreEqual("site", path); } - [Fact] + [TestMethod] public void CanExpandRoutes_LiteralPatterns() { var pattern = StaticWebAssetPathPattern.Parse("css/site.css", "MyApp"); var routePatterns = pattern.ExpandPatternExpression(); - Assert.Equal([pattern], routePatterns); + Assert.AreSequenceEqual([pattern], routePatterns); } - [Fact] + [TestMethod] public void CanExpandRoutes_SingleRequiredExpression() { var pattern = StaticWebAssetPathPattern.Parse("css/site#[.{fingerprint}].css", "MyApp"); var routePatterns = pattern.ExpandPatternExpression(); - Assert.Equal([pattern], routePatterns); + Assert.AreSequenceEqual([pattern], routePatterns); } - [Fact] + [TestMethod] public void CanExpandRoutes_SingleOptionalExpression() { var pattern = StaticWebAssetPathPattern.Parse("site#[.{fingerprint}]?.css", "MyApp"); @@ -668,10 +676,10 @@ public void CanExpandRoutes_SingleOptionalExpression() } }; - Assert.Equal(expected, routePatterns); + Assert.AreSequenceEqual(expected, routePatterns); } - [Fact] + [TestMethod] public void CanExpandRoutes_MultipleOptionalExpressions() { var pattern = StaticWebAssetPathPattern.Parse("site#[.{fingerprint}]?#[.{version}]?.css", "MyApp"); @@ -717,7 +725,7 @@ public void CanExpandRoutes_MultipleOptionalExpressions() } }; - Assert.Equal(expected, routePatterns); + Assert.AreSequenceEqual(expected, routePatterns); } private static StaticWebAssetTokenResolver CreateTestResolver(Dictionary additionalTokens = null) => new(additionalTokens); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetTaskEnvironmentTests.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetTaskEnvironmentTests.cs index 30a2109492c0..abc774bc4b6c 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetTaskEnvironmentTests.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetTaskEnvironmentTests.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -13,9 +19,11 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; // [assembly:CollectionBehavior(DisableTestParallelization = true)] in // LegacyStaticWebAssetsV1IntegrationTest.cs, which already isolates the // process-CWD mutation these tests perform. +[DoNotParallelize] +[TestClass] public class StaticWebAssetTaskEnvironmentTests { - [Fact] + [TestMethod] public void NormalizeContentRootPath_WithTaskEnvironment_AbsolutizesAgainstProjectDirectory_NotProcessCurrentDirectory() { WithDecoyCwdAndProjectDirectory((projectDir, _) => @@ -29,7 +37,7 @@ public void NormalizeContentRootPath_WithTaskEnvironment_AbsolutizesAgainstProje }); } - [Fact] + [TestMethod] public void NormalizeContentRootPath_WithoutEnvOverload_StillUsesProcessCurrentDirectory_ForBackCompat() { WithDecoyCwdAndProjectDirectory((_, spawnDir) => @@ -43,7 +51,7 @@ public void NormalizeContentRootPath_WithoutEnvOverload_StillUsesProcessCurrentD }); } - [Fact] + [TestMethod] public void Normalize_WithTaskEnvironment_AbsolutizesContentRootAndRelatedAssetAgainstProjectDirectory() { WithDecoyCwdAndProjectDirectory((projectDir, _) => @@ -67,7 +75,7 @@ public void Normalize_WithTaskEnvironment_AbsolutizesContentRootAndRelatedAssetA }); } - [Fact] + [TestMethod] public void FromTaskItem_WithTaskEnvironment_HydratesAssetWithProjectDirectoryAbsolutizedPaths() { WithDecoyCwdAndProjectDirectory((projectDir, _) => @@ -89,7 +97,7 @@ public void FromTaskItem_WithTaskEnvironment_HydratesAssetWithProjectDirectoryAb }); } - [Fact] + [TestMethod] public void FromV1TaskItem_WithTaskEnvironment_HydratesAssetWithProjectDirectoryAbsolutizedPaths() { WithDecoyCwdAndProjectDirectory((projectDir, _) => @@ -118,7 +126,7 @@ public void FromV1TaskItem_WithTaskEnvironment_HydratesAssetWithProjectDirectory }); } - [Fact] + [TestMethod] public void FromTaskItemGroup_WithTaskEnvironment_AbsolutizesAllAssets() { WithDecoyCwdAndProjectDirectory((projectDir, _) => @@ -137,7 +145,7 @@ public void FromTaskItemGroup_WithTaskEnvironment_AbsolutizesAllAssets() }); } - [Fact] + [TestMethod] public void ResolveFile_WithTaskEnvironment_ResolvesIdentityRelativeToProjectDirectory() { WithDecoyCwdAndProjectDirectory((projectDir, _) => @@ -155,7 +163,7 @@ public void ResolveFile_WithTaskEnvironment_ResolvesIdentityRelativeToProjectDir }); } - [Fact] + [TestMethod] public void HasContentRoot_WithTaskEnvironment_ComparesAgainstProjectDirectoryNormalizedForm() { WithDecoyCwdAndProjectDirectory((projectDir, _) => @@ -176,7 +184,7 @@ public void HasContentRoot_WithTaskEnvironment_ComparesAgainstProjectDirectoryNo }); } - [Fact] + [TestMethod] public void NormalizeContentRootPath_WithTaskEnvironment_PreservesCanonicalization_DotDot() { WithDecoyCwdAndProjectDirectory((projectDir, _) => @@ -192,7 +200,7 @@ public void NormalizeContentRootPath_WithTaskEnvironment_PreservesCanonicalizati }); } - [Fact] + [TestMethod] public void Normalize_WithTaskEnvironment_AbsolutePathInputs_ArePreservedAndCanonicalized() { // The single most common production case: upstream targets pre-absolutize. The new diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetTest.cs index faf9b7cfe8cf..8cf81c9f5eeb 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetTest.cs @@ -1,15 +1,23 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests.StaticWebAssets; +[TestClass] + public class StaticWebAssetTest { - [Fact] + [TestMethod] public void ValidateAssetGroup_SingleAsset_ReturnsTrue() { var asset = CreateAsset("wwwroot/app.js", "app.js", "All", "All"); @@ -18,11 +26,11 @@ public void ValidateAssetGroup_SingleAsset_ReturnsTrue() var groupSet = new HashSet(StringComparer.Ordinal); var result = StaticWebAsset.ValidateAssetGroup("app.js", group, out var reason, groupSet); - Assert.True(result); - Assert.Null(reason); + Assert.IsTrue(result); + Assert.IsNull(reason); } - [Fact] + [TestMethod] public void ValidateAssetGroup_TwoAssetsFromDifferentProjects_ReturnsFalse() { var asset1 = CreateAsset("wwwroot/app.js", "app.js", "All", "All", sourceId: "Project1"); @@ -32,11 +40,11 @@ public void ValidateAssetGroup_TwoAssetsFromDifferentProjects_ReturnsFalse() var groupSet2 = new HashSet(StringComparer.Ordinal); var result = StaticWebAsset.ValidateAssetGroup("app.js", group, out var reason, groupSet2); - Assert.False(result); + Assert.IsFalse(result); Assert.Contains("different projects", reason); } - [Fact] + [TestMethod] public void ValidateAssetGroup_TwoAllAssetsFromSameProject_ReturnsFalse() { var asset1 = CreateAsset("wwwroot/app.js", "app.js", "All", "All"); @@ -46,11 +54,11 @@ public void ValidateAssetGroup_TwoAllAssetsFromSameProject_ReturnsFalse() var groupSet3 = new HashSet(StringComparer.Ordinal); var result = StaticWebAsset.ValidateAssetGroup("app.js", group, out var reason, groupSet3); - Assert.False(result); + Assert.IsFalse(result); Assert.Contains("'All' assets", reason); } - [Fact] + [TestMethod] public void ValidateAssetGroup_BuildAndPublishAssetsFromSameProject_ReturnsTrue() { var buildAsset = CreateAsset("wwwroot/app.js", "app.js", "Build", "All"); @@ -60,11 +68,11 @@ public void ValidateAssetGroup_BuildAndPublishAssetsFromSameProject_ReturnsTrue( var groupSet4 = new HashSet(StringComparer.Ordinal); var result = StaticWebAsset.ValidateAssetGroup("app.js", group, out var reason, groupSet4); - Assert.True(result); - Assert.Null(reason); + Assert.IsTrue(result); + Assert.IsNull(reason); } - [Fact] + [TestMethod] public void ComputeTargetPath_WithoutTokenResolver_KeepsTokensInPath() { var asset = CreateAsset( @@ -76,10 +84,10 @@ public void ComputeTargetPath_WithoutTokenResolver_KeepsTokensInPath() var targetPath = asset.ComputeTargetPath("", '/'); - Assert.Equal("MyApp.styles#[.{fingerprint}]?.css", targetPath); + Assert.AreEqual("MyApp.styles#[.{fingerprint}]?.css", targetPath); } - [Fact] + [TestMethod] public void ComputeTargetPath_WithTokenResolver_ReplacesOptionalTokens() { var asset = CreateAsset( @@ -91,10 +99,10 @@ public void ComputeTargetPath_WithTokenResolver_ReplacesOptionalTokens() var targetPath = asset.ComputeTargetPath("", '/', StaticWebAssetTokenResolver.Instance); - Assert.Equal("MyApp.styles.css", targetPath); + Assert.AreEqual("MyApp.styles.css", targetPath); } - [Fact] + [TestMethod] public void TwoAssetsWithDifferentPatternsResolveToSameTargetPath_AfterTokenReplacement() { var discoveredAsset = CreateAsset( @@ -114,19 +122,19 @@ public void TwoAssetsWithDifferentPatternsResolveToSameTargetPath_AfterTokenRepl var path1WithTokens = discoveredAsset.ComputeTargetPath("", '/'); var path2WithTokens = computedAsset.ComputeTargetPath("", '/'); - Assert.NotEqual(path1WithTokens, path2WithTokens); - Assert.Equal("MyApp.styles#[.{fingerprint}]?.css", path1WithTokens); - Assert.Equal("MyApp#[.{fingerprint}]?.styles.css", path2WithTokens); + Assert.AreNotEqual(path1WithTokens, path2WithTokens); + Assert.AreEqual("MyApp.styles#[.{fingerprint}]?.css", path1WithTokens); + Assert.AreEqual("MyApp#[.{fingerprint}]?.styles.css", path2WithTokens); var path1Resolved = discoveredAsset.ComputeTargetPath("", '/', StaticWebAssetTokenResolver.Instance); var path2Resolved = computedAsset.ComputeTargetPath("", '/', StaticWebAssetTokenResolver.Instance); - Assert.Equal("MyApp.styles.css", path1Resolved); - Assert.Equal("MyApp.styles.css", path2Resolved); - Assert.Equal(path1Resolved, path2Resolved); + Assert.AreEqual("MyApp.styles.css", path1Resolved); + Assert.AreEqual("MyApp.styles.css", path2Resolved); + Assert.AreEqual(path1Resolved, path2Resolved); } - [Fact] + [TestMethod] public void ValidateAssetGroup_DetectsConflict_WhenAssetsHaveDifferentPatterns_ButSameResolvedPath() { var discoveredAsset = CreateAsset( @@ -147,23 +155,23 @@ public void ValidateAssetGroup_DetectsConflict_WhenAssetsHaveDifferentPatterns_B var groupSet = new HashSet(StringComparer.Ordinal); var result = StaticWebAsset.ValidateAssetGroup("MyApp.styles.css", group, out var reason, groupSet); - Assert.False(result); + Assert.IsFalse(result); Assert.Contains("'All' assets", reason); } // SortByRelatedAssetInPlace tests - [Fact] + [TestMethod] public void SortByRelatedAssetInPlace_EmptyArray_DoesNothing() { var assets = Array.Empty(); StaticWebAsset.SortByRelatedAssetInPlace(assets); - Assert.Empty(assets); + Assert.IsEmpty(assets); } - [Fact] + [TestMethod] public void SortByRelatedAssetInPlace_SingleElement_DoesNothing() { var a = CreateChainAsset("A"); @@ -171,10 +179,10 @@ public void SortByRelatedAssetInPlace_SingleElement_DoesNothing() StaticWebAsset.SortByRelatedAssetInPlace(assets); - Assert.Same(a, assets[0]); + Assert.AreSame(a, assets[0]); } - [Fact] + [TestMethod] public void SortByRelatedAssetInPlace_AllRoots_PreservesOrder() { var a = CreateChainAsset("A"); @@ -184,12 +192,12 @@ public void SortByRelatedAssetInPlace_AllRoots_PreservesOrder() StaticWebAsset.SortByRelatedAssetInPlace(assets); - Assert.Same(a, assets[0]); - Assert.Same(b, assets[1]); - Assert.Same(c, assets[2]); + Assert.AreSame(a, assets[0]); + Assert.AreSame(b, assets[1]); + Assert.AreSame(c, assets[2]); } - [Fact] + [TestMethod] public void SortByRelatedAssetInPlace_AlreadySorted_Chain() { // D (root) → C → B → A (parents before children) @@ -203,7 +211,7 @@ public void SortByRelatedAssetInPlace_AlreadySorted_Chain() AssertParentsBeforeChildren(assets); } - [Fact] + [TestMethod] public void SortByRelatedAssetInPlace_ReversedChain_WorstCase() { // Chain: A→B→C→D (D is root). Array in child-first order. @@ -217,7 +225,7 @@ public void SortByRelatedAssetInPlace_ReversedChain_WorstCase() AssertParentsBeforeChildren(assets); } - [Fact] + [TestMethod] public void SortByRelatedAssetInPlace_LongReversedChain() { // A→B→C→D→E (E is root), worst order [A, B, C, D, E] @@ -232,7 +240,7 @@ public void SortByRelatedAssetInPlace_LongReversedChain() AssertParentsBeforeChildren(assets); } - [Fact] + [TestMethod] public void SortByRelatedAssetInPlace_ShuffledChain() { // A→B→C→D→E (E is root), shuffled order [C, A, D, B, E] @@ -247,7 +255,7 @@ public void SortByRelatedAssetInPlace_ShuffledChain() AssertParentsBeforeChildren(assets); } - [Fact] + [TestMethod] public void SortByRelatedAssetInPlace_MultipleIndependentChains() { // Chain 1: X→Y (Y root). Chain 2: P→Q→R (R root). @@ -263,7 +271,7 @@ public void SortByRelatedAssetInPlace_MultipleIndependentChains() AssertParentsBeforeChildren(assets); } - [Fact] + [TestMethod] public void SortByRelatedAssetInPlace_Diamond_TwoChildrenOneParent() { // A→C, B→C, C is root. Order: [A, B, C] @@ -276,7 +284,7 @@ public void SortByRelatedAssetInPlace_Diamond_TwoChildrenOneParent() AssertParentsBeforeChildren(assets); } - [Fact] + [TestMethod] public void SortByRelatedAssetInPlace_MixedRootsAndChain() { // Roots: R1, R2. Chain: A→B→C (C root). Order: [A, R1, B, R2, C] @@ -291,7 +299,7 @@ public void SortByRelatedAssetInPlace_MixedRootsAndChain() AssertParentsBeforeChildren(assets); } - [Fact] + [TestMethod] public void SortByRelatedAssetInPlace_OrphanAsset_PlacedAnyway() { // A→B but B is not in the array. A should still be placed. @@ -301,12 +309,12 @@ public void SortByRelatedAssetInPlace_OrphanAsset_PlacedAnyway() StaticWebAsset.SortByRelatedAssetInPlace(assets); - Assert.Equal(2, assets.Length); + Assert.HasCount(2, assets); Assert.Contains(a, assets); Assert.Contains(r, assets); } - [Fact] + [TestMethod] public void SortByRelatedAssetInPlace_TwoElements_ChildBeforeParent() { var parent = CreateChainAsset("Parent"); @@ -315,11 +323,11 @@ public void SortByRelatedAssetInPlace_TwoElements_ChildBeforeParent() StaticWebAsset.SortByRelatedAssetInPlace(assets); - Assert.Same(parent, assets[0]); - Assert.Same(child, assets[1]); + Assert.AreSame(parent, assets[0]); + Assert.AreSame(child, assets[1]); } - [Fact] + [TestMethod] public void SortByRelatedAssetInPlace_ProducesValidOrder_OnVariousInputs() { // Verify the in-place sort produces a valid topological ordering @@ -346,7 +354,7 @@ public void SortByRelatedAssetInPlace_ProducesValidOrder_OnVariousInputs() } } - [Fact] + [TestMethod] public void SortByRelatedAssetInPlace_PreservesAllElements() { var e = CreateChainAsset("E"); @@ -359,7 +367,7 @@ public void SortByRelatedAssetInPlace_PreservesAllElements() StaticWebAsset.SortByRelatedAssetInPlace(assets); - Assert.Equal(original, new HashSet(assets)); + new HashSet(assets).Should().BeEquivalentTo(original); } // Asserts that for every asset in the array, its RelatedAsset (parent) @@ -371,8 +379,8 @@ private static void AssertParentsBeforeChildren(StaticWebAsset[] assets) { if (!string.IsNullOrEmpty(asset.RelatedAsset)) { - Assert.True( - seen.Contains(asset.RelatedAsset), + seen.Should().Contain( + asset.RelatedAsset, $"Asset '{Path.GetFileName(asset.Identity)}' appears before its parent '{Path.GetFileName(asset.RelatedAsset)}'"); } seen.Add(asset.Identity); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetsGeneratePackManifestMultiThreadingTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetsGeneratePackManifestMultiThreadingTest.cs index d128904d1b49..31eb7856914a 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetsGeneratePackManifestMultiThreadingTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetsGeneratePackManifestMultiThreadingTest.cs @@ -10,13 +10,13 @@ namespace Microsoft.AspNetCore.Razor.Tasks; -// Test parallelization is disabled assembly-wide via -// [assembly:CollectionBehavior(DisableTestParallelization = true)] in -// LegacyStaticWebAssetsV1IntegrationTest.cs, which already isolates the -// process-CWD mutation these tests perform. +// This test mutates the process-wide current directory, so it must not run +// concurrently with other tests under MSTest's method-level parallelization. +[DoNotParallelize] +[TestClass] public class StaticWebAssetsGeneratePackManifestMultiThreadingTest { - [Fact] + [TestMethod] public void WritesManifestRelativeToTaskEnvironmentProjectDirectory_NotProcessCurrentDirectory() { var testRoot = Path.Combine(AppContext.BaseDirectory, nameof(StaticWebAssetsGeneratePackManifestMultiThreadingTest), Guid.NewGuid().ToString("N")); @@ -58,7 +58,7 @@ public void WritesManifestRelativeToTaskEnvironmentProjectDirectory_NotProcessCu } } - [Fact] + [TestMethod] public void ResolvesExistingManifestCheckRelativeToProjectDirectory_NotProcessCurrentDirectory() { // Verifies that the File.Exists/File.ReadAllBytes change-detection probe in PersistManifest @@ -109,7 +109,7 @@ public void ResolvesExistingManifestCheckRelativeToProjectDirectory_NotProcessCu } } - [Fact] + [TestMethod] public void WritesManifestToAbsoluteManifestPath_WhenProcessCurrentDirectoryDiffers() { var testRoot = Path.Combine(AppContext.BaseDirectory, nameof(StaticWebAssetsGeneratePackManifestMultiThreadingTest), Guid.NewGuid().ToString("N")); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetsGeneratePackagePropsFileMultiThreadingTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetsGeneratePackagePropsFileMultiThreadingTest.cs index 3cf25d0246a0..defb8456f423 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetsGeneratePackagePropsFileMultiThreadingTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetsGeneratePackagePropsFileMultiThreadingTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Moq; @@ -13,9 +19,11 @@ namespace Microsoft.AspNetCore.Razor.Tasks; // [assembly:CollectionBehavior(DisableTestParallelization = true)] in // LegacyStaticWebAssetsV1IntegrationTest.cs, which already isolates the // process-CWD mutation this test performs. +[DoNotParallelize] +[TestClass] public class StaticWebAssetsGeneratePackagePropsFileMultiThreadingTest { - [Fact] + [TestMethod] public void WritesPropsFileRelativeToTaskEnvironmentProjectDirectory() { var testRoot = Path.Combine(AppContext.BaseDirectory, nameof(StaticWebAssetsGeneratePackagePropsFileMultiThreadingTest), Guid.NewGuid().ToString("N")); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetsGeneratePackagePropsFileTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetsGeneratePackagePropsFileTest.cs index 15738d2dac43..60dea1e28ace 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetsGeneratePackagePropsFileTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/StaticWebAssetsGeneratePackagePropsFileTest.cs @@ -1,15 +1,22 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.AspNetCore.StaticWebAssets.Tasks; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; using Microsoft.Build.Framework; using Moq; +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace Microsoft.AspNetCore.Razor.Tasks { + [TestClass] public class StaticWebAssetsGeneratePackagePropsFileTest { - [Fact] + [TestMethod] public void WritesPropsFile_WithProvidedImportPath() { // Arrange diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdateExternallyDefinedStaticWebAssetsTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdateExternallyDefinedStaticWebAssetsTest.cs index 1c64f37d3d00..d39d079b3780 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdateExternallyDefinedStaticWebAssetsTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdateExternallyDefinedStaticWebAssetsTest.cs @@ -1,17 +1,25 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Moq; namespace Microsoft.AspNetCore.StaticWebAssets.Tasks; +[TestClass] + public class UpdateExternallyDefinedStaticWebAssetsTest { - [Fact] + [TestMethod] public void Execute_UpdatesAssetsWithoutFingerprint() { // Arrange @@ -85,7 +93,7 @@ public void Execute_UpdatesAssetsWithoutFingerprint() task.UpdatedAssets[1].GetMetadata("Integrity").Should().NotBeNullOrEmpty(); } - [Fact] + [TestMethod] public void Execute_DoesNotAddAssets_WithEndpointsTo_AssetsWithoutEndpoints() { // Arrange @@ -171,7 +179,7 @@ public void Execute_DoesNotAddAssets_WithEndpointsTo_AssetsWithoutEndpoints() task.UpdatedAssets[1].GetMetadata("Integrity").Should().NotBeNullOrEmpty(); } - [Fact] + [TestMethod] public void Execute_InfersFingerprint_ForMatchingAssets() { // Arrange @@ -255,7 +263,7 @@ public void Execute_InfersFingerprint_ForMatchingAssets() task.UpdatedAssets[1].GetMetadata("Integrity").Should().NotBeNullOrEmpty(); } - [Fact] + [TestMethod] public void Execute_MaterializesFrameworkAssetsFromP2PReferences() { // Arrange @@ -318,7 +326,7 @@ public void Execute_MaterializesFrameworkAssetsFromP2PReferences() task.OriginalFrameworkAssets[0].GetMetadata("SourceType").Should().Be("Framework"); } - [Fact] + [TestMethod] public void Execute_RemapsEndpointRoutesForMaterializedFrameworkAssets() { // Arrange @@ -397,7 +405,7 @@ public void Execute_RemapsEndpointRoutesForMaterializedFrameworkAssets() endpointProperties.Should().NotContain("_content/SourceLib"); } - [Fact] + [TestMethod] public void Execute_RemapsEndpointRoutesToConsumerBasePath() { // Arrange @@ -471,7 +479,7 @@ public void Execute_RemapsEndpointRoutesToConsumerBasePath() endpointProperties.Should().NotContain("_content/SourceLib"); } - [Fact] + [TestMethod] public void Execute_PassesThroughNonFrameworkAssetsUnchanged() { // Arrange diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdatePackageStaticWebAssetsMultiThreadingTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdatePackageStaticWebAssetsMultiThreadingTest.cs index 1f1d09093c86..12d0a5edddfd 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdatePackageStaticWebAssetsMultiThreadingTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdatePackageStaticWebAssetsMultiThreadingTest.cs @@ -10,14 +10,14 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; -// Test parallelization is disabled assembly-wide via -// [assembly:CollectionBehavior(DisableTestParallelization = true)] in -// LegacyStaticWebAssetsV1IntegrationTest.cs, which already isolates the -// process-CWD mutation this test performs. +// This test mutates the process-wide current directory, so it must not run +// concurrently with other tests under MSTest's method-level parallelization. +[DoNotParallelize] +[TestClass] public class UpdatePackageStaticWebAssetsMultiThreadingTest { // Relative ContentRoot should resolve against TaskEnvironment.ProjectDirectory, not process CWD. - [Fact] + [TestMethod] public void NormalizesContentRootRelativeToTaskEnvironmentProjectDirectory_NotProcessCurrentDirectory() { var testRoot = Path.Combine(AppContext.BaseDirectory, nameof(UpdatePackageStaticWebAssetsMultiThreadingTest), Guid.NewGuid().ToString("N")); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdatePackageStaticWebAssetsTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdatePackageStaticWebAssetsTest.cs index e16ab07c55af..672ddb647826 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdatePackageStaticWebAssetsTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdatePackageStaticWebAssetsTest.cs @@ -1,14 +1,22 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Moq; namespace Microsoft.AspNetCore.StaticWebAssets.Tasks; +[TestClass] + public class UpdatePackageStaticWebAssetsTest : IDisposable { private readonly string _tempDir; @@ -38,7 +46,7 @@ public void Dispose() } } - [Fact] + [TestMethod] public void Execute_PackageAssets_ArePassedThrough() { // Arrange @@ -64,7 +72,7 @@ public void Execute_PackageAssets_ArePassedThrough() task.UpdatedAssets[0].GetMetadata("SourceType").Should().Be("Package"); } - [Fact] + [TestMethod] public void Execute_FrameworkAssets_AreMaterialized() { // Arrange @@ -99,7 +107,7 @@ public void Execute_FrameworkAssets_AreMaterialized() File.ReadAllText(expectedPath).Should().Be("console.log('framework');"); } - [Fact] + [TestMethod] public void Execute_FrameworkAssets_SourceTypeChangedToDiscovered() { // Arrange @@ -127,7 +135,7 @@ public void Execute_FrameworkAssets_SourceTypeChangedToDiscovered() updated.GetMetadata("AssetMode").Should().Be("CurrentProject"); } - [Fact] + [TestMethod] public void Execute_FrameworkAssets_ContentRootPointsToFxDirectory() { // Arrange @@ -154,7 +162,7 @@ public void Execute_FrameworkAssets_ContentRootPointsToFxDirectory() updated.GetMetadata("ContentRoot").Should().Be(expectedContentRoot); } - [Fact] + [TestMethod] public void Execute_FrameworkAssets_MissingSourceFile_LogsError() { // Arrange @@ -178,7 +186,7 @@ public void Execute_FrameworkAssets_MissingSourceFile_LogsError() _errorMessages.Should().ContainSingle(e => e.Contains("does not exist") && e.Contains("does_not_exist.js")); } - [Fact] + [TestMethod] public void Execute_MixedAssets_ProcessesBothTypes() { // Arrange @@ -211,7 +219,7 @@ public void Execute_MixedAssets_ProcessesBothTypes() task.UpdatedAssets[1].GetMetadata("SourceType").Should().Be("Discovered"); } - [Fact] + [TestMethod] public void Execute_FrameworkAssets_PreservesOriginalFingerprintAndIntegrity() { // Arrange @@ -242,7 +250,7 @@ public void Execute_FrameworkAssets_PreservesOriginalFingerprintAndIntegrity() updated.GetMetadata("Integrity").Should().Be(originalIntegrity); } - [Fact] + [TestMethod] public void Execute_FrameworkAssets_IncrementalSkipsCopy_WhenUpToDate() { // Arrange @@ -278,7 +286,7 @@ public void Execute_FrameworkAssets_IncrementalSkipsCopy_WhenUpToDate() _logMessages.Should().Contain(m => m.Contains("already up to date")); } - [Fact] + [TestMethod] public void Execute_FrameworkAssets_OverwritesStaleDestination() { // Arrange @@ -313,7 +321,7 @@ public void Execute_FrameworkAssets_OverwritesStaleDestination() _logMessages.Should().Contain(m => m.Contains("Materialized framework asset")); } - [Fact] + [TestMethod] public void Execute_NoFrameworkAssets_EndpointsNotRemapped() { // Arrange @@ -348,7 +356,7 @@ public void Execute_NoFrameworkAssets_EndpointsNotRemapped() task.RemappedEndpoints.Should().BeNullOrEmpty(); } - [Fact] + [TestMethod] public void Execute_FrameworkAssets_EndpointsAreRemapped() { // Arrange @@ -387,7 +395,7 @@ public void Execute_FrameworkAssets_EndpointsAreRemapped() remapped.GetMetadata("AssetFile").Should().Be(expectedPath); } - [Fact] + [TestMethod] public void Execute_MultipleEndpoints_SameIdentity_AllRemapped() { // Arrange — two endpoints share the same Identity (e.g. same route, different selectors) @@ -435,7 +443,7 @@ public void Execute_MultipleEndpoints_SameIdentity_AllRemapped() task.RemappedEndpoints[1].GetMetadata("AssetFile").Should().Be(expectedPath); } - [Fact] + [TestMethod] public void Execute_EndpointsNotMatchingFramework_AreNotRemapped() { // Arrange — endpoint pointing to a file that is NOT a framework asset @@ -482,7 +490,7 @@ public void Execute_EndpointsNotMatchingFramework_AreNotRemapped() task.RemappedEndpoints[0].ItemSpec.Should().Be("framework.js"); } - [Fact] + [TestMethod] public void Execute_NullEndpoints_DoesNotRemapAndSucceeds() { // Arrange @@ -508,7 +516,7 @@ public void Execute_NullEndpoints_DoesNotRemapAndSucceeds() task.RemappedEndpoints.Should().BeNullOrEmpty(); } - [Fact] + [TestMethod] public void Execute_EmptyAssetsArray_Succeeds() { // Arrange @@ -530,7 +538,7 @@ public void Execute_EmptyAssetsArray_Succeeds() task.OriginalAssets.Should().BeEmpty(); } - [Fact] + [TestMethod] public void Execute_FrameworkAssets_SubdirectoriesArePreserved() { // Arrange @@ -640,7 +648,7 @@ private ITaskItem CreateEndpoint(string route, string assetFile, string label = }); } - [Fact] + [TestMethod] public void Execute_FrameworkAssets_RemapsEndpointRoutes_StripOldBasePath() { // Arrange @@ -679,7 +687,7 @@ public void Execute_FrameworkAssets_RemapsEndpointRoutes_StripOldBasePath() task.OriginalFrameworkEndpoints[0].ItemSpec.Should().Be("_content/FxLib/js/framework.js"); } - [Fact] + [TestMethod] public void Execute_FrameworkAssets_RemapsEndpointRoutes_ToConsumerBasePath() { // Arrange diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdateStaticWebAssetEndpointsTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdateStaticWebAssetEndpointsTest.cs index 43956cf963c3..565d6cc16ed7 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdateStaticWebAssetEndpointsTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/UpdateStaticWebAssetEndpointsTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -10,9 +16,11 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests.StaticWebAssets; +[TestClass] + public class UpdateStaticWebAssetEndpointsTest { - [Fact] + [TestMethod] public void CanUpdateEndpoint_AppendResponseHeaders() { // Arrrange @@ -57,7 +65,7 @@ public void CanUpdateEndpoint_AppendResponseHeaders() } } - [Fact] + [TestMethod] public void CanUpdateEndpoint_RemoveResponseHeaders() { // Arrrange @@ -98,7 +106,7 @@ public void CanUpdateEndpoint_RemoveResponseHeaders() } } - [Fact] + [TestMethod] public void CanUpdateEndpoint_RemoveAllResponseHeaders() { // Arrrange @@ -143,7 +151,7 @@ public void CanUpdateEndpoint_RemoveAllResponseHeaders() } } - [Fact] + [TestMethod] public void CanUpdateEndpoint_RemoveAllResponseHeadersWithValue() { // Arrrange @@ -189,7 +197,7 @@ public void CanUpdateEndpoint_RemoveAllResponseHeadersWithValue() } } - [Fact] + [TestMethod] public void CanUpdateEndpoint_ReplaceResponseHeaders() { // Arrrange @@ -230,7 +238,7 @@ public void CanUpdateEndpoint_ReplaceResponseHeaders() } } - [Fact] + [TestMethod] public void CanUpdateEndpoint_RetainsNonModifiedEndpointsWithSameRoute() { // Arrrange diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ValidateStaticWebAssetsUniquePathsTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ValidateStaticWebAssetsUniquePathsTest.cs index fe6518ed6bda..965635d12ada 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ValidateStaticWebAssetsUniquePathsTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssets/ValidateStaticWebAssetsUniquePathsTest.cs @@ -1,8 +1,14 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -10,9 +16,10 @@ namespace Microsoft.AspNetCore.Razor.Tasks { + [TestClass] public class ValidateStaticWebAssetsUniquePathsTest { - [Fact] + [TestMethod] public void ReturnsError_WhenStaticWebAssetsWebRootPathMatchesExistingContentItemPath() { // Arrange @@ -59,7 +66,7 @@ public void ReturnsError_WhenStaticWebAssetsWebRootPathMatchesExistingContentIte errorMessages.Should().Contain(expectedMessage); } - [Fact] + [TestMethod] public void AllowsAssetsHavingTheSameBasePathAcrossDifferentSources_WhenTheirFinalDestinationPathIsDifferent() { // Arrange @@ -92,7 +99,7 @@ public void AllowsAssetsHavingTheSameBasePathAcrossDifferentSources_WhenTheirFin result.Should().Be(true); } - [Fact] + [TestMethod] public void AllowsAssetsHavingTheSameContentRootAndDifferentBasePathsAcrossDifferentSources_WhenTheirFinalDestinationPathIsDifferent() { // Arrange @@ -125,7 +132,7 @@ public void AllowsAssetsHavingTheSameContentRootAndDifferentBasePathsAcrossDiffe result.Should().Be(true); } - [Fact] + [TestMethod] public void ReturnsError_WhenMultipleStaticWebAssetsHaveTheSameWebRootPath() { // Arrange @@ -161,7 +168,7 @@ public void ReturnsError_WhenMultipleStaticWebAssetsHaveTheSameWebRootPath() errorMessages.Should().Contain($"Conflicting assets with the same path '/wwwroot/sample.js' for content root paths '{Path.Combine(".", "Library", "bin", "dist", "sample.js")}' and '{Path.Combine(".", "Library", "wwwroot", "sample.js")}'."); } - [Fact] + [TestMethod] public void ReturnsSuccess_WhenStaticWebAssetsDontConflictWithApplicationContentItems() { // Arrange diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsBaselineComparer.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsBaselineComparer.cs index b1f90ef05e38..cb0fe3fb703d 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsBaselineComparer.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsBaselineComparer.cs @@ -1,10 +1,15 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; using System.Linq; using Microsoft.AspNetCore.StaticWebAssets.Tasks; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; + namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; public class StaticWebAssetsBaselineComparer diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsBaselineFactory.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsBaselineFactory.cs index bf33b8a5b711..e783d934fe8a 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsBaselineFactory.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsBaselineFactory.cs @@ -1,8 +1,13 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; + using System.Runtime.Versioning; using System.Text.RegularExpressions; using Microsoft.AspNetCore.StaticWebAssets.Tasks; diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsCompressionIntegrationTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsCompressionIntegrationTest.cs index df2caf4709da..7482a1d5871f 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsCompressionIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsCompressionIntegrationTest.cs @@ -1,17 +1,22 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.IO.Compression; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; using System.Net.Http.Headers; using Microsoft.AspNetCore.StaticWebAssets.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { + [TestClass] public class StaticWebAssetsCompressionIntegrationTest : AspNetSdkBaselineTest { - public StaticWebAssetsCompressionIntegrationTest(ITestOutputHelper log) : base(log, GenerateBaselines) { } - - [Fact] + [TestMethod] public void Build_Detects_PrecompressedAssets() { var expectedManifest = LoadBuildManifest(); @@ -94,7 +99,7 @@ public void Build_Detects_PrecompressedAssets() } } - [Fact] + [TestMethod] public void CanEnable_CompressionOnAllAssets() { var expectedManifest = LoadBuildManifest(); @@ -126,7 +131,7 @@ public void CanEnable_CompressionOnAllAssets() new FileInfo(finalPath).Should().Exist(); } - [Fact] + [TestMethod] public void PublishWorks_With_PrecompressedAssets() { var expectedManifest = LoadBuildManifest(); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsCrossTargetingTests.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsCrossTargetingTests.cs index 8e00dd1f9f2f..3be4a2957dfb 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsCrossTargetingTests.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsCrossTargetingTests.cs @@ -6,15 +6,23 @@ #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { - public class StaticWebAssetsCrossTargetingTests(ITestOutputHelper log) - : IsolatedNuGetPackageFolderAspNetSdkBaselineTest(log, nameof(StaticWebAssetsCrossTargetingTests)) + [TestClass] + public class StaticWebAssetsCrossTargetingTests : IsolatedNuGetPackageFolderAspNetSdkBaselineTest { + protected override string RestoreNugetPackagePath => nameof(StaticWebAssetsCrossTargetingTests); // Build Standalone project - [RequiresMSBuildVersionFact("17.12", Reason = "Needs System.Text.Json 8.0.5")] + [TestMethod] + [RequiresMSBuildVersion("17.12", Reason = "Needs System.Text.Json 8.0.5")] public void Build_CrosstargetingTests_CanIncludeBrowserAssets() { var expectedManifest = LoadBuildManifest(); @@ -59,7 +67,7 @@ public void Build_CrosstargetingTests_CanIncludeBrowserAssets() new FileInfo(finalPath).Should().Exist(); } - [Fact] + [TestMethod] public void Publish_CrosstargetingTests_CanIncludeBrowserAssets() { var testAsset = "RazorComponentAppMultitarget"; diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsDesignTimeTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsDesignTimeTest.cs index 5b57ef2b2c53..6c059da352bd 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsDesignTimeTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsDesignTimeTest.cs @@ -3,6 +3,12 @@ #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System; using System.Collections.Generic; using System.Linq; @@ -11,7 +17,8 @@ namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; -public class StaticWebAssetsDesignTimeTest(ITestOutputHelper log) : AspNetSdkBaselineTest(log) +[TestClass] +public class StaticWebAssetsDesignTimeTest : AspNetSdkBaselineTest { #if DEBUG public const string Configuration = "Debug"; @@ -19,7 +26,7 @@ public class StaticWebAssetsDesignTimeTest(ITestOutputHelper log) : AspNetSdkBas public const string Configuration = "Release"; #endif - [Fact] + [TestMethod] public void CollectUpToDateCheckInputOutputsDesignTime_ReportsAddedFiles() { // Arrange @@ -55,7 +62,7 @@ public void CollectUpToDateCheckInputOutputsDesignTime_ReportsAddedFiles() Path.GetFileName(outputFiles[0]).Should().Be("staticwebassets.build.json"); } - [Fact] + [TestMethod] public void CollectUpToDateCheckInputOutputsDesignTime_ReportsRemovedFiles_Once() { // Arrange @@ -90,7 +97,7 @@ public void CollectUpToDateCheckInputOutputsDesignTime_ReportsRemovedFiles_Once( Path.GetFileName(outputFiles[0]).Should().Be("staticwebassets.build.json"); } - [Fact] + [TestMethod] public void CollectUpToDateCheckInputOutputsDesignTime_IncludesReferencedProjectsManifests() { // Arrange diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsFingerprintingTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsFingerprintingTest.cs index 741aad03ed4f..7f313f685987 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsFingerprintingTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsFingerprintingTest.cs @@ -3,15 +3,22 @@ #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.AspNetCore.StaticWebAssets.Tasks; using System.Text.Json; using System.IO.Compression; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; -public class StaticWebAssetsContentFingerprintingIntegrationTest(ITestOutputHelper log) : AspNetSdkBaselineTest(log) +[TestClass] +public class StaticWebAssetsContentFingerprintingIntegrationTest : AspNetSdkBaselineTest { - [Fact] + [TestMethod] public void Build_FingerprintsContent_WhenEnabled() { var expectedManifest = LoadBuildManifest(); @@ -54,8 +61,8 @@ public void Build_FingerprintsContent_WhenEnabled() { "BlazorWasmMinimal", "_framework/blazor.webassembly.js", "_framework/blazor.webassembly#[.{fingerprint}].js", false, true } }; - [Theory] - [MemberData(nameof(OverrideHtmlAssetPlaceholdersData))] + [TestMethod] + [DynamicData(nameof(OverrideHtmlAssetPlaceholdersData))] public void Build_OverrideHtmlAssetPlaceholders(string testAsset, string scriptPath, string scriptPathWithFingerprintPattern, bool fingerprintUserJavascriptAssets, bool expectFingerprintOnScript) { ProjectDirectory = CreateAspNetSdkTestAsset(testAsset, identifier: $"{testAsset}_{fingerprintUserJavascriptAssets}_{expectFingerprintOnScript}"); @@ -72,7 +79,7 @@ public void Build_OverrideHtmlAssetPlaceholders(string testAsset, string scriptP AssertImportMapInHtml(indexHtmlPath, endpointsManifestPath, scriptPath, expectFingerprintOnScript: expectFingerprintOnScript, expectPreloadElement: testAsset == "VanillaWasm"); } - [Fact] + [TestMethod] public void Build_OverrideHtmlAssetPlaceholders_PreservesAdditionalEndpointDefinitions() { ProjectDirectory = CreateAspNetSdkTestAsset("VanillaWasm", identifier: nameof(Build_OverrideHtmlAssetPlaceholders_PreservesAdditionalEndpointDefinitions)); @@ -88,8 +95,8 @@ public void Build_OverrideHtmlAssetPlaceholders_PreservesAdditionalEndpointDefin AssertAdditionalEndpointDefinitionsExist(endpointsManifestPath); } - [Theory] - [MemberData(nameof(OverrideHtmlAssetPlaceholdersData))] + [TestMethod] + [DynamicData(nameof(OverrideHtmlAssetPlaceholdersData))] public void Publish_OverrideHtmlAssetPlaceholders(string testAsset, string scriptPath, string scriptPathWithFingerprintPattern, bool fingerprintUserJavascriptAssets, bool expectFingerprintOnScript) { ProjectDirectory = CreateAspNetSdkTestAsset(testAsset, identifier: $"{testAsset}_{fingerprintUserJavascriptAssets}_{expectFingerprintOnScript}"); @@ -108,7 +115,7 @@ public void Publish_OverrideHtmlAssetPlaceholders(string testAsset, string scrip AssertImportMapInHtml(indexHtmlOutputPath, endpointsManifestPath, scriptPath, expectFingerprintOnScript: expectFingerprintOnScript, expectPreloadElement: testAsset == "VanillaWasm", assertHtmlCompressed: true); } - [Fact] + [TestMethod] public void Publish_OverrideHtmlAssetPlaceholders_PreservesAdditionalEndpointDefinitions() { ProjectDirectory = CreateAspNetSdkTestAsset("VanillaWasm", identifier: nameof(Publish_OverrideHtmlAssetPlaceholders_PreservesAdditionalEndpointDefinitions)); diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsIntegrationTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsIntegrationTest.cs index c13c8b2d5c6b..2a1549f8a0c0 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsIntegrationTest.cs @@ -1,19 +1,25 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Reflection; using Microsoft.AspNetCore.StaticWebAssets.Tasks; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { + [TestClass] public class StaticWebAssetsIntegrationTest : AspNetSdkBaselineTest { - public StaticWebAssetsIntegrationTest(ITestOutputHelper log) : base(log, GenerateBaselines) { } // Build Standalone project - [Fact] + [TestMethod] public void Build_GeneratesJsonManifestAndCopiesItToOutputFolder() { var expectedManifest = LoadBuildManifest(); @@ -41,7 +47,7 @@ public void Build_GeneratesJsonManifestAndCopiesItToOutputFolder() AssertBuildAssets(manifest1, outputPath, intermediateOutputPath); } - [Fact] + [TestMethod] public void Build_Can_DisableAssetCaching() { var expectedManifest = LoadBuildManifest(); @@ -80,7 +86,7 @@ public void Build_Can_DisableAssetCaching() AssertBuildAssets(manifest1, outputPath, intermediateOutputPath); } - [Fact] + [TestMethod] public void Build_DoesNotUpdateManifest_WhenHasNotChanged() { var testAsset = "RazorComponentApp"; @@ -126,7 +132,7 @@ public void Build_DoesNotUpdateManifest_WhenHasNotChanged() secondFinalFile.LastWriteTimeUtc.Should().Be(originalFile.LastWriteTimeUtc); } - [Fact] + [TestMethod] public void Build_UpdatesManifest_WhenFilesChange() { var testAsset = "RazorComponentApp"; @@ -194,7 +200,7 @@ public void Build_UpdatesManifest_WhenFilesChange() } // Rebuild - [Fact] + [TestMethod] public void Rebuild_RegeneratesJsonManifestAndCopiesItToOutputFolder() { var testAsset = "RazorComponentApp"; @@ -255,7 +261,7 @@ public void Rebuild_RegeneratesJsonManifestAndCopiesItToOutputFolder() } // Publish - [Fact] + [TestMethod] public void Publish_GeneratesPublishJsonManifestAndCopiesPublishAssets() { var testAsset = "RazorComponentApp"; @@ -289,7 +295,7 @@ public void Publish_GeneratesPublishJsonManifestAndCopiesPublishAssets() intermediateOutputPath); } - [Fact] + [TestMethod] public void Publish_PublishSingleFile_GeneratesPublishJsonManifestAndCopiesPublishAssets() { var expectedManifest = LoadBuildManifest(); @@ -327,7 +333,7 @@ public void Publish_PublishSingleFile_GeneratesPublishJsonManifestAndCopiesPubli intermediateOutputPath); } - [Fact] + [TestMethod] public void Publish_NoBuild_GeneratesPublishJsonManifestAndCopiesPublishAssets() { var expectedManifest = LoadBuildManifest(); @@ -394,7 +400,7 @@ public void Publish_NoBuild_GeneratesPublishJsonManifestAndCopiesPublishAssets() intermediateOutputPath); } - [Fact] + [TestMethod] public void Build_DeployOnBuild_GeneratesPublishJsonManifestAndCopiesPublishAssets() { var expectedManifest = LoadBuildManifest(); @@ -430,7 +436,7 @@ public void Build_DeployOnBuild_GeneratesPublishJsonManifestAndCopiesPublishAsse } // Clean - [Fact] + [TestMethod] public void Clean_RemovesManifestFrom_BuildAndIntermediateOutput() { var expectedManifest = LoadBuildManifest(); @@ -465,7 +471,7 @@ public void Clean_RemovesManifestFrom_BuildAndIntermediateOutput() new FileInfo(finalPath).Should().NotExist(); } - [Fact] + [TestMethod] public void Publish_WithExternalProjectReference_UpdatesAssets() { var testAsset = "RazorAppWithP2PReference"; @@ -520,7 +526,7 @@ public void Publish_WithExternalProjectReference_UpdatesAssets() intermediateOutputPath); } - [Fact] + [TestMethod] public void Build_WithExternalProjectReference_UpdatesAssets() { var testAsset = "RazorAppWithP2PReference"; @@ -574,7 +580,7 @@ public void Build_WithExternalProjectReference_UpdatesAssets() intermediateOutputPath); } - [Fact] + [TestMethod] public void Build_DoesNotFailToCompress_TwoAssetsWith_TheSameContent() { var expectedManifest = LoadBuildManifest(); @@ -619,10 +625,11 @@ public void Build_DoesNotFailToCompress_TwoAssetsWith_TheSameContent() } } - public class StaticWebAssetsAppWithPackagesIntegrationTest(ITestOutputHelper log) - : IsolatedNuGetPackageFolderAspNetSdkBaselineTest(log, nameof(StaticWebAssetsAppWithPackagesIntegrationTest)) + [TestClass] + public class StaticWebAssetsAppWithPackagesIntegrationTest : IsolatedNuGetPackageFolderAspNetSdkBaselineTest { - [Fact] + protected override string RestoreNugetPackagePath => nameof(StaticWebAssetsAppWithPackagesIntegrationTest); + [TestMethod] public void Build_Fails_WhenConflictingAssetsFoundBetweenAStaticWebAssetAndAFileInTheWebRootFolder() { var testAsset = "RazorAppWithPackageAndP2PReference"; @@ -640,7 +647,7 @@ public void Build_Fails_WhenConflictingAssetsFoundBetweenAStaticWebAssetAndAFile ExecuteCommand(build).Should().Fail(); } - [Fact] + [TestMethod] public void BuildProjectWithReferences_DeployOnBuild_GeneratesPublishJsonManifestAndCopiesPublishAssets() { var testAsset = "RazorAppWithPackageAndP2PReference"; @@ -681,7 +688,7 @@ public void BuildProjectWithReferences_DeployOnBuild_GeneratesPublishJsonManifes intermediateOutputPath); } - [Fact] + [TestMethod] public void BuildProjectWithReferences_GeneratesJsonManifestAndCopiesItToOutputFolder() { var testAsset = "RazorAppWithPackageAndP2PReference"; @@ -716,7 +723,7 @@ public void BuildProjectWithReferences_GeneratesJsonManifestAndCopiesItToOutputF intermediateOutputPath); } - [Fact] + [TestMethod] public void BuildProjectWithReferences_NoDependencies_GeneratesJsonManifestAndCopiesItToOutputFolder() { var testAsset = "RazorAppWithPackageAndP2PReference"; @@ -779,7 +786,7 @@ public void BuildProjectWithReferences_NoDependencies_GeneratesJsonManifestAndCo manifestContents.Should().Be(File.ReadAllText(finalPath)); } - [Fact] + [TestMethod] public void PublishProjectWithReferences_GeneratesPublishJsonManifestAndCopiesPublishAssets() { var testAsset = "RazorAppWithPackageAndP2PReference"; @@ -821,7 +828,7 @@ public void PublishProjectWithReferences_GeneratesPublishJsonManifestAndCopiesPu intermediateOutputPath); } - [Fact] + [TestMethod] public void PublishProjectWithReferences_PublishSingleFile_GeneratesPublishJsonManifestAndCopiesPublishAssets() { var testAsset = "RazorAppWithPackageAndP2PReference"; @@ -862,7 +869,7 @@ public void PublishProjectWithReferences_PublishSingleFile_GeneratesPublishJsonM intermediateOutputPath); } - [Fact] + [TestMethod] public void PublishProjectWithReferences_NoBuild_GeneratesPublishJsonManifestAndCopiesPublishAssets() { var testAsset = "RazorAppWithPackageAndP2PReference"; @@ -930,7 +937,7 @@ public void PublishProjectWithReferences_NoBuild_GeneratesPublishJsonManifestAnd intermediateOutputPath); } - [Fact] + [TestMethod] public void PublishProjectWithReferences_AppendTargetFrameworkToOutputPathFalse_GeneratesPublishJsonManifestAndCopiesPublishAssets() { var testAsset = "RazorAppWithPackageAndP2PReference"; diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsPackIntegrationTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsPackIntegrationTest.cs index a42564667788..368efd4987f7 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsPackIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/StaticWebAssetsPackIntegrationTest.cs @@ -3,12 +3,19 @@ #nullable disable +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + namespace Microsoft.NET.Sdk.StaticWebAssets.Tests { - public class StaticWebAssetsPackIntegrationTest(ITestOutputHelper log) - : IsolatedNuGetPackageFolderAspNetSdkBaselineTest(log, nameof(StaticWebAssetsPackIntegrationTest)) + [TestClass] + public class StaticWebAssetsPackIntegrationTest : IsolatedNuGetPackageFolderAspNetSdkBaselineTest { - [Fact] + protected override string RestoreNugetPackagePath => nameof(StaticWebAssetsPackIntegrationTest); + [TestMethod] public void Pack_FailsWhenStaticWebAssetsHaveConflictingPaths() { var testAsset = "PackageLibraryDirectDependency"; @@ -35,7 +42,7 @@ public void Pack_FailsWhenStaticWebAssetsHaveConflictingPaths() } // If you modify this test, make sure you also modify the test below this one to assert that things are not included as content. - [Fact] + [TestMethod] public void Pack_IncludesStaticWebAssets() { var testAsset = "PackageLibraryDirectDependency"; @@ -65,7 +72,7 @@ public void Pack_IncludesStaticWebAssets() }); } - [Fact] + [TestMethod] public void Pack_NoAssets_DoesNothing() { var testAsset = "PackageLibraryNoStaticAssets"; @@ -92,7 +99,7 @@ public void Pack_NoAssets_DoesNothing() }); } - [Fact] + [TestMethod] public void Pack_NoAssets_Multitargeting_DoesNothing() { var testAsset = "PackageLibraryNoStaticAssets"; @@ -126,7 +133,7 @@ public void Pack_NoAssets_Multitargeting_DoesNothing() }); } - [Fact] + [TestMethod] public void Pack_Incremental_IncludesStaticWebAssets() { var testAsset = "PackageLibraryDirectDependency"; @@ -161,7 +168,7 @@ public void Pack_Incremental_IncludesStaticWebAssets() }); } - [Fact] + [TestMethod] public void Pack_StaticWebAssets_WithoutFileExtension_AreCorrectlyPacked() { var testAsset = "PackageLibraryDirectDependency"; @@ -194,7 +201,7 @@ public void Pack_StaticWebAssets_WithoutFileExtension_AreCorrectlyPacked() }); } - [Fact] + [TestMethod] public void Pack_MultipleTargetFrameworks_Works() { var projectDirectory = SetupMultiTargetProject(); @@ -222,7 +229,7 @@ public void Pack_MultipleTargetFrameworks_Works() }); } - [Fact] + [TestMethod] public void Pack_MultipleTargetFrameworks_NoBuild_IncludesStaticWebAssets() { var projectDirectory = SetupMultiTargetProject(); @@ -253,7 +260,7 @@ public void Pack_MultipleTargetFrameworks_NoBuild_IncludesStaticWebAssets() }); } - [Fact] + [TestMethod] public void Pack_MultipleTargetFrameworks_NoBuild_DoesNotIncludeAssetsAsContent() { var projectDirectory = SetupMultiTargetProject(); @@ -281,7 +288,7 @@ public void Pack_MultipleTargetFrameworks_NoBuild_DoesNotIncludeAssetsAsContent( }); } - [Fact] + [TestMethod] public void Pack_MultipleTargetFrameworks_GeneratePackageOnBuild_IncludesStaticWebAssets() { var projectDirectory = SetupMultiTargetProject(); @@ -309,7 +316,7 @@ public void Pack_MultipleTargetFrameworks_GeneratePackageOnBuild_IncludesStaticW }); } - [Fact] + [TestMethod] public void Pack_MultipleTargetFrameworks_GeneratePackageOnBuild_DoesNotIncludeAssetsAsContent() { var projectDirectory = SetupMultiTargetProject(); @@ -334,7 +341,7 @@ public void Pack_MultipleTargetFrameworks_GeneratePackageOnBuild_DoesNotIncludeA }); } - [Fact] + [TestMethod] public void Pack_BeforeNet60_MultipleTargetFrameworks_WithScopedCss_IncludesAssetsAndProjectBundle() { var projectDirectory = SetupBeforeNet60ScopedCssProject(); @@ -368,7 +375,7 @@ public void Pack_BeforeNet60_MultipleTargetFrameworks_WithScopedCss_IncludesAsse }); } - [Fact] + [TestMethod] public void Pack_BeforeNet60_MultipleTargetFrameworks_WithScopedCss_DoesNotIncludeAssetsAsContent() { var projectDirectory = SetupBeforeNet60ScopedCssProject(); @@ -401,7 +408,7 @@ public void Pack_BeforeNet60_MultipleTargetFrameworks_WithScopedCss_DoesNotInclu }); } - [Fact] + [TestMethod] public void Pack_BeforeNet60_MultipleTargetFrameworks_NoBuild_WithScopedCss_IncludesAssetsAndProjectBundle() { var projectDirectory = SetupBeforeNet60ScopedCssProject(); @@ -440,7 +447,7 @@ public void Pack_BeforeNet60_MultipleTargetFrameworks_NoBuild_WithScopedCss_Incl }); } - [Fact] + [TestMethod] public void Pack_BeforeNet60_MultipleTargetFrameworks_NoBuild_WithScopedCss_DoesNotIncludeAssetsAsContent() { var projectDirectory = SetupBeforeNet60ScopedCssProject(); @@ -478,7 +485,7 @@ public void Pack_BeforeNet60_MultipleTargetFrameworks_NoBuild_WithScopedCss_Does }); } - [Fact] + [TestMethod] public void Pack_BeforeNet60_MultipleTargetFrameworks_GeneratePackageOnBuild_WithScopedCss_IncludesAssetsAndProjectBundle() { var projectDirectory = SetupBeforeNet60ScopedCssProject(); @@ -512,7 +519,7 @@ public void Pack_BeforeNet60_MultipleTargetFrameworks_GeneratePackageOnBuild_Wit }); } - [Fact] + [TestMethod] public void Pack_BeforeNet60_MultipleTargetFrameworks_GeneratePackageOnBuild_WithScopedCss_DoesNotIncludeAssetsAsContent() { var projectDirectory = SetupBeforeNet60ScopedCssProject(); @@ -545,7 +552,7 @@ public void Pack_BeforeNet60_MultipleTargetFrameworks_GeneratePackageOnBuild_Wit }); } - [Fact] + [TestMethod] public void Pack_Net50_WithScopedCss_IncludesAssetsAndProjectBundle() { var projectDirectory = SetupNet50ScopedCssProject(); @@ -579,7 +586,7 @@ public void Pack_Net50_WithScopedCss_IncludesAssetsAndProjectBundle() }); } - [Fact] + [TestMethod] public void Pack_Net50_WithScopedCss_DoesNotIncludeAssetsAsContent() { var projectDirectory = SetupNet50ScopedCssProject(); @@ -612,7 +619,7 @@ public void Pack_Net50_WithScopedCss_DoesNotIncludeAssetsAsContent() }); } - [Fact] + [TestMethod] public void Pack_Net50_NoBuild_WithScopedCss_IncludesAssetsAndProjectBundle() { var projectDirectory = SetupNet50ScopedCssProject(); @@ -651,7 +658,7 @@ public void Pack_Net50_NoBuild_WithScopedCss_IncludesAssetsAndProjectBundle() }); } - [Fact] + [TestMethod] public void Pack_Net50_NoBuild_WithScopedCss_DoesNotIncludeAssetsAsContent() { var projectDirectory = SetupNet50ScopedCssProject(); @@ -689,7 +696,7 @@ public void Pack_Net50_NoBuild_WithScopedCss_DoesNotIncludeAssetsAsContent() }); } - [Fact] + [TestMethod] public void Pack_Net50_GeneratePackageOnBuild_WithScopedCss_IncludesAssetsAndProjectBundle() { var projectDirectory = SetupNet50ScopedCssProject(); @@ -723,7 +730,7 @@ public void Pack_Net50_GeneratePackageOnBuild_WithScopedCss_IncludesAssetsAndPro }); } - [Fact] + [TestMethod] public void Pack_Net50_GeneratePackageOnBuild_WithScopedCss_DoesNotIncludeAssetsAsContent() { var projectDirectory = SetupNet50ScopedCssProject(); @@ -756,7 +763,7 @@ public void Pack_Net50_GeneratePackageOnBuild_WithScopedCss_DoesNotIncludeAssets }); } - [Fact] + [TestMethod] public void Pack_MultipleTargetFrameworks_WithScopedCssAndJsModules_IncludesAssetsAndProjectBundle() { var testAsset = "PackageLibraryTransitiveDependency"; @@ -832,7 +839,7 @@ This component is defined in the razorclasslibrarypack library. }); } - [Fact] + [TestMethod] public void Pack_Incremental_MultipleTargetFrameworks_WithScopedCssAndJsModules_IncludesAssetsAndProjectBundle() { var testAsset = "PackageLibraryTransitiveDependency"; @@ -910,7 +917,7 @@ This component is defined in the razorclasslibrarypack library. }); } - [Fact] + [TestMethod] public void Pack_MultipleTargetFrameworks_WithScopedCssAndJsModules_DoesNotIncludeApplicationBundleNorModulesManifest() { var testAsset = "PackageLibraryTransitiveDependency"; @@ -976,7 +983,7 @@ This component is defined in the razorclasslibrarypack library. }); } - [Fact] + [TestMethod] public void Pack_MultipleTargetFrameworks_DoesNotIncludeAssetsAsContent() { var testAsset = "PackageLibraryDirectDependency"; @@ -1014,7 +1021,7 @@ public void Pack_MultipleTargetFrameworks_DoesNotIncludeAssetsAsContent() }); } - [Fact] + [TestMethod] public void Pack_DoesNotInclude_TransitiveBundleOrScopedCssAsStaticWebAsset() { var testAsset = "PackageLibraryDirectDependency"; @@ -1039,7 +1046,7 @@ public void Pack_DoesNotInclude_TransitiveBundleOrScopedCssAsStaticWebAsset() }); } - [Fact] + [TestMethod] public void Pack_DoesNotIncludeStaticWebAssetsAsContent() { var testAsset = "PackageLibraryDirectDependency"; @@ -1071,7 +1078,7 @@ public void Pack_DoesNotIncludeStaticWebAssetsAsContent() }); } - [Fact] + [TestMethod] public void Pack_NoBuild_IncludesStaticWebAssets() { var testAsset = "PackageLibraryDirectDependency"; @@ -1102,7 +1109,7 @@ public void Pack_NoBuild_IncludesStaticWebAssets() }); } - [Fact] + [TestMethod] public void Pack_NoBuild_DoesNotIncludeFilesAsContent() { var testAsset = "PackageLibraryDirectDependency"; @@ -1131,7 +1138,7 @@ public void Pack_NoBuild_DoesNotIncludeFilesAsContent() }); } - [Fact] + [TestMethod] public void Pack_DoesNotIncludeAnyCustomPropsFiles_WhenNoStaticAssetsAreAvailable() { var testAsset = "RazorComponentLibrary"; @@ -1155,7 +1162,7 @@ public void Pack_DoesNotIncludeAnyCustomPropsFiles_WhenNoStaticAssetsAreAvailabl }); } - [Fact] + [TestMethod] public void Pack_Incremental_DoesNotRegenerateCacheAndPropsFiles() { var testAsset = "PackageLibraryTransitiveDependency"; @@ -1198,11 +1205,11 @@ public void Pack_Incremental_DoesNotRegenerateCacheAndPropsFiles() foreach (var file in thumbPrintFiles) { var thumbprint = FileThumbPrint.Create(file); - Assert.Equal(thumbPrints[file], thumbprint); + Assert.AreEqual(thumbPrints[file], thumbprint); } } - [Fact] + [TestMethod] public void Build_StaticWebAssets_GeneratePackageOnBuild_PacksStaticWebAssets() { var testAsset = "PackageLibraryDirectDependency"; @@ -1234,7 +1241,7 @@ public void Build_StaticWebAssets_GeneratePackageOnBuild_PacksStaticWebAssets() }); } - [Fact] + [TestMethod] public void Build_StaticWebAssets_GeneratePackageOnBuild_DoesNotIncludeAssetsAsContent() { var testAsset = "PackageLibraryDirectDependency"; diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/TheoryData.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/TheoryData.cs new file mode 100644 index 000000000000..bd239168a0b0 --- /dev/null +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/TheoryData.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Generic; + +namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; + +public class TheoryData : List +{ + public void Add(T1 item1) => Add([item1]); +} + +public class TheoryData : List +{ + public void Add(T1 item1, T2 item2) => Add([item1, item2]); +} + +public class TheoryData : List +{ + public void Add(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5) => Add([item1, item2, item3, item4, item5]); +} diff --git a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/TypeScriptIntegrationTest.cs b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/TypeScriptIntegrationTest.cs index 7b3860d4647a..f2254d723c4e 100644 --- a/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/TypeScriptIntegrationTest.cs +++ b/test/Microsoft.NET.Sdk.StaticWebAssets.Tests/TypeScriptIntegrationTest.cs @@ -5,20 +5,28 @@ using System.Reflection; using Microsoft.AspNetCore.StaticWebAssets.Tasks; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Utilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.NET.Sdk.StaticWebAssets.Tests; +[TestClass] public class TypeScriptIntegrationTest : IsolatedNuGetPackageFolderAspNetSdkBaselineTest { + protected override string RestoreNugetPackagePath => nameof(TypeScriptIntegrationTest); + public string TypeScriptMSBuildPackageVersion { get; } - public TypeScriptIntegrationTest(ITestOutputHelper log) : base(log, nameof(TypeScriptIntegrationTest)) + public TypeScriptIntegrationTest() { var testAssemblyMetadata = TestAssembly.GetCustomAttributes(); TypeScriptMSBuildPackageVersion = testAssemblyMetadata.SingleOrDefault(a => a.Key == "MicrosoftTypeScriptMSBuildPackageVersion")?.Value ?? "5.9.3"; } - [Fact] + [TestMethod] public void Build_RegistersTypeScriptOutputsAsStaticWebAssets() { var testAsset = "RazorClassLibrary"; @@ -42,7 +50,7 @@ public void Build_RegistersTypeScriptOutputsAsStaticWebAssets() buildManifest.Assets.Should().Contain(a => a.RelativePath.EndsWith("app.js")); } - [Fact] + [TestMethod] public void Build_TypeScriptOutputsAreProperlyCompressed() { var testAsset = "RazorClassLibrary"; @@ -71,7 +79,7 @@ public void Build_TypeScriptOutputsAreProperlyCompressed() buildManifest.Assets.Should().Contain(a => a.RelativePath.EndsWith("app.js.gz") || a.RelativePath.EndsWith("app.js.br")); } - [Fact] + [TestMethod] public void Rebuild_SucceedsWithTypeScriptOutputs() { var testAsset = "RazorClassLibrary"; @@ -98,7 +106,7 @@ public void Rebuild_SucceedsWithTypeScriptOutputs() buildManifest.Assets.Should().Contain(a => a.RelativePath.EndsWith("app.js")); } - [Fact] + [TestMethod] public async Task Build_IncrementalBuild_WorksCorrectly() { var testAsset = "RazorClassLibrary"; @@ -116,7 +124,7 @@ public async Task Build_IncrementalBuild_WorksCorrectly() var firstBuildManifestTime = File.GetLastWriteTime(manifestPath); // Wait a bit and do incremental build - await Task.Delay(100, TestContext.Current.CancellationToken); + await Task.Delay(100, TestContext.CancellationToken); build = CreateBuildCommand(ProjectDirectory); ExecuteCommand(build).Should().Pass(); @@ -126,7 +134,7 @@ public async Task Build_IncrementalBuild_WorksCorrectly() secondBuildManifestTime.Should().Be(firstBuildManifestTime); } - [Fact] + [TestMethod] public void Build_ModifyTypeScriptFile_UpdatesStaticWebAssets() { var testAsset = "RazorClassLibrary"; @@ -154,7 +162,7 @@ public void Build_ModifyTypeScriptFile_UpdatesStaticWebAssets() File.ReadAllText(jsFilePath).Should().Contain("Modified"); } - [Fact] + [TestMethod] public void Publish_IncludesTypeScriptOutputs() { var testAsset = "RazorClassLibrary"; @@ -175,7 +183,7 @@ public void Publish_IncludesTypeScriptOutputs() publishManifest.Assets.Should().Contain(a => a.RelativePath.EndsWith("app.js")); } - [Fact] + [TestMethod] public void Clean_ThenBuild_SucceedsWithTypeScriptOutputs() { var testAsset = "RazorClassLibrary"; @@ -207,7 +215,7 @@ public void Clean_ThenBuild_SucceedsWithTypeScriptOutputs() buildManifest.Assets.Should().Contain(a => a.RelativePath.EndsWith("app.js")); } - [Fact] + [TestMethod] public void Build_TypeScriptDisabled_DoesNotRegisterAssets() { var testAsset = "RazorClassLibrary";