diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DesignTimeNodeWriterTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DesignTimeNodeWriterTest.cs
index b974231f2d5..d34c08ea4b9 100644
--- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DesignTimeNodeWriterTest.cs
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DesignTimeNodeWriterTest.cs
@@ -493,7 +493,7 @@ Render Children
ignoreLineEndingDifferences: true);
}
- [ConditionalTheory(Is.Windows)]
+ [OSSkipConditionTheory(new[] { "Linux", "OSX" })]
[InlineData(@"test.cshtml", @"test.cshtml")]
[InlineData(@"pages/test.cshtml", @"pages\test.cshtml")]
[InlineData(@"pages\test.cshtml", @"pages\test.cshtml")]
@@ -540,7 +540,7 @@ public void LinePragma_Is_Adjusted_On_Windows(string fileName, string expectedFi
ignoreLineEndingDifferences: true);
}
- [ConditionalTheory(Is.Windows)]
+ [OSSkipConditionTheory(new[] { "Linux", "OSX" })]
[InlineData(@"test.cshtml", @"test.cshtml")]
[InlineData(@"pages/test.cshtml", @"pages\test.cshtml")]
[InlineData(@"pages\test.cshtml", @"pages\test.cshtml")]
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorProjectFileSystemTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorProjectFileSystemTest.cs
index c4440c48784..9835901f4da 100644
--- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorProjectFileSystemTest.cs
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorProjectFileSystemTest.cs
@@ -6,6 +6,7 @@
using System;
using System.IO;
using System.Linq;
+using System.Runtime.InteropServices;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Language;
@@ -260,10 +261,15 @@ public void GetItem_ReturnsFileFromDisk()
Assert.Equal(Path.Combine("Views", "About", "About.cshtml"), item.RelativePhysicalPath);
}
- // "This test does not makes sense for case sensitive Operating Systems."
- [ConditionalFact(Is.Windows)]
+ [Fact]
public void GetItem_MismatchedCase_ReturnsFileFromDisk()
{
+ if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ // "This test does not makes sense for case sensitive Operating Systems."
+ return;
+ }
+
// Arrange
var filePath = "/Views/About/About.cshtml";
var lowerCaseTestFolder = TestFolder.ToLowerInvariant();
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Microsoft.AspNetCore.Razor.Language.Test.csproj b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Microsoft.AspNetCore.Razor.Language.Test.csproj
index 811cc7994aa..7927a8dd84e 100644
--- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Microsoft.AspNetCore.Razor.Language.Test.csproj
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Microsoft.AspNetCore.Razor.Language.Test.csproj
@@ -30,6 +30,7 @@
+
diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparer.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparer.cs
index 2cefe674961..70237b458f6 100644
--- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparer.cs
+++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparer.cs
@@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System;
-using Microsoft.AspNetCore.Razor.Utilities;
+using System.Runtime.InteropServices;
namespace Microsoft.CodeAnalysis.Razor;
@@ -14,7 +14,7 @@ public static StringComparer Instance
{
get
{
- return _instance ??= PlatformInformation.IsLinux
+ return _instance ??= RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
? StringComparer.Ordinal
: StringComparer.OrdinalIgnoreCase;
}
diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparison.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparison.cs
index 34062b5f1c6..a85b6fe2d65 100644
--- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparison.cs
+++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/FilePathComparison.cs
@@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System;
-using Microsoft.AspNetCore.Razor.Utilities;
+using System.Runtime.InteropServices;
namespace Microsoft.CodeAnalysis.Razor;
@@ -14,7 +14,7 @@ public static StringComparison Instance
{
get
{
- return _instance ??= PlatformInformation.IsLinux
+ return _instance ??= RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
? StringComparison.Ordinal
: StringComparison.OrdinalIgnoreCase;
}
diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeWriterExtensions.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeWriterExtensions.cs
index 3e87ef8f930..9c2c36d6991 100644
--- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeWriterExtensions.cs
+++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeWriterExtensions.cs
@@ -8,8 +8,8 @@
using System.Diagnostics;
using System.Globalization;
using System.Linq;
+using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
-using Microsoft.AspNetCore.Razor.Utilities;
namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration;
@@ -661,7 +661,7 @@ public static IDisposable BuildEnhancedLinePragma(this CodeWriter writer, Source
private static SourceSpan RemapFilePathIfNecessary(SourceSpan sourceSpan, CodeRenderingContext context)
{
- if (context.Options.RemapLinePragmaPathsOnWindows && PlatformInformation.IsWindows)
+ if (context.Options.RemapLinePragmaPathsOnWindows && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// ISSUE: https://github.com/dotnet/razor/issues/9108
// The razor tooling normalizes paths to be forward slash based, regardless of OS.
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultLanguageServerFeatureOptions.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultLanguageServerFeatureOptions.cs
index 8911f1c7425..cc165ade2b7 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultLanguageServerFeatureOptions.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/DefaultLanguageServerFeatureOptions.cs
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
-using Microsoft.AspNetCore.Razor.Utilities;
+using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis.Razor.Workspaces;
namespace Microsoft.AspNetCore.Razor.LanguageServer;
@@ -25,7 +25,8 @@ internal class DefaultLanguageServerFeatureOptions : LanguageServerFeatureOption
// Code action and rename paths in Windows VS Code need to be prefixed with '/':
// https://github.com/dotnet/razor/issues/8131
- public override bool ReturnCodeActionAndRenamePathsWithPrefixedSlash => PlatformInformation.IsWindows;
+ public override bool ReturnCodeActionAndRenamePathsWithPrefixedSlash
+ => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
public override bool ShowAllCSharpCodeActions => false;
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RemoteRazorProjectFileSystem.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RemoteRazorProjectFileSystem.cs
index a195a62898d..15211a880bf 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RemoteRazorProjectFileSystem.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/RemoteRazorProjectFileSystem.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis.Razor;
@@ -81,7 +82,7 @@ protected override string NormalizeAndEnsureValidPath(string path)
static bool IsPathRootedForPlatform(string path)
{
- if (PlatformInformation.IsWindows && path == "/")
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && path == "/")
{
// We have to special case windows and "/" because for some reason Path.IsPathRooted returns true on windows for a single "/" path.
return false;
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/FilePathNormalizer.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/FilePathNormalizer.cs
index ec419431db0..4d3a5e3db8f 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/FilePathNormalizer.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/FilePathNormalizer.cs
@@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Utilities;
internal static class FilePathNormalizer
{
- private static readonly Func s_charConverter = PlatformInformation.IsLinux
+ private static readonly Func s_charConverter = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
? c => c
: char.ToLowerInvariant;
@@ -223,7 +223,7 @@ private static (int start, int length) NormalizeCore(ReadOnlySpan source,
// Replace slashes in our normalized span.
NormalizeAndDedupeSlashes(destination, ref charsWritten);
- if (PlatformInformation.IsWindows &&
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
charsWritten > 1 &&
destination is ['/', ..] and not ['/', '/', ..])
{
diff --git a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/RazorProjectInfoFactory.cs b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/RazorProjectInfoFactory.cs
index 7eeb86d7ac1..bb518d231a5 100644
--- a/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/RazorProjectInfoFactory.cs
+++ b/src/Razor/src/Microsoft.AspNetCore.Razor.ProjectEngineHost/Utilities/RazorProjectInfoFactory.cs
@@ -5,6 +5,7 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.IO;
+using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language;
@@ -27,7 +28,7 @@ internal static class RazorProjectInfoFactory
static RazorProjectInfoFactory()
{
- s_stringComparison = PlatformInformation.IsLinux
+ s_stringComparison = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
? StringComparison.Ordinal
: StringComparison.OrdinalIgnoreCase;
}
diff --git a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/DynamicFiles/RazorDynamicFileInfoProvider.cs b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/DynamicFiles/RazorDynamicFileInfoProvider.cs
index 1e004d5bc65..96d41243c64 100644
--- a/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/DynamicFiles/RazorDynamicFileInfoProvider.cs
+++ b/src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/DynamicFiles/RazorDynamicFileInfoProvider.cs
@@ -6,13 +6,13 @@
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Diagnostics;
+using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.AspNetCore.Razor.Threading;
-using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
using Microsoft.CodeAnalysis.Razor;
@@ -305,7 +305,7 @@ public static string GetProjectSystemFilePath(Uri uri)
// however, it's the only way to get the correct file path for a document to map to a corresponding project
// system.
- if (PlatformInformation.IsWindows)
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// VSWin
return uri.GetAbsoluteOrUNCPath().Replace('/', '\\');
diff --git a/src/Razor/src/rzls/Program.cs b/src/Razor/src/rzls/Program.cs
index 5c83140c6c2..340d1491302 100644
--- a/src/Razor/src/rzls/Program.cs
+++ b/src/Razor/src/rzls/Program.cs
@@ -4,12 +4,12 @@
using System;
using System.Diagnostics;
using System.Linq;
+using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.LanguageServer.Extensions;
using Microsoft.AspNetCore.Razor.LanguageServer.Hosting;
using Microsoft.AspNetCore.Razor.Telemetry;
-using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis.Razor.Logging;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.Extensions.DependencyInjection;
@@ -30,10 +30,10 @@ public static async Task Main(string[] args)
if (args[i].Contains("debug", StringComparison.OrdinalIgnoreCase))
{
await Console.Error.WriteLineAsync($"Server started with process ID {Environment.ProcessId}").ConfigureAwait(true);
- if (PlatformInformation.IsWindows)
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Debugger.Launch() only works on Windows.
- Debugger.Launch();
+ _ = Debugger.Launch();
}
else
{
diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.LegacyEditor.Test/Microsoft.AspNetCore.Razor.ExternalAccess.LegacyEditor.Test.csproj b/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.LegacyEditor.Test/Microsoft.AspNetCore.Razor.ExternalAccess.LegacyEditor.Test.csproj
index d7e7c685f78..35907884879 100644
--- a/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.LegacyEditor.Test/Microsoft.AspNetCore.Razor.ExternalAccess.LegacyEditor.Test.csproj
+++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.LegacyEditor.Test/Microsoft.AspNetCore.Razor.ExternalAccess.LegacyEditor.Test.csproj
@@ -6,6 +6,7 @@
+
diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test.csproj b/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test.csproj
index 14814afcfa8..38b6311f6e2 100644
--- a/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test.csproj
+++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test/Microsoft.AspNetCore.Razor.ExternalAccess.RoslynWorkspace.Test.csproj
@@ -6,6 +6,7 @@
+
diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentPresentation/TextDocumentUriPresentationEndpointTests.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentPresentation/TextDocumentUriPresentationEndpointTests.cs
index ffdff508744..0e3e8509efd 100644
--- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentPresentation/TextDocumentUriPresentationEndpointTests.cs
+++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/DocumentPresentation/TextDocumentUriPresentationEndpointTests.cs
@@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.LanguageServer.DocumentPresentation;
public class TextDocumentUriPresentationEndpointTests(ITestOutputHelper testOutput) : LanguageServerTestBase(testOutput)
{
- [ConditionalFact(Is.Windows)]
+ [OSSkipConditionFact(["OSX", "Linux"])]
public async Task Handle_SimpleComponent_ReturnsResult()
{
// Arrange
@@ -83,7 +83,7 @@ await projectManager.UpdateAsync(updater =>
Assert.Equal("", documentEdits[0].Edits[0].NewText);
}
- [ConditionalFact(Is.Windows)]
+ [OSSkipConditionFact(["OSX", "Linux"])]
public async Task Handle_SimpleComponentWithChildFile_ReturnsResult()
{
// Arrange
@@ -148,7 +148,7 @@ await projectManager.UpdateAsync(updater =>
Assert.Equal("", documentEdits[0].Edits[0].NewText);
}
- [ConditionalFact(Is.Windows)]
+ [OSSkipConditionFact(["OSX", "Linux"])]
public async Task Handle_ComponentWithRequiredAttribute_ReturnsResult()
{
// Arrange
@@ -308,7 +308,7 @@ public async Task Handle_NotComponent_ReturnsNull()
Assert.Null(result);
}
- [ConditionalFact(Is.Windows)]
+ [OSSkipConditionFact(["OSX", "Linux"])]
public async Task Handle_ComponentWithNestedFiles_ReturnsResult()
{
// Arrange
diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/FindNodeTests.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/FindNodeTests.cs
index b9038c5dcba..5adc6703356 100644
--- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/FindNodeTests.cs
+++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/FindNodeTests.cs
@@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.
+using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Syntax;
using Microsoft.AspNetCore.Razor.Test.Common;
-using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis.Text;
using Xunit;
using Xunit.Abstractions;
@@ -63,7 +63,7 @@ protected override async Task OnInitializedAsync()
}
""";
- private static readonly string s_fetchDataContents = PlatformInformation.IsWindows
+ private static readonly string s_fetchDataContents = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? FetchDataContents
: FetchDataContents.Replace("\n", "\r\n");
diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Microsoft.AspNetCore.Razor.LanguageServer.Test.csproj b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Microsoft.AspNetCore.Razor.LanguageServer.Test.csproj
index 0a46c9e0354..685173189f4 100644
--- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Microsoft.AspNetCore.Razor.LanguageServer.Test.csproj
+++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Microsoft.AspNetCore.Razor.LanguageServer.Test.csproj
@@ -10,6 +10,7 @@
+
diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectSystem/IProjectSnapshotManagerExtensionsTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectSystem/IProjectSnapshotManagerExtensionsTest.cs
index e8335d1056d..c124083560f 100644
--- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectSystem/IProjectSnapshotManagerExtensionsTest.cs
+++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/ProjectSystem/IProjectSnapshotManagerExtensionsTest.cs
@@ -177,7 +177,7 @@ public async Task TryResolveAllProjects_MiscellaneousOwnerProjectWithOthers_Retu
AssertSnapshotsEqual(miscProject, project);
}
- [ConditionalFact(Is.Windows)]
+ [OSSkipConditionFact(["OSX", "Linux"])]
public async Task TryResolveAllProjects_OwnerProjectDifferentCasing_ReturnsTrue()
{
// Arrange
diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RemoteRazorProjectFileSystemTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RemoteRazorProjectFileSystemTest.cs
index e4a3f8751a5..919c0abb20a 100644
--- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RemoteRazorProjectFileSystemTest.cs
+++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RemoteRazorProjectFileSystemTest.cs
@@ -3,8 +3,8 @@
#nullable disable
+using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Razor.Test.Common;
-using Microsoft.AspNetCore.Razor.Utilities;
using Xunit;
using Xunit.Abstractions;
@@ -54,7 +54,7 @@ public void GetItem_RootedFilePath_DoesNotBelongToProject()
RemoteRazorProjectFileSystem fileSystem;
string documentFilePath;
- if (PlatformInformation.IsWindows)
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
fileSystem = new RemoteRazorProjectFileSystem(@"C:\path\to");
documentFilePath = @"C:\otherpath\to\file.cshtml";
diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Semantic/SemanticTokensTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Semantic/SemanticTokensTest.cs
index 20d7a817396..6ef88b7406d 100644
--- a/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Semantic/SemanticTokensTest.cs
+++ b/src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Semantic/SemanticTokensTest.cs
@@ -8,6 +8,7 @@
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
@@ -18,7 +19,6 @@
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.AspNetCore.Razor.Test.Common;
using Microsoft.AspNetCore.Razor.Test.Common.LanguageServer;
-using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
using Microsoft.CodeAnalysis.Razor.Protocol;
@@ -903,7 +903,7 @@ public void GetMappedCSharpRanges_MinimalRangeVsSmallDisjointRanges_DisjointRang
else
{
// Note that the expected lengths are different on Windows vs. Unix.
- var expectedCsharpRangeLength = PlatformInformation.IsWindows ? 945 : 911;
+ var expectedCsharpRangeLength = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 945 : 911;
Assert.True(codeDocument.TryGetMinimalCSharpRange(razorRange, out var csharpRange));
var textSpan = csharpSourceText.GetTextSpan(csharpRange);
Assert.Equal(expectedCsharpRangeLength, textSpan.Length);
@@ -1120,7 +1120,7 @@ private string GetBaselineFileContents(string baselineFileName)
var baselineContents = semanticFile.ReadAllText();
- if (!PlatformInformation.IsWindows)
+ if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
baselineContents = s_matchNewLines.Replace(baselineContents, "\n");
}
diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/FilePathNormalizerTest.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/FilePathNormalizerTest.cs
index dc7f80d3276..4f3215e65ca 100644
--- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/FilePathNormalizerTest.cs
+++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/FilePathNormalizerTest.cs
@@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Razor.ProjectEngineHost.Test;
public class FilePathNormalizerTest(ITestOutputHelper testOutput) : ToolingTestBase(testOutput)
{
- [ConditionalFact(Is.Windows)]
+ [OSSkipConditionFact(["OSX", "Linux"])]
public void Normalize_Windows_StripsPrecedingSlash()
{
// Arrange
@@ -24,7 +24,7 @@ public void Normalize_Windows_StripsPrecedingSlash()
Assert.Equal("c:/path/to/something", path);
}
- [ConditionalFact(Is.Windows)]
+ [OSSkipConditionFact(["OSX", "Linux"])]
public void Normalize_Windows_StripsPrecedingSlash_ShortPath()
{
// Arrange
@@ -141,7 +141,7 @@ public void NormalizeDirectory_EndsWithoutSlash()
Assert.Equal("C:/path/to/directory/", normalized);
}
- [ConditionalFact(Is.Windows)]
+ [OSSkipConditionFact(["OSX", "Linux"])]
public void NormalizeDirectory_Windows_HandlesSingleSlashDirectory()
{
// Arrange
@@ -261,7 +261,7 @@ public void Normalize_EmptyFilePath_ReturnsEmptyString()
Assert.Equal("/", normalized);
}
- [ConditionalFact(Is.Not.Windows)]
+ [OSSkipConditionFact(["Windows"])]
public void Normalize_NonWindows_AddsLeadingForwardSlash()
{
// Arrange
@@ -314,7 +314,7 @@ public void Normalize_ReplacesBackSlashesWithForwardSlashes()
Assert.Equal("C:/path/to/document.cshtml", normalized);
}
- [ConditionalTheory(Is.Windows)]
+ [OSSkipConditionTheory(["OSX", "Linux"])]
[InlineData(@"C:\path\to\document.cshtml")]
[InlineData(@"c:\path\to\document.cshtml")]
[InlineData("C:/path/to/document.cshtml")]
diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test.csproj b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test.csproj
index 9ceec560da4..19e59e95087 100644
--- a/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test.csproj
+++ b/src/Razor/test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test/Microsoft.AspNetCore.Razor.ProjectEngineHost.Test.csproj
@@ -6,6 +6,7 @@
+
diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/IntegrationTests/RazorToolingIntegrationTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/IntegrationTests/RazorToolingIntegrationTestBase.cs
index f59a6dece19..a4ff782e2bb 100644
--- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/IntegrationTests/RazorToolingIntegrationTestBase.cs
+++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/Language/IntegrationTests/RazorToolingIntegrationTestBase.cs
@@ -8,9 +8,9 @@
using System.IO;
using System.Linq;
using System.Reflection;
+using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Razor.PooledObjects;
using Microsoft.AspNetCore.Razor.Test.Common;
-using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Razor;
@@ -54,7 +54,7 @@ public RazorToolingIntegrationTestBase(ITestOutputHelper testOutput)
Configuration = RazorConfiguration.Default;
FileSystem = new VirtualRazorProjectFileSystem();
PathSeparator = Path.DirectorySeparatorChar.ToString();
- WorkingDirectory = PlatformInformation.IsWindows ? ArbitraryWindowsPath : ArbitraryMacLinuxPath;
+ WorkingDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ArbitraryWindowsPath : ArbitraryMacLinuxPath;
DefaultRootNamespace = "Test"; // Matches the default working directory
DefaultFileName = "TestComponent.cshtml";
@@ -316,7 +316,7 @@ protected static CSharpSyntaxTree Parse(string text, string path = null)
protected static void AssertSourceEquals(string expected, CompileToCSharpResult generated)
{
// Normalize the paths inside the expected result to match the OS paths
- if (!PlatformInformation.IsWindows)
+ if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var windowsPath = Path.Combine(ArbitraryWindowsPath, generated.CodeDocument.Source.RelativePath).Replace('/', '\\');
expected = expected.Replace(windowsPath, generated.CodeDocument.Source.FilePath);
diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/PathUtilities.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/PathUtilities.cs
index a7c074ee2a7..d98a1432973 100644
--- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/PathUtilities.cs
+++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/PathUtilities.cs
@@ -3,6 +3,7 @@
using System;
using System.IO;
+using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Razor.Utilities;
using Xunit;
@@ -16,7 +17,7 @@ public static string CreateRootedPath(params string[] parts)
if (!Path.IsPathRooted(result))
{
- result = PlatformInformation.IsWindows
+ result = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? @"C:\" + result
: "/" + result;
}
diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestProjectData.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestProjectData.cs
index 815e9588eea..32291f15f8d 100644
--- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestProjectData.cs
+++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common.Tooling/TestProjectData.cs
@@ -2,8 +2,8 @@
// Licensed under the MIT license. See License.txt in the project root for license information.
using System.IO;
+using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Razor.Language;
-using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
namespace Microsoft.AspNetCore.Razor.Test.Common;
@@ -18,7 +18,7 @@ internal static class TestProjectData
{
static TestProjectData()
{
- var baseDirectory = PlatformInformation.IsWindows ? @"c:\users\example\src" : "/home/example";
+ var baseDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "c:\\users\\example\\src" : "/home/example";
SomeProjectPath = Path.Combine(baseDirectory, "SomeProject");
var someProjectObjPath = Path.Combine(SomeProjectPath, "obj");
diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Microsoft.CodeAnalysis.Razor.Workspaces.Test.csproj b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Microsoft.CodeAnalysis.Razor.Workspaces.Test.csproj
index 36c2f7e6ac4..232456c3724 100644
--- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Microsoft.CodeAnalysis.Razor.Workspaces.Test.csproj
+++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Microsoft.CodeAnalysis.Razor.Workspaces.Test.csproj
@@ -7,6 +7,7 @@
+
diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectKeyTests.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectKeyTests.cs
index f62e0175a1d..ce5c210063c 100644
--- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectKeyTests.cs
+++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/ProjectSystem/ProjectKeyTests.cs
@@ -40,7 +40,7 @@ public void EqualityTests(string id1, string id2)
Assert.False(!key1.Equals((object)key2));
}
- [ConditionalTheory(Is.Windows)]
+ [OSSkipConditionTheory(new[] { "OSX", "Linux" })]
[InlineData(@"/c:/path/to/dir/", @"c:\path\to\dir")]
[InlineData(@"/c:\path/to\dir/", @"c:\path\to\dir")]
[InlineData(@"\path\to\dir\", @"path\to\dir")]
diff --git a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/UriExtensionsTest.cs b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/UriExtensionsTest.cs
index 6bad640a6c5..4c9cd9cc0b9 100644
--- a/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/UriExtensionsTest.cs
+++ b/src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/UriExtensionsTest.cs
@@ -16,7 +16,7 @@ public UriExtensionsTest(ITestOutputHelper testOutput)
{
}
- [ConditionalFact(Is.Windows)]
+ [OSSkipConditionFact(new[] { "OSX", "Linux" })]
public void GetAbsoluteOrUNCPath_AbsolutePath_ReturnsAbsolutePath()
{
// Arrange
@@ -29,7 +29,7 @@ public void GetAbsoluteOrUNCPath_AbsolutePath_ReturnsAbsolutePath()
Assert.Equal(uri.AbsolutePath, path);
}
- [ConditionalFact(Is.Windows)]
+ [OSSkipConditionFact(new[] { "OSX", "Linux" })]
public void GetAbsoluteOrUNCPath_AbsolutePath_HandlesPlusPaths()
{
// Arrange
@@ -42,7 +42,7 @@ public void GetAbsoluteOrUNCPath_AbsolutePath_HandlesPlusPaths()
Assert.Equal(uri.AbsolutePath, path);
}
- [ConditionalFact(Is.Windows)]
+ [OSSkipConditionFact(new[] { "OSX", "Linux" })]
public void GetAbsoluteOrUNCPath_AbsolutePath_HandlesSpacePaths()
{
// Arrange
@@ -55,8 +55,7 @@ public void GetAbsoluteOrUNCPath_AbsolutePath_HandlesSpacePaths()
Assert.Equal("c:/Some/path/to/file path.cshtml", path);
}
- [ConditionalTheory(Is.Windows)]
- [WorkItem("https://github.com/dotnet/razor/issues/9365")]
+ [OSSkipConditionTheory(new[] { "OSX", "Linux" }), WorkItem("https://github.com/dotnet/razor/issues/9365")]
[InlineData(@"git:/c%3A/path/to/dir/Index.cshtml", @"c:/_git_/path/to/dir/Index.cshtml")]
[InlineData(@"git:/c:/path%2Fto/dir/Index.cshtml?%7B%22p", @"c:/_git_/path/to/dir/Index.cshtml")]
[InlineData(@"git:/c:/path/to/dir/Index.cshtml", @"c:/_git_/path/to/dir/Index.cshtml")]
@@ -72,7 +71,7 @@ public void GetAbsoluteOrUNCPath_AbsolutePath_HandlesGitScheme(string filePath,
Assert.Equal(expected, path);
}
- [ConditionalTheory(Is.Windows)]
+ [OSSkipConditionTheory(new[] { "OSX", "Linux" })]
[InlineData(@"file:///c:/path/to/dir/Index.cshtml", @"c:/path/to/dir/Index.cshtml")]
[InlineData(@"file:///c:\path/to\dir/Index.cshtml", @"c:/path/to/dir/Index.cshtml")]
[InlineData(@"file:///C:\path\to\dir\Index.cshtml", @"C:/path/to/dir/Index.cshtml")]
@@ -130,8 +129,7 @@ public void GetAbsoluteOrUNCPath_UNCPath_HandlesSpacePaths()
Assert.Equal(@"\\some\path\to\file path.cshtml", path);
}
- [ConditionalTheory(Is.Not.Windows)]
- [WorkItem("https://github.com/dotnet/razor/issues/9365")]
+ [OSSkipConditionTheory(new[] { "Windows" }), WorkItem("https://github.com/dotnet/razor/issues/9365")]
[InlineData("git:///path/to/dir/Index.cshtml", "/_git_/path/to/dir/Index.cshtml")]
[InlineData("git:///path%2Fto/dir/Index.cshtml", "/_git_/path/to/dir/Index.cshtml")]
[InlineData("file:///path/to/dir/Index.cshtml", @"/path/to/dir/Index.cshtml")]
diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test.csproj b/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test.csproj
index 3c89a6a9ed9..5f66568e762 100644
--- a/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test.csproj
+++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test.csproj
@@ -8,6 +8,10 @@
+
+
+
+
diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/UriExtensionsTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/UriExtensionsTest.cs
index b27574a8d03..24987107c32 100644
--- a/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/UriExtensionsTest.cs
+++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServer.ContainedLanguage.Test/UriExtensionsTest.cs
@@ -17,7 +17,7 @@ public UriExtensionsTest(ITestOutputHelper testOutput)
{
}
- [ConditionalFact(Is.Windows)]
+ [OSSkipConditionFact(new[] { "OSX", "Linux" })]
public void GetAbsoluteOrUNCPath_AbsolutePath_ReturnsAbsolutePath()
{
// Arrange
@@ -30,7 +30,7 @@ public void GetAbsoluteOrUNCPath_AbsolutePath_ReturnsAbsolutePath()
Assert.Equal(uri.AbsolutePath, path);
}
- [ConditionalFact(Is.Windows)]
+ [OSSkipConditionFact(new[] { "OSX", "Linux" })]
public void GetAbsoluteOrUNCPath_AbsolutePath_HandlesPlusPaths()
{
// Arrange
@@ -43,7 +43,7 @@ public void GetAbsoluteOrUNCPath_AbsolutePath_HandlesPlusPaths()
Assert.Equal(uri.AbsolutePath, path);
}
- [ConditionalFact(Is.Windows)]
+ [OSSkipConditionFact(new[] { "OSX", "Linux" })]
public void GetAbsoluteOrUNCPath_AbsolutePath_HandlesSpacePaths()
{
// Arrange
diff --git a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorDocumentOptionsServiceTest.cs b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorDocumentOptionsServiceTest.cs
index 72570a90160..9e6c078dd94 100644
--- a/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorDocumentOptionsServiceTest.cs
+++ b/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorDocumentOptionsServiceTest.cs
@@ -3,12 +3,12 @@
using System.IO;
using System.Linq;
+using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.ProjectSystem;
using Microsoft.AspNetCore.Razor.Test.Common;
using Microsoft.AspNetCore.Razor.Test.Common.Workspaces;
-using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Options;
@@ -90,7 +90,7 @@ private static OptionKey GetIndentationSizeOptionKey(Document document)
// Adds the text to a ProjectSnapshot, generates code, and updates the workspace.
private Document InitializeDocument(SourceText sourceText)
{
- var baseDirectory = PlatformInformation.IsWindows ? @"c:\users\example\src" : "/home/example";
+ var baseDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "c:\\users\\example\\src" : "/home/example";
var hostProject = new HostProject(
Path.Combine(baseDirectory, "SomeProject", "SomeProject.csproj"), Path.Combine(baseDirectory, "SomeProject", "obj"), RazorConfiguration.Default, "SomeProject");
var hostDocument = new HostDocument(
diff --git a/src/Razor/test/OSSkipConditionFactAttribute.cs b/src/Razor/test/OSSkipConditionFactAttribute.cs
new file mode 100644
index 00000000000..1720cad03ca
--- /dev/null
+++ b/src/Razor/test/OSSkipConditionFactAttribute.cs
@@ -0,0 +1,52 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the MIT license. See License.txt in the project root for license information.
+
+using System;
+using System.Runtime.InteropServices;
+using Xunit;
+
+namespace Microsoft.AspNetCore.Razor;
+
+public class OSSkipConditionFactAttribute : FactAttribute
+{
+ ///
+ /// A that configures on the specified platforms.
+ ///
+ /// Valid values include WINDOWS, LINUX, OSX, and FREEBSD.
+ ///
+ public OSSkipConditionFactAttribute(string[] skippedPlatforms)
+ {
+ SetSkipIfNecessary(this, skippedPlatforms);
+ }
+
+ internal static void SetSkipIfNecessary(FactAttribute fact, string[] skippedPlatforms)
+ {
+ foreach (var platform in skippedPlatforms)
+ {
+ var osPlatform = platform switch
+ {
+ "Windows" => OSPlatform.Windows,
+ "Linux" => OSPlatform.Linux,
+ "OSX" => OSPlatform.OSX,
+#if NET
+ "FreeBSD" => OSPlatform.FreeBSD,
+#endif
+ _ => throw new NotSupportedException($"Unsupported platform: {platform}")
+ };
+
+ if (RuntimeInformation.IsOSPlatform(osPlatform))
+ {
+ fact.Skip = $"Ignored on {platform}";
+ break;
+ }
+ }
+ }
+}
+
+public class OSSkipConditionTheoryAttribute : TheoryAttribute
+{
+ public OSSkipConditionTheoryAttribute(string[] skippedPlatforms)
+ {
+ OSSkipConditionFactAttribute.SetSkipIfNecessary(this, skippedPlatforms);
+ }
+}
diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/ConditionalFactAttribute.cs b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/ConditionalFactAttribute.cs
deleted file mode 100644
index c025e3b34fa..00000000000
--- a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/ConditionalFactAttribute.cs
+++ /dev/null
@@ -1,192 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Collections.Frozen;
-using System.Collections.Generic;
-using Microsoft.AspNetCore.Razor.Utilities;
-using Xunit;
-
-namespace Microsoft.AspNetCore.Razor;
-
-///
-/// A that only executes if each of the given conditions are met.
-///
-///
-/// Conditions can be provided using the type. For example, -or-
-/// , .
-///
-public sealed class ConditionalFactAttribute : FactAttribute
-{
- public ConditionalFactAttribute(params string[] conditions)
- {
- if (!Conditions.AllTrue(conditions))
- {
- base.Skip = Reason ?? Conditions.GetSkipReason(conditions);
- }
- }
-
- ///
- /// This property exists to prevent users of
- /// from accidentally putting documentation in the property instead of Reason.
- /// Setting would cause the test to be unconditionally skip.
- ///
- [Obsolete($"{nameof(ConditionalFactAttribute)} should always use {nameof(Reason)} or {nameof(AlwaysSkip)}", error: true)]
- public new string Skip
- {
- get { return base.Skip; }
- set { base.Skip = value; }
- }
-
- ///
- /// Use to unconditionally skip a test.
- ///
- ///
- /// This is useful in the rare occasion when a conditional test needs to be skipped unconditionally.
- /// Typically, this is for a short term reason, such as working on a bug fix.
- ///
- public string AlwaysSkip
- {
- get { return base.Skip; }
- set { base.Skip = value; }
- }
-
- public string? Reason { get; set; }
-}
-
-///
-/// A that only executes if each of the given conditions are met.
-///
-///
-/// Conditions can be provided using the type. For example, -or-
-/// , .
-///
-public sealed class ConditionalTheoryAttribute : TheoryAttribute
-{
- public ConditionalTheoryAttribute(params string[] conditions)
- {
- if (!Conditions.AllTrue(conditions))
- {
- base.Skip = Reason ?? Conditions.GetSkipReason(conditions);
- }
- }
-
- ///
- /// This property exists to prevent users of
- /// from accidentally putting documentation in the property instead of Reason.
- /// Setting would cause the test to be unconditionally skip.
- ///
- [Obsolete($"{nameof(ConditionalFactAttribute)} should always use {nameof(Reason)} or {nameof(AlwaysSkip)}", error: true)]
- public new string Skip
- {
- get { return base.Skip; }
- set { base.Skip = value; }
- }
-
- ///
- /// Use to unconditionally skip a test.
- ///
- ///
- /// This is useful in the rare occasion when a conditional test needs to be skipped unconditionally.
- /// Typically, this is for a short term reason, such as working on a bug fix.
- ///
- public string AlwaysSkip
- {
- get { return base.Skip; }
- set { base.Skip = value; }
- }
-
- public string? Reason { get; set; }
-}
-
-public static class Is
-{
- ///
- /// Only execute if the current operating system platform is Windows.
- ///
- public const string Windows = nameof(Windows);
-
- ///
- /// Only execute if the current operating system platform is Linux.
- ///
- public const string Linux = nameof(Linux);
-
- ///
- /// Only execute if the current operating system platform is MacOS.
- ///
- public const string MacOS = nameof(MacOS);
-
- ///
- /// Only execute if the current operating system platform is FreeBSD.
- ///
- public const string FreeBSD = nameof(FreeBSD);
-
- public static class Not
- {
- ///
- /// Only execute if the current operating system platform is not Windows.
- ///
- public const string Windows = $"!{nameof(Windows)}";
-
- ///
- /// Only execute if the current operating system platform is Linux.
- ///
- public const string Linux = $"!{nameof(Linux)}";
-
- ///
- /// Only execute if the current operating system platform is not MacOS.
- ///
- public const string MacOS = $"!{nameof(MacOS)}";
-
- ///
- /// Only execute if the current operating system platform is not FreeBSD.
- ///
- public const string FreeBSD = $"!{nameof(FreeBSD)}";
- }
-}
-
-public static class Conditions
-{
- private static readonly FrozenDictionary> s_conditionMap = CreateConditionMap();
-
- private static FrozenDictionary> CreateConditionMap()
- {
- var map = new Dictionary>(StringComparer.OrdinalIgnoreCase);
-
- Add(Is.Windows, static () => PlatformInformation.IsWindows);
- Add(Is.Linux, static () => PlatformInformation.IsLinux);
- Add(Is.MacOS, static () => PlatformInformation.IsMacOS);
- Add(Is.FreeBSD, static () => PlatformInformation.IsFreeBSD);
-
- return map.ToFrozenDictionary();
-
- void Add(string name, Func predicate)
- {
- map.Add(name, predicate);
-
- // Add negated condition
- map.Add($"!{name}", () => !predicate());
- }
- }
-
- public static bool AllTrue(string[] conditions)
- {
- foreach (var condition in conditions)
- {
- if (!s_conditionMap.TryGetValue(condition, out var predicate))
- {
- throw new NotSupportedException($"Encountered unexpected condition: {condition}");
- }
-
- if (!predicate())
- {
- return false;
- }
- }
-
- return true;
- }
-
- public static string GetSkipReason(string[] conditions)
- => $"The following conditions are not all true: {string.Join(", ", conditions)}";
-}
diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorIntegrationTestBase.cs b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorIntegrationTestBase.cs
index 87828d221a0..8781a1ffafd 100644
--- a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorIntegrationTestBase.cs
+++ b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorIntegrationTestBase.cs
@@ -6,9 +6,9 @@
using System.Collections.Immutable;
using System.IO;
using System.Linq;
+using System.Runtime.InteropServices;
using System.Text;
using Microsoft.AspNetCore.Razor.Test.Common;
-using Microsoft.AspNetCore.Razor.Utilities;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Razor;
@@ -51,7 +51,7 @@ public RazorIntegrationTestBase()
Configuration = RazorConfiguration.Default;
FileSystem = new VirtualRazorProjectFileSystem();
PathSeparator = Path.DirectorySeparatorChar.ToString();
- WorkingDirectory = PlatformInformation.IsWindows ? ArbitraryWindowsPath : ArbitraryMacLinuxPath;
+ WorkingDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ArbitraryWindowsPath : ArbitraryMacLinuxPath;
DefaultRootNamespace = "Test"; // Matches the default working directory
DefaultFileName = "TestComponent.cshtml";
@@ -404,7 +404,7 @@ protected static CSharpSyntaxTree Parse(string text, CSharpParseOptions? parseOp
protected static void AssertSourceEquals(string expected, CompileToCSharpResult generated)
{
// Normalize the paths inside the expected result to match the OS paths
- if (!PlatformInformation.IsWindows)
+ if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var windowsPath = Path.Combine(ArbitraryWindowsPath, generated.CodeDocument.Source.RelativePath ?? "").Replace('/', '\\');
expected = expected.Replace(windowsPath, generated.CodeDocument.Source.FilePath);
diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared.Test/Microsoft.AspNetCore.Razor.Utilities.Shared.Test.csproj b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared.Test/Microsoft.AspNetCore.Razor.Utilities.Shared.Test.csproj
index 1f008203c9b..b10885404af 100644
--- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared.Test/Microsoft.AspNetCore.Razor.Utilities.Shared.Test.csproj
+++ b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared.Test/Microsoft.AspNetCore.Razor.Utilities.Shared.Test.csproj
@@ -12,7 +12,6 @@
-
diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Utilities/PlatformInformation.cs b/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Utilities/PlatformInformation.cs
deleted file mode 100644
index 29a6310f2ab..00000000000
--- a/src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/Utilities/PlatformInformation.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the MIT license. See License.txt in the project root for license information.
-
-using System.Runtime.InteropServices;
-
-namespace Microsoft.AspNetCore.Razor.Utilities;
-
-internal static class PlatformInformation
-{
- public static bool IsWindows { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
- public static bool IsLinux { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
- public static bool IsMacOS { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
-
-#if NET
- public static bool IsFreeBSD { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD);
-#else
- public static bool IsFreeBSD { get; } = false;
-#endif
-}