From 78dec7d2457827bb4c98495ee9b97ed1b5253357 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Jul 2026 13:40:42 +0000 Subject: [PATCH 01/19] Migrate test infrastructure from xUnit v2 to xUnit v3 - Update central package versions (XUnitV3Version=3.2.2, MicrosoftTestingPlatformVersion=1.9.1) - Set TestRunnerName=XUnitV3 and OutputType=Exe in test/Directory.Build.props - Replace Verify.Xunit with Verify.XunitV3, update Xunit.Combinatorial to 2.0.24 - Remove test/TestUtilities project and all references - Replace ConditionalFact/ConditionalTheory with Fact/Theory + Assert.Skip() - Replace SkipTestException with Assert.Skip() - Replace Xunit.Abstractions namespace with Xunit - Update ITestOutputHelper implementations for v3 interface - Update test TFM from net462 to net472 - Suppress xUnit1051 analyzer (CancellationToken recommendation) --- eng/Versions.props | 13 +-- eng/packages/Tests.props | 7 +- eng/xunit.runner.json | 4 +- test/Directory.Build.props | 6 +- test/Directory.Build.targets | 9 +- .../Unit/GeneratorTests.cs | 3 +- ...n.ContextualOptions.Generated.Tests.csproj | 2 +- ...crosoft.Gen.Logging.Generated.Tests.csproj | 2 +- ...Microsoft.Gen.Logging.HelperLibrary.csproj | 2 +- .../Unit/GeneratorTests.cs | 3 +- ...crosoft.Gen.Metrics.Generated.Tests.csproj | 2 +- .../Unit/GeneratorTests.cs | 3 +- test/Libraries/Directory.Build.props | 2 +- .../FakeCertificateFactoryTests.cs | 13 +-- .../Microsoft.AspNetCore.Testing.Tests.csproj | 6 +- ...ft.Extensions.AI.Abstractions.Tests.csproj | 6 +- .../Utilities/AIJsonUtilitiesTests.cs | 7 +- .../AgentQualityEvaluatorTests.cs | 13 ++- ...ons.AI.Evaluation.Integration.Tests.csproj | 6 +- .../NLPEvaluatorTests.cs | 13 ++- .../QualityEvaluatorTests.cs | 13 ++- .../SafetyEvaluatorTests.cs | 27 +++--- .../DiskBased/PathValidationTests.cs | 56 ++++++----- .../EmbeddingTests.cs | 7 +- ...sions.AI.Evaluation.Reporting.Tests.csproj | 6 +- .../ResponseCacheTester.cs | 17 ++-- .../ResultStoreTester.cs | 17 ++-- .../ChatClientIntegrationTests.cs | 97 +++++++++---------- .../EmbeddingGeneratorIntegrationTests.cs | 17 ++-- ...ageGeneratingChatClientIntegrationTests.cs | 17 ++-- .../ImageGeneratorIntegrationTests.cs | 9 +- ...oft.Extensions.AI.Integration.Tests.csproj | 6 +- .../SpeechToTextClientIntegrationTests.cs | 11 +-- .../TextToSpeechClientIntegrationTests.cs | 15 ++- .../OllamaSharpChatClientIntegrationTests.cs | 13 ++- ...SharpEmbeddingGeneratorIntegrationTests.cs | 5 +- ...enAIAssistantChatClientIntegrationTests.cs | 5 +- .../OpenAIHostedFileClientIntegrationTests.cs | 25 +++-- .../OpenAIResponseClientIntegrationTests.cs | 71 +++++++------- ...penAITextToSpeechClientIntegrationTests.cs | 7 +- .../DistributedCacheTests.cs | 2 +- .../ExpirationTests.cs | 4 +- .../HybridCacheEventSourceTests.cs | 40 ++++---- .../L2Tests.cs | 2 +- .../LocalInvalidationTests.cs | 4 +- .../LogCollector.cs | 4 +- ...oft.Extensions.Caching.Hybrid.Tests.csproj | 3 +- .../PayloadTests.cs | 4 +- .../RedisTests.cs | 2 +- .../SizeTests.cs | 4 +- .../SqlServerTests.cs | 2 +- .../UnreliableL2Tests.cs | 4 +- ...soft.Extensions.DataIngestion.Tests.csproj | 6 +- .../Readers/DocumentReaderConformanceTests.cs | 17 ++-- .../Readers/MarkItDownConditionAttribute.cs | 9 +- .../Readers/MarkItDownReaderTests.cs | 7 +- .../Readers/MarkdownReaderTests.cs | 19 ++-- .../Linux/LinuxResourceHealthCheckTests.cs | 6 +- ...lthChecks.ResourceUtilization.Tests.csproj | 4 +- .../ResourceHealthCheckExtensionsTests.cs | 58 +++++------ .../Linux/AcceptanceTest.cs | 9 +- ...ResourceMonitoring.Kubernetes.Tests.csproj | 6 +- .../Linux/AcceptanceTest.cs | 43 ++++---- .../Linux/Disk/DiskStatsReaderTests.cs | 10 +- .../Linux/Disk/LinuxSystemDiskMetricsTests.cs | 9 +- .../Linux/LinuxNetworkMetricsTests.cs | 7 +- .../LinuxUtilizationParserCgroupV1Tests.cs | 43 ++++---- .../LinuxUtilizationParserCgroupV2Tests.cs | 67 +++++++------ .../Linux/LinuxUtilizationProviderTests.cs | 25 ++--- .../Linux/OSFileSystemTests.cs | 17 ++-- ...iagnostics.ResourceMonitoring.Tests.csproj | 6 +- .../ResourceMonitoringBuilderTests.cs | 14 ++- .../ResourceMonitoringExtensionsTests.cs | 58 ++++++----- .../Disk/WindowsDiskIoRatePerfCounterTests.cs | 13 ++- .../Disk/WindowsDiskIoTimePerfCounterTests.cs | 9 +- .../Windows/Disk/WindowsDiskMetricsTests.cs | 15 +-- .../Windows/MemoryInfoTests.cs | 12 ++- .../Windows/PerformanceCounterFactoryTests.cs | 12 ++- .../Windows/PerformanceCounterWrapperTests.cs | 12 ++- .../Windows/ProcessInfoTests.cs | 5 +- .../Windows/SystemInfoTests.cs | 12 ++- .../Windows/Tcp6TableInfoTests.cs | 15 +-- .../Windows/TcpTableInfoTests.cs | 17 ++-- .../Windows/WindowsNetworkMetricsTests.cs | 12 ++- .../Windows/WindowsSnapshotProviderTests.cs | 21 ++-- .../FakeLogCollectorTests.LogEnumeration.cs | 3 +- .../Logging/FakeLogCollectorTests.cs | 12 ++- .../Resolver/CancellationTests.cs | 2 +- .../Resolver/LoopbackDnsTestBase.cs | 2 +- .../Resolver/ResolveAddressesTests.cs | 2 +- .../Resolver/ResolveServiceTests.cs | 2 +- .../Resolver/RetryTests.cs | 2 +- .../Resolver/TcpFailoverTests.cs | 2 +- .../XunitLoggerFactoryExtensions.cs | 4 +- .../Infrastructure/DotNetNewCommand.cs | 4 +- .../MessageSinkTestOutputHelper.cs | 21 +++- .../TemplateExecutionTestBase.cs | 3 +- .../TemplateExecutionTestClassFixtureBase.cs | 3 +- .../Infrastructure/TestCommand.cs | 4 +- .../AIAgentWebAPIExecutionTests.cs | 1 - .../AIAgentWebAPISnapshotTests.cs | 1 - .../AIChatWebExecutionTests.cs | 6 +- .../AIChatWebSnapshotTests.cs | 3 +- ...osoft.Extensions.AI.Templates.Tests.csproj | 6 +- .../McpServerExecutionTests.cs | 3 +- .../McpServerSnapshotTests.cs | 3 +- test/Shared/Shared.Tests.csproj | 2 +- test/TestUtilities/TestUtilities.csproj | 21 ---- .../XUnit/ConditionalFactAttribute.cs | 16 --- .../XUnit/ConditionalFactDiscoverer.cs | 30 ------ .../XUnit/ConditionalTheoryAttribute.cs | 16 --- .../XUnit/ConditionalTheoryDiscoverer.cs | 95 ------------------ .../EnvironmentVariableConditionAttribute.cs | 86 ---------------- test/TestUtilities/XUnit/ITestCondition.cs | 13 --- .../XUnit/OSSkipConditionAttribute.cs | 69 ------------- test/TestUtilities/XUnit/OperatingSystems.cs | 16 --- test/TestUtilities/XUnit/SkipTestException.cs | 16 --- .../XUnit/SkippedFactTestCase.cs | 42 -------- test/TestUtilities/XUnit/SkippedTestCase.cs | 52 ---------- .../XUnit/SkippedTestMessageBus.cs | 44 --------- .../XUnit/SkippedTheoryTestCase.cs | 49 ---------- .../XUnit/TestMethodExtensions.cs | 35 ------- .../WORKAROUND_SkippedDataRowTestCase.cs | 88 ----------------- 123 files changed, 690 insertions(+), 1322 deletions(-) delete mode 100644 test/TestUtilities/TestUtilities.csproj delete mode 100644 test/TestUtilities/XUnit/ConditionalFactAttribute.cs delete mode 100644 test/TestUtilities/XUnit/ConditionalFactDiscoverer.cs delete mode 100644 test/TestUtilities/XUnit/ConditionalTheoryAttribute.cs delete mode 100644 test/TestUtilities/XUnit/ConditionalTheoryDiscoverer.cs delete mode 100644 test/TestUtilities/XUnit/EnvironmentVariableConditionAttribute.cs delete mode 100644 test/TestUtilities/XUnit/ITestCondition.cs delete mode 100644 test/TestUtilities/XUnit/OSSkipConditionAttribute.cs delete mode 100644 test/TestUtilities/XUnit/OperatingSystems.cs delete mode 100644 test/TestUtilities/XUnit/SkipTestException.cs delete mode 100644 test/TestUtilities/XUnit/SkippedFactTestCase.cs delete mode 100644 test/TestUtilities/XUnit/SkippedTestCase.cs delete mode 100644 test/TestUtilities/XUnit/SkippedTestMessageBus.cs delete mode 100644 test/TestUtilities/XUnit/SkippedTheoryTestCase.cs delete mode 100644 test/TestUtilities/XUnit/TestMethodExtensions.cs delete mode 100644 test/TestUtilities/XUnit/WORKAROUND_SkippedDataRowTestCase.cs diff --git a/eng/Versions.props b/eng/Versions.props index 2630919b053..2fcd8982884 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -216,15 +216,10 @@ 4.8.0 3.3.4 - - 2.9.3 - - 2.8.2 + + 3.2.2 + 3.1.5 + 1.9.1 9.7.0 0.43.0 diff --git a/eng/packages/Tests.props b/eng/packages/Tests.props index 9a13460ce10..5f80b404aa6 100644 --- a/eng/packages/Tests.props +++ b/eng/packages/Tests.props @@ -33,11 +33,8 @@ - - - - - + + diff --git a/eng/xunit.runner.json b/eng/xunit.runner.json index 826972feba6..93a90a659aa 100644 --- a/eng/xunit.runner.json +++ b/eng/xunit.runner.json @@ -1,5 +1,5 @@ { + "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", "diagnosticMessages": true, - "longRunningTestSeconds": 300, - "shadowCopy": false + "longRunningTestSeconds": 300 } diff --git a/test/Directory.Build.props b/test/Directory.Build.props index f886872fa3d..7749c5ddf79 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -2,7 +2,11 @@ false - $(NoWarn);RT0000 + $(NoWarn);RT0000;xUnit1051 + + XUnitV3 + + Exe diff --git a/test/Directory.Build.targets b/test/Directory.Build.targets index 8cddc800bac..fed303ed3fe 100644 --- a/test/Directory.Build.targets +++ b/test/Directory.Build.targets @@ -1,6 +1,11 @@ + + $(MSBuildThisFileDirectory)\..\eng\xunit.runner.json + $(MSBuildThisFileDirectory)\..\eng\xunit.runner.json + + @@ -8,10 +13,8 @@ - + - - diff --git a/test/Generators/Microsoft.Gen.ComplianceReports/Unit/GeneratorTests.cs b/test/Generators/Microsoft.Gen.ComplianceReports/Unit/GeneratorTests.cs index 28dbb80a36c..490ae645e16 100644 --- a/test/Generators/Microsoft.Gen.ComplianceReports/Unit/GeneratorTests.cs +++ b/test/Generators/Microsoft.Gen.ComplianceReports/Unit/GeneratorTests.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. using System; @@ -12,7 +12,6 @@ using Microsoft.Extensions.Logging; using Microsoft.Gen.Shared; using Xunit; -using Xunit.Abstractions; namespace Microsoft.Gen.ComplianceReports.Tests; diff --git a/test/Generators/Microsoft.Gen.ContextualOptions/Generated/Microsoft.Gen.ContextualOptions.Generated.Tests.csproj b/test/Generators/Microsoft.Gen.ContextualOptions/Generated/Microsoft.Gen.ContextualOptions.Generated.Tests.csproj index e99de5a9789..ce8265414c4 100644 --- a/test/Generators/Microsoft.Gen.ContextualOptions/Generated/Microsoft.Gen.ContextualOptions.Generated.Tests.csproj +++ b/test/Generators/Microsoft.Gen.ContextualOptions/Generated/Microsoft.Gen.ContextualOptions.Generated.Tests.csproj @@ -6,7 +6,7 @@ $(TestNetCoreTargetFrameworks) - $(TestNetCoreTargetFrameworks)$(ConditionalNet462) + $(TestNetCoreTargetFrameworks);net472 true true true diff --git a/test/Generators/Microsoft.Gen.Logging/Generated/Microsoft.Gen.Logging.Generated.Tests.csproj b/test/Generators/Microsoft.Gen.Logging/Generated/Microsoft.Gen.Logging.Generated.Tests.csproj index d4a72e9e371..d0b98af9cb4 100644 --- a/test/Generators/Microsoft.Gen.Logging/Generated/Microsoft.Gen.Logging.Generated.Tests.csproj +++ b/test/Generators/Microsoft.Gen.Logging/Generated/Microsoft.Gen.Logging.Generated.Tests.csproj @@ -6,7 +6,7 @@ $(TestNetCoreTargetFrameworks) - $(TestNetCoreTargetFrameworks)$(ConditionalNet462) + $(TestNetCoreTargetFrameworks);net472 true true true diff --git a/test/Generators/Microsoft.Gen.Logging/HelperLibrary/Microsoft.Gen.Logging.HelperLibrary.csproj b/test/Generators/Microsoft.Gen.Logging/HelperLibrary/Microsoft.Gen.Logging.HelperLibrary.csproj index 0f3e6d3bedf..65fa2220f3a 100644 --- a/test/Generators/Microsoft.Gen.Logging/HelperLibrary/Microsoft.Gen.Logging.HelperLibrary.csproj +++ b/test/Generators/Microsoft.Gen.Logging/HelperLibrary/Microsoft.Gen.Logging.HelperLibrary.csproj @@ -6,7 +6,7 @@ $(TestNetCoreTargetFrameworks) - $(TestNetCoreTargetFrameworks)$(ConditionalNet462) + $(TestNetCoreTargetFrameworks);net472 diff --git a/test/Generators/Microsoft.Gen.MetadataExtractor/Unit/GeneratorTests.cs b/test/Generators/Microsoft.Gen.MetadataExtractor/Unit/GeneratorTests.cs index 6d7f9a23c61..18554b46b91 100644 --- a/test/Generators/Microsoft.Gen.MetadataExtractor/Unit/GeneratorTests.cs +++ b/test/Generators/Microsoft.Gen.MetadataExtractor/Unit/GeneratorTests.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. using System; @@ -15,7 +15,6 @@ using Microsoft.Extensions.Logging; using Microsoft.Gen.Shared; using Xunit; -using Xunit.Abstractions; namespace Microsoft.Gen.MetadataExtractor.Unit.Tests; diff --git a/test/Generators/Microsoft.Gen.Metrics/Generated/Microsoft.Gen.Metrics.Generated.Tests.csproj b/test/Generators/Microsoft.Gen.Metrics/Generated/Microsoft.Gen.Metrics.Generated.Tests.csproj index 114e45e0df7..198869c8205 100644 --- a/test/Generators/Microsoft.Gen.Metrics/Generated/Microsoft.Gen.Metrics.Generated.Tests.csproj +++ b/test/Generators/Microsoft.Gen.Metrics/Generated/Microsoft.Gen.Metrics.Generated.Tests.csproj @@ -6,7 +6,7 @@ $(TestNetCoreTargetFrameworks) - $(TestNetCoreTargetFrameworks)$(ConditionalNet462) + $(TestNetCoreTargetFrameworks);net472 true true $(NoWarn);IDE0161;S1144 diff --git a/test/Generators/Microsoft.Gen.MetricsReports/Unit/GeneratorTests.cs b/test/Generators/Microsoft.Gen.MetricsReports/Unit/GeneratorTests.cs index f432257b111..55ee834ee31 100644 --- a/test/Generators/Microsoft.Gen.MetricsReports/Unit/GeneratorTests.cs +++ b/test/Generators/Microsoft.Gen.MetricsReports/Unit/GeneratorTests.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. using System; @@ -14,7 +14,6 @@ using Microsoft.Extensions.Diagnostics.Metrics; using Microsoft.Gen.Shared; using Xunit; -using Xunit.Abstractions; namespace Microsoft.Gen.MetricsReports.Test; diff --git a/test/Libraries/Directory.Build.props b/test/Libraries/Directory.Build.props index d64d3a34c2c..1791b6ae272 100644 --- a/test/Libraries/Directory.Build.props +++ b/test/Libraries/Directory.Build.props @@ -3,6 +3,6 @@ $(TestNetCoreTargetFrameworks) - $(TestNetCoreTargetFrameworks)$(ConditionalNet462) + $(TestNetCoreTargetFrameworks);net472 diff --git a/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs b/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs index 1da6dc74ddc..b8aab2bd227 100644 --- a/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs +++ b/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs @@ -1,10 +1,9 @@ -// 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; using System.Linq; using System.Security.Cryptography.X509Certificates; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.AspNetCore.Testing.Test; @@ -23,19 +22,21 @@ public void Create_CreatesCertificate() Assert.False(certificate.Extensions.OfType().Single().Critical); } - [ConditionalTheory] - [OSSkipCondition(OperatingSystems.Linux)] + [Theory] [InlineData(false)] [InlineData(true)] public void GenerateRsa_RunsOnWindows_GeneratesRsa(bool runsOnWindows) { + if (OperatingSystem.IsLinux()) Assert.Skip("Skipped on Linux"); + Assert.NotNull(FakeSslCertificateFactory.GenerateRsa(runsOnWindows)); } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Windows)] + [Fact] public void GenerateRsa_DoesNotRunOnWindows_GeneratesRsa() { + if (OperatingSystem.IsWindows()) Assert.Skip("Skipped on Windows"); + Assert.NotNull(FakeSslCertificateFactory.GenerateRsa(runsOnWindows: false)); } } diff --git a/test/Libraries/Microsoft.AspNetCore.Testing.Tests/Microsoft.AspNetCore.Testing.Tests.csproj b/test/Libraries/Microsoft.AspNetCore.Testing.Tests/Microsoft.AspNetCore.Testing.Tests.csproj index 11d60ebbaba..c6169aa3379 100644 --- a/test/Libraries/Microsoft.AspNetCore.Testing.Tests/Microsoft.AspNetCore.Testing.Tests.csproj +++ b/test/Libraries/Microsoft.AspNetCore.Testing.Tests/Microsoft.AspNetCore.Testing.Tests.csproj @@ -1,4 +1,4 @@ - + Microsoft.AspNetCore.Testing.Test Unit tests for Microsoft.AspNetCore.Testing @@ -10,7 +10,5 @@ - - - + diff --git a/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Microsoft.Extensions.AI.Abstractions.Tests.csproj b/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Microsoft.Extensions.AI.Abstractions.Tests.csproj index 2a1dfe36c6d..a138907fcbc 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Microsoft.Extensions.AI.Abstractions.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Microsoft.Extensions.AI.Abstractions.Tests.csproj @@ -1,4 +1,4 @@ - + Microsoft.Extensions.AI Unit tests for Microsoft.Extensions.AI.Abstractions. @@ -36,7 +36,5 @@ - - - + diff --git a/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs b/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs index 606fdea9721..acaaee01077 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.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. using System; @@ -15,7 +15,6 @@ using System.Text.Json.Serialization.Metadata; using System.Threading; using Microsoft.Extensions.AI.JsonSchemaExporter; -using Microsoft.TestUtilities; using Xunit; #pragma warning disable SA1114 // parameter list should follow declaration @@ -648,7 +647,7 @@ public static void CreateJsonSchema_NullableEnum_IncludesTypeKeyword() AssertDeepEquals(expectedSchema, schema); } - [ConditionalFact] + [Fact] public static void CreateJsonSchema_IncorporatesTypesAndAnnotations_Net() { if (RuntimeInformation.FrameworkDescription.Contains(".NET Framework")) @@ -884,7 +883,7 @@ public static void CreateJsonSchema_IncorporatesTypesAndAnnotations_Net() // .NET Framework only has a subset of the available data annotation attributes. // .NET Standard doesn't have any (the M.E.AI.Abstractions library doesn't reference the additional package). - [ConditionalFact] + [Fact] public static void CreateJsonSchema_IncorporatesTypesAndAnnotations_NetFx() { if (!RuntimeInformation.FrameworkDescription.Contains(".NET Framework")) diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/AgentQualityEvaluatorTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/AgentQualityEvaluatorTests.cs index 238b805e867..6c730cf577c 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/AgentQualityEvaluatorTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/AgentQualityEvaluatorTests.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. using System; @@ -11,7 +11,6 @@ using Microsoft.Extensions.AI.Evaluation.Reporting; using Microsoft.Extensions.AI.Evaluation.Reporting.Storage; using Microsoft.Extensions.AI.Evaluation.Tests; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.AI.Evaluation.Integration.Tests; @@ -81,7 +80,7 @@ static AgentQualityEvaluatorTests() } } - [ConditionalFact] + [Fact] public async Task ToolDefinitionsAreNotNeededAndNotPassed() { SkipIfNotConfigured(); @@ -104,7 +103,7 @@ await _agentQualityReportingConfiguration.CreateScenarioRunAsync( Assert.True(result.TryGet(IntentResolutionEvaluator.IntentResolutionMetricName, out NumericMetric? _)); } - [ConditionalFact] + [Fact] public async Task ToolDefinitionsAreNotNeededButPassed() { SkipIfNotConfigured(); @@ -137,7 +136,7 @@ await scenarioRun.EvaluateAsync( Assert.True(result.TryGet(IntentResolutionEvaluator.IntentResolutionMetricName, out NumericMetric? _)); } - [ConditionalFact] + [Fact] public async Task ToolDefinitionsAreNeededButNotPassed() { SkipIfNotConfigured(); @@ -161,7 +160,7 @@ await _needsContextReportingConfiguration.CreateScenarioRunAsync( Assert.True(result.TryGet(IntentResolutionEvaluator.IntentResolutionMetricName, out NumericMetric? _)); } - [ConditionalFact] + [Fact] public async Task ToolDefinitionsAreNeededAndPassed() { SkipIfNotConfigured(); @@ -270,7 +269,7 @@ private static void SkipIfNotConfigured() { if (!Settings.Current.Configured) { - throw new SkipTestException("Test is not configured"); + Assert.Skip("Test is not configured"); } Assert.NotNull(_chatOptionsWithTools); diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/Microsoft.Extensions.AI.Evaluation.Integration.Tests.csproj b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/Microsoft.Extensions.AI.Evaluation.Integration.Tests.csproj index 579debd599f..9a5eb28d96e 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/Microsoft.Extensions.AI.Evaluation.Integration.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/Microsoft.Extensions.AI.Evaluation.Integration.Tests.csproj @@ -1,4 +1,4 @@ - + $(LatestTargetFramework) @@ -33,8 +33,6 @@ - - - + \ No newline at end of file diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/NLPEvaluatorTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/NLPEvaluatorTests.cs index 9cd593a647a..fd92ece1a76 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/NLPEvaluatorTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/NLPEvaluatorTests.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. using System; @@ -8,7 +8,6 @@ using Microsoft.Extensions.AI.Evaluation.NLP; using Microsoft.Extensions.AI.Evaluation.Reporting; using Microsoft.Extensions.AI.Evaluation.Reporting.Storage; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.AI.Evaluation.Integration.Tests; @@ -41,7 +40,7 @@ static NLPEvaluatorTests() } } - [ConditionalFact] + [Fact] public async Task ExactMatch() { SkipIfNotConfigured(); @@ -67,7 +66,7 @@ await _nlpReportingConfiguration.CreateScenarioRunAsync( Assert.True(result.TryGet(F1Evaluator.F1MetricName, out NumericMetric? _)); } - [ConditionalFact] + [Fact] public async Task PartialMatch() { SkipIfNotConfigured(); @@ -94,7 +93,7 @@ await _nlpReportingConfiguration.CreateScenarioRunAsync( Assert.True(result.TryGet(F1Evaluator.F1MetricName, out NumericMetric? _)); } - [ConditionalFact] + [Fact] public async Task Unmatched() { SkipIfNotConfigured(); @@ -120,7 +119,7 @@ await _nlpReportingConfiguration.CreateScenarioRunAsync( Assert.True(result.TryGet(F1Evaluator.F1MetricName, out NumericMetric? _)); } - [ConditionalFact] + [Fact] public async Task AdditionalContextIsNotPassed() { SkipIfNotConfigured(); @@ -151,7 +150,7 @@ private static void SkipIfNotConfigured() { if (!Settings.Current.Configured) { - throw new SkipTestException("Test is not configured"); + Assert.Skip("Test is not configured"); } Assert.NotNull(_nlpReportingConfiguration); diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/QualityEvaluatorTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/QualityEvaluatorTests.cs index fde342a4161..9017e4c874c 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/QualityEvaluatorTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/QualityEvaluatorTests.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. using System; @@ -10,7 +10,6 @@ using Microsoft.Extensions.AI.Evaluation.Reporting; using Microsoft.Extensions.AI.Evaluation.Reporting.Storage; using Microsoft.Extensions.AI.Evaluation.Tests; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.AI.Evaluation.Integration.Tests; @@ -74,7 +73,7 @@ static QualityEvaluatorTests() } } - [ConditionalFact] + [Fact] public async Task SampleSingleResponse() { SkipIfNotConfigured(); @@ -107,7 +106,7 @@ await _qualityReportingConfiguration.CreateScenarioRunAsync( Assert.True(result.TryGet(RelevanceEvaluator.RelevanceMetricName, out NumericMetric? _)); } - [ConditionalFact] + [Fact] public async Task SampleMultipleResponses() { SkipIfNotConfigured(); @@ -153,7 +152,7 @@ await _qualityReportingConfiguration.CreateScenarioRunAsync( #endif } - [ConditionalFact] + [Fact] public async Task AdditionalContextIsNotPassed() { SkipIfNotConfigured(); @@ -188,7 +187,7 @@ await _needsContextReportingConfiguration.CreateScenarioRunAsync( Assert.Null(retrieval.Context); } - [ConditionalFact] + [Fact] public async Task AdditionalContextIsPassed() { SkipIfNotConfigured(); @@ -284,7 +283,7 @@ private static void SkipIfNotConfigured() { if (!Settings.Current.Configured) { - throw new SkipTestException("Test is not configured"); + Assert.Skip("Test is not configured"); } Assert.NotNull(_chatOptions); diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/SafetyEvaluatorTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/SafetyEvaluatorTests.cs index 68b4a9d8ce0..1a47a82c3f9 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/SafetyEvaluatorTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/SafetyEvaluatorTests.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. using System; @@ -13,7 +13,6 @@ using Microsoft.Extensions.AI.Evaluation.Safety; using Microsoft.Extensions.AI.Evaluation.Tests; using Microsoft.Extensions.AI.Evaluation.Utilities; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.AI.Evaluation.Integration.Tests; @@ -154,7 +153,7 @@ static SafetyEvaluatorTests() } } - [ConditionalFact] + [Fact] public async Task EvaluateConversationWithSingleTurn_HubBasedProject() { SkipIfNotConfigured(); @@ -166,7 +165,7 @@ await _hubBasedContentSafetyReportingConfiguration.CreateScenarioRunAsync( await EvaluateConversationWithSingleTurn(scenarioRun); } - [ConditionalFact] + [Fact] public async Task EvaluateConversationWithSingleTurn_NonHubBasedProject() { SkipIfNotConfigured(); @@ -232,7 +231,7 @@ The distance varies due to the elliptical orbits of both planets. ReferenceEquals(context2, ungroundedAttributesContext)); } - [ConditionalFact] + [Fact] public async Task EvaluateConversationWithMultipleTurns_HubBasedProject() { SkipIfNotConfigured(); @@ -244,7 +243,7 @@ await _hubBasedContentSafetyReportingConfiguration.CreateScenarioRunAsync( await EvaluateConversationWithMultipleTurns(scenarioRun); } - [ConditionalFact] + [Fact] public async Task EvaluateConversationWithMultipleTurns_NonHubBasedProject() { SkipIfNotConfigured(); @@ -323,7 +322,7 @@ At its furthest (conjunction), it can be approximately 601 million miles away. ReferenceEquals(context2, ungroundedAttributesContext)); } - [ConditionalFact] + [Fact] public async Task EvaluateConversationWithImageInQuestion() { SkipIfNotConfigured(); @@ -359,7 +358,7 @@ await _imageContentSafetyReportingConfiguration.CreateScenarioRunAsync( Assert.True(result.TryGet(IndirectAttackEvaluator.IndirectAttackMetricName, out BooleanMetric? _)); } - [ConditionalFact] + [Fact] public async Task EvaluateConversationWithImageInAnswer() { SkipIfNotConfigured(); @@ -395,7 +394,7 @@ await _imageContentSafetyReportingConfiguration.CreateScenarioRunAsync( Assert.True(result.TryGet(IndirectAttackEvaluator.IndirectAttackMetricName, out BooleanMetric? _)); } - [ConditionalFact] + [Fact] public async Task EvaluateConversationWithImagesInMultipleTurns() { SkipIfNotConfigured(); @@ -444,7 +443,7 @@ await _imageContentSafetyReportingConfiguration.CreateScenarioRunAsync( Assert.True(result.TryGet(IndirectAttackEvaluator.IndirectAttackMetricName, out BooleanMetric? _)); } - [ConditionalFact] + [Fact] public async Task EvaluateConversationWithImagesAndTextInMultipleTurns() { SkipIfNotConfigured(); @@ -506,7 +505,7 @@ These distances are approximate and can vary slightly depending on the specific Assert.True(result.TryGet(IndirectAttackEvaluator.IndirectAttackMetricName, out BooleanMetric? _)); } - [ConditionalFact] + [Fact] public async Task EvaluateCodeCompletionWithSingleTurn() { SkipIfNotConfigured(); @@ -535,7 +534,7 @@ await _codeVulnerabilityReportingConfiguration.CreateScenarioRunAsync( Assert.True(result.TryGet(CodeVulnerabilityEvaluator.CodeVulnerabilityMetricName, out BooleanMetric? _)); } - [ConditionalFact] + [Fact] public async Task EvaluateCodeCompletionWithMultipleTurns() { SkipIfNotConfigured(); @@ -576,7 +575,7 @@ await _codeVulnerabilityReportingConfiguration.CreateScenarioRunAsync( Assert.True(result.TryGet(CodeVulnerabilityEvaluator.CodeVulnerabilityMetricName, out BooleanMetric? _)); } - [ConditionalFact] + [Fact] public async Task EvaluateSafetyAndQualityMetricsForSameConversation() { SkipIfNotConfigured(); @@ -624,7 +623,7 @@ private static void SkipIfNotConfigured() { if (!Settings.Current.Configured) { - throw new SkipTestException("Test is not configured"); + Assert.Skip("Test is not configured"); } Assert.NotNull(_chatOptions); diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/PathValidationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/PathValidationTests.cs index bcf7dceaa3d..38c39cd9e50 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/PathValidationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/PathValidationTests.cs @@ -6,7 +6,6 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.Extensions.AI.Evaluation.Reporting.Utilities; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.AI.Evaluation.Reporting.Tests; @@ -257,10 +256,11 @@ await Assert.ThrowsAsync(() => // EnsureWithinRoot – UNC paths (Windows only) // ────────────────────────────────────────────── - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] + [Fact] public void EnsureWithinRoot_UncPath_ChildPath_ReturnsResolved() { + if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + string root = @"\\server\share\data"; string child = @"\\server\share\data\sub\file.txt"; @@ -269,10 +269,11 @@ public void EnsureWithinRoot_UncPath_ChildPath_ReturnsResolved() Assert.Equal(Path.GetFullPath(child), result); } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] + [Fact] public void EnsureWithinRoot_UncPath_DifferentShare_Throws() { + if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + string root = @"\\server\share\data"; string other = @"\\server\share\other\file.txt"; @@ -280,10 +281,11 @@ public void EnsureWithinRoot_UncPath_DifferentShare_Throws() PathValidation.EnsureWithinRoot(root, other)); } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] + [Fact] public void EnsureWithinRoot_UncPath_DotDotEscapes_Throws() { + if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + string root = @"\\server\share\data"; string escaped = @"\\server\share\data\..\other"; @@ -291,10 +293,11 @@ public void EnsureWithinRoot_UncPath_DotDotEscapes_Throws() PathValidation.EnsureWithinRoot(root, escaped)); } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] + [Fact] public void EnsureWithinRoot_UncPath_SiblingWithPrefix_Throws() { + if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + string root = @"\\server\share\data"; string sibling = @"\\server\share\data-sibling\file.txt"; @@ -302,10 +305,11 @@ public void EnsureWithinRoot_UncPath_SiblingWithPrefix_Throws() PathValidation.EnsureWithinRoot(root, sibling)); } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] + [Fact] public void EnsureWithinRoot_UncPath_PathEqualsRoot_DoesNotThrow() { + if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + string root = @"\\server\share\data"; string result = PathValidation.EnsureWithinRoot(root, root); @@ -317,10 +321,11 @@ public void EnsureWithinRoot_UncPath_PathEqualsRoot_DoesNotThrow() // EnsureWithinRoot – short (8.3) Windows paths // ────────────────────────────────────────────── - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] + [Fact] public void EnsureWithinRoot_ShortPathRoot_LongPathChild_DocumentedBehavior() { + if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + // Short (8.3) paths are NOT consistently normalized by Path.GetFullPath // across .NET versions. This test documents that if the root uses a short // path form and the child uses the long form, the behavior depends on @@ -365,10 +370,11 @@ public void EnsureWithinRoot_ShortPathRoot_LongPathChild_DocumentedBehavior() } } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] + [Fact] public void EnsureWithinRoot_ConsistentShortPaths_Works() { + if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + // When both root and child are constructed from the same short-path // string via Path.Combine, EnsureWithinRoot succeeds because // Path.GetFullPath treats both consistently. @@ -403,10 +409,11 @@ public void EnsureWithinRoot_ConsistentShortPaths_Works() // EnsureWithinRoot – additional edge cases // ────────────────────────────────────────────── - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] + [Fact] public void EnsureWithinRoot_AltSeparatorInRoot_Works() { + if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + // Forward slash is an alternate directory separator on Windows. string root = Path.GetTempPath().Replace('\\', '/') + "testroot"; string child = Path.Combine(root, "sub", "file.txt"); @@ -436,10 +443,11 @@ public void EnsureWithinRoot_CaseMismatch_BehavesPerPlatform() } } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] + [Fact] public void EnsureWithinRoot_DriveRoot_ChildPath_Works() { + if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + string root = @"C:\"; string child = @"C:\some\nested\file.txt"; @@ -448,10 +456,11 @@ public void EnsureWithinRoot_DriveRoot_ChildPath_Works() Assert.Equal(Path.GetFullPath(child), result); } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] + [Fact] public void EnsureWithinRoot_DriveRoot_DifferentDrive_Throws() { + if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + string root = @"C:\data"; string other = @"D:\data\file.txt"; @@ -459,10 +468,11 @@ public void EnsureWithinRoot_DriveRoot_DifferentDrive_Throws() PathValidation.EnsureWithinRoot(root, other)); } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Windows)] + [Fact] public void EnsureWithinRoot_UnixAbsoluteRoot_ChildPath_Works() { + if (OperatingSystem.IsWindows()) Assert.Skip("Skipped on Windows"); + string root = "/tmp/testroot"; string child = "/tmp/testroot/sub/file.txt"; diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/EmbeddingTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/EmbeddingTests.cs index bf00efc6471..71a171e51f2 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/EmbeddingTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/EmbeddingTests.cs @@ -1,22 +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 System; using Microsoft.Extensions.AI.Evaluation.Reporting.Formats.Html; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.AI.Evaluation.Reporting.Tests; public class EmbeddingTests { - [ConditionalFact] + [Fact] public void CIBuildsMustIncludeEmbeddedHTML() { // TF_BUILD should be set in our CI pipeline if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TF_BUILD"))) { - throw new SkipTestException("Skipping test because it is not running in CI"); + Assert.Skip("Skipping test because it is not running in CI"); } Assert.NotEmpty(HtmlReportWriter.HtmlTemplateBefore); diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/Microsoft.Extensions.AI.Evaluation.Reporting.Tests.csproj b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/Microsoft.Extensions.AI.Evaluation.Reporting.Tests.csproj index 44b7e2f561b..e1e817ab952 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/Microsoft.Extensions.AI.Evaluation.Reporting.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/Microsoft.Extensions.AI.Evaluation.Reporting.Tests.csproj @@ -1,4 +1,4 @@ - + Microsoft.Extensions.AI.Evaluation.Reporting.Tests @@ -16,8 +16,6 @@ - - - + \ No newline at end of file diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ResponseCacheTester.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ResponseCacheTester.cs index 50793dfdb66..586fb828d57 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ResponseCacheTester.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ResponseCacheTester.cs @@ -1,11 +1,10 @@ -// 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; using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.Caching.Distributed; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.AI.Evaluation.Reporting.Tests; @@ -25,11 +24,11 @@ private void SkipIfNotConfigured() { if (!IsConfigured) { - throw new SkipTestException("Test not configured"); + Assert.Skip("Test not configured"); } } - [ConditionalFact] + [Fact] public async Task AddUncachedEntry() { SkipIfNotConfigured(); @@ -52,7 +51,7 @@ public async Task AddUncachedEntry() Assert.True(_responseB.SequenceEqual(cached)); } - [ConditionalFact] + [Fact] public async Task RemoveCachedEntry() { SkipIfNotConfigured(); @@ -78,7 +77,7 @@ public async Task RemoveCachedEntry() Assert.Null(cache.Get(_keyB)); } - [ConditionalFact] + [Fact] public async Task CacheEntryExpiration() { SkipIfNotConfigured(); @@ -106,7 +105,7 @@ public async Task CacheEntryExpiration() Assert.Null(cache.Get(_keyB)); } - [ConditionalFact] + [Fact] public async Task MultipleCacheInstances() { SkipIfNotConfigured(); @@ -128,7 +127,7 @@ public async Task MultipleCacheInstances() Assert.True(_responseB.SequenceEqual(cache.Get(_keyB) ?? [])); } - [ConditionalFact] + [Fact] public async Task DeleteExpiredEntries() { SkipIfNotConfigured(); @@ -163,7 +162,7 @@ public async Task DeleteExpiredEntries() Assert.Null(cache.Get(_keyB)); } - [ConditionalFact] + [Fact] public async Task ResetCache() { SkipIfNotConfigured(); diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ResultStoreTester.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ResultStoreTester.cs index 995b77a8c5e..e8957a6e0c5 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ResultStoreTester.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ResultStoreTester.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. using System; @@ -6,7 +6,6 @@ using System.IO; using System.Linq; using System.Threading.Tasks; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.AI.Evaluation.Reporting.Tests; @@ -61,11 +60,11 @@ private void SkipIfNotConfigured() { if (!IsConfigured) { - throw new SkipTestException("Test not configured"); + Assert.Skip("Test not configured"); } } - [ConditionalFact] + [Fact] public async Task WriteAndReadResults() { SkipIfNotConfigured(); @@ -104,7 +103,7 @@ public async Task WriteAndReadResults() Assert.Equal(IterationName(5), results[5].iterationName); } - [ConditionalFact] + [Fact] public async Task WriteAndReadHistoricalResults() { SkipIfNotConfigured(); @@ -148,7 +147,7 @@ public async Task WriteAndReadHistoricalResults() Assert.True(results.Skip(6).Take(3).All(r => r.executionName == firstExecutionName)); } - [ConditionalFact] + [Fact] public async Task DeleteExecutions() { SkipIfNotConfigured(); @@ -172,7 +171,7 @@ public async Task DeleteExecutions() Assert.Empty(results); } - [ConditionalFact] + [Fact] public async Task DeleteSomeExecutions() { SkipIfNotConfigured(); @@ -207,7 +206,7 @@ public async Task DeleteSomeExecutions() Assert.Equal(IterationName(5), results[2].iterationName); } - [ConditionalFact] + [Fact] public async Task DeleteScenarios() { SkipIfNotConfigured(); @@ -242,7 +241,7 @@ public async Task DeleteScenarios() Assert.Equal(IterationName(5), results[2].iterationName); } - [ConditionalFact] + [Fact] public async Task DeleteIterations() { SkipIfNotConfigured(); diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs index 208fbddf34f..0e83fb8da4a 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.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. using System; @@ -18,7 +18,6 @@ using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Testing; -using Microsoft.TestUtilities; using OpenTelemetry.Trace; using Xunit; @@ -49,7 +48,7 @@ public void Dispose() protected abstract IChatClient? CreateChatClient(); - [ConditionalFact] + [Fact] public virtual async Task GetResponseAsync_SingleRequestMessage() { SkipIfNotEnabled(); @@ -59,7 +58,7 @@ public virtual async Task GetResponseAsync_SingleRequestMessage() Assert.Contains("whale", response.Text, StringComparison.OrdinalIgnoreCase); } - [ConditionalFact] + [Fact] public virtual async Task GetResponseAsync_MultipleRequestMessages() { SkipIfNotEnabled(); @@ -77,7 +76,7 @@ public virtual async Task GetResponseAsync_MultipleRequestMessages() Assert.Contains("Asia", response.Text); } - [ConditionalFact] + [Fact] public virtual async Task GetResponseAsync_WithEmptyMessage() { SkipIfNotEnabled(); @@ -93,7 +92,7 @@ public virtual async Task GetResponseAsync_WithEmptyMessage() Assert.Contains("3", response.Text); } - [ConditionalFact] + [Fact] public virtual async Task GetStreamingResponseAsync() { SkipIfNotEnabled(); @@ -114,7 +113,7 @@ public virtual async Task GetStreamingResponseAsync() Assert.Contains("one giant leap", responseText, StringComparison.OrdinalIgnoreCase); } - [ConditionalFact] + [Fact] public virtual async Task GetResponseAsync_UsageDataAvailable() { SkipIfNotEnabled(); @@ -126,7 +125,7 @@ public virtual async Task GetResponseAsync_UsageDataAvailable() Assert.Equal(response.Usage?.InputTokenCount + response.Usage?.OutputTokenCount, response.Usage?.TotalTokenCount); } - [ConditionalFact] + [Fact] public virtual async Task GetStreamingResponseAsync_UsageDataAvailable() { SkipIfNotEnabled(); @@ -153,7 +152,7 @@ public virtual async Task GetStreamingResponseAsync_UsageDataAvailable() Assert.Equal(usage.Details.InputTokenCount + usage.Details.OutputTokenCount, usage.Details.TotalTokenCount); } - [ConditionalFact] + [Fact] public virtual async Task GetStreamingResponseAsync_AppendToHistory() { SkipIfNotEnabled(); @@ -174,7 +173,7 @@ public virtual async Task GetStreamingResponseAsync_AppendToHistory() protected virtual string? GetModel_MultiModal_DescribeImage() => null; - [ConditionalFact] + [Fact] public virtual async Task MultiModal_DescribeImage() { SkipIfNotEnabled(); @@ -192,7 +191,7 @@ public virtual async Task MultiModal_DescribeImage() Assert.True(response.Text.IndexOf("net", StringComparison.OrdinalIgnoreCase) >= 0, response.Text); } - [ConditionalFact] + [Fact] public virtual async Task MultiModal_DescribePdf() { SkipIfNotEnabled(); @@ -210,7 +209,7 @@ public virtual async Task MultiModal_DescribePdf() Assert.True(response.Text.IndexOf("hello", StringComparison.OrdinalIgnoreCase) >= 0, response.Text); } - [ConditionalFact] + [Fact] public virtual async Task FunctionInvocation_AutomaticallyInvokeFunction_Parameterless() { SkipIfNotEnabled(); @@ -241,7 +240,7 @@ public virtual async Task FunctionInvocation_AutomaticallyInvokeFunction_Paramet AssertUsageAgainstActivities(response, activities); } - [ConditionalFact] + [Fact] public virtual async Task FunctionInvocation_AutomaticallyInvokeFunction_WithParameters_NonStreaming() { SkipIfNotEnabled(); @@ -256,7 +255,7 @@ public virtual async Task FunctionInvocation_AutomaticallyInvokeFunction_WithPar Assert.Contains("3528", response.Text); } - [ConditionalFact] + [Fact] public virtual async Task FunctionInvocation_AutomaticallyInvokeFunction_WithParameters_Streaming() { SkipIfNotEnabled(); @@ -277,7 +276,7 @@ public virtual async Task FunctionInvocation_AutomaticallyInvokeFunction_WithPar Assert.Contains("3528", sb.ToString()); } - [ConditionalFact] + [Fact] public virtual async Task FunctionInvocation_OptionalParameter() { SkipIfNotEnabled(); @@ -309,7 +308,7 @@ public virtual async Task FunctionInvocation_OptionalParameter() AssertUsageAgainstActivities(response, activities); } - [ConditionalFact] + [Fact] public virtual async Task FunctionInvocation_NestedParameters() { SkipIfNotEnabled(); @@ -341,7 +340,7 @@ public virtual async Task FunctionInvocation_NestedParameters() AssertUsageAgainstActivities(response, activities); } - [ConditionalFact] + [Fact] public virtual async Task FunctionInvocation_ArrayParameter() { SkipIfNotEnabled(); @@ -391,11 +390,11 @@ private static void AssertUsageAgainstActivities(ChatResponse response, List AvailableTools_SchemasAreAccepted(strict: true); - [ConditionalFact] + [Fact] public virtual Task AvailableTools_SchemasAreAccepted_NonStrict() => AvailableTools_SchemasAreAccepted(strict: false); @@ -562,13 +561,13 @@ private class ComplexObject protected virtual bool SupportsParallelFunctionCalling => true; - [ConditionalFact] + [Fact] public virtual async Task FunctionInvocation_SupportsMultipleParallelRequests() { SkipIfNotEnabled(); if (!SupportsParallelFunctionCalling) { - throw new SkipTestException("Parallel function calling is not supported by this chat client"); + Assert.Skip("Parallel function calling is not supported by this chat client"); } using var chatClient = new FunctionInvokingChatClient(ChatClient); @@ -592,7 +591,7 @@ public virtual async Task FunctionInvocation_SupportsMultipleParallelRequests() $"Doesn't contain three: {response.Text}"); } - [ConditionalFact] + [Fact] public virtual async Task FunctionInvocation_RequireAny() { SkipIfNotEnabled(); @@ -615,7 +614,7 @@ public virtual async Task FunctionInvocation_RequireAny() Assert.True(callCount >= 1); } - [ConditionalFact] + [Fact] public virtual async Task FunctionInvocation_RequireSpecific() { SkipIfNotEnabled(); @@ -636,7 +635,7 @@ public virtual async Task FunctionInvocation_RequireSpecific() Assert.True(shieldsUp); } - [ConditionalFact] + [Fact] public virtual async Task Caching_OutputVariesWithoutCaching() { SkipIfNotEnabled(); @@ -648,7 +647,7 @@ public virtual async Task Caching_OutputVariesWithoutCaching() Assert.NotEqual(firstResponse.Text, secondResponse.Text); } - [ConditionalFact] + [Fact] public virtual async Task Caching_SamePromptResultsInCacheHit_NonStreaming() { SkipIfNotEnabled(); @@ -673,7 +672,7 @@ public virtual async Task Caching_SamePromptResultsInCacheHit_NonStreaming() Assert.NotEqual(firstResponse.Messages, thirdResponse.Messages); } - [ConditionalFact] + [Fact] public virtual async Task Caching_SamePromptResultsInCacheHit_Streaming() { SkipIfNotEnabled(); @@ -712,7 +711,7 @@ public virtual async Task Caching_SamePromptResultsInCacheHit_Streaming() Assert.NotEqual(orig.ToString(), third.ToString()); } - [ConditionalFact] + [Fact] public virtual async Task Caching_BeforeFunctionInvocation_AvoidsExtraCalls() { SkipIfNotEnabled(); @@ -748,7 +747,7 @@ public virtual async Task Caching_BeforeFunctionInvocation_AvoidsExtraCalls() Assert.Equal(2, llmCallCount!.CallCount); } - [ConditionalFact] + [Fact] public virtual async Task Caching_AfterFunctionInvocation_FunctionOutputUnchangedAsync() { SkipIfNotEnabled(); @@ -790,7 +789,7 @@ public virtual async Task Caching_AfterFunctionInvocation_FunctionOutputUnchange public virtual bool FunctionInvokingChatClientSetsConversationId => false; - [ConditionalFact] + [Fact] public virtual async Task Caching_AfterFunctionInvocation_FunctionOutputChangedAsync() { SkipIfNotEnabled(); @@ -831,7 +830,7 @@ public virtual async Task Caching_AfterFunctionInvocation_FunctionOutputChangedA Assert.Equal(3, llmCallCount!.CallCount); } - [ConditionalFact] + [Fact] public virtual async Task Logging_LogsCalls_NonStreaming() { SkipIfNotEnabled(); @@ -850,7 +849,7 @@ public virtual async Task Logging_LogsCalls_NonStreaming() entry => Assert.Contains("whale", entry.Message)); } - [ConditionalFact] + [Fact] public virtual async Task Logging_LogsCalls_Streaming() { SkipIfNotEnabled(); @@ -872,7 +871,7 @@ public virtual async Task Logging_LogsCalls_Streaming() Assert.Contains(logs, e => e.Message.Contains("whale")); } - [ConditionalFact] + [Fact] public virtual async Task Logging_LogsFunctionCalls_NonStreaming() { SkipIfNotEnabled(); @@ -898,7 +897,7 @@ await chatClient.GetResponseAsync( entry => Assert.Contains(secretNumber.ToString(), entry.Message)); } - [ConditionalFact] + [Fact] public virtual async Task Logging_LogsFunctionCalls_Streaming() { SkipIfNotEnabled(); @@ -926,7 +925,7 @@ public virtual async Task Logging_LogsFunctionCalls_Streaming() Assert.Contains(logs, e => e.Message.Contains($"\"result\": {secretNumber}")); } - [ConditionalFact] + [Fact] public virtual async Task OpenTelemetry_CanEmitTracesAndMetrics() { SkipIfNotEnabled(); @@ -956,7 +955,7 @@ public virtual async Task OpenTelemetry_CanEmitTracesAndMetrics() Assert.True(activity.Duration.TotalMilliseconds > 0); } - [ConditionalFact] + [Fact] public virtual async Task GetResponseAsync_StructuredOutput() { SkipIfNotEnabled(); @@ -972,7 +971,7 @@ Who is described in the following sentence? Assert.Equal(JobType.Programmer, response.Result.Job); } - [ConditionalFact] + [Fact] public virtual async Task GetResponseAsync_StructuredOutputArray() { SkipIfNotEnabled(); @@ -988,7 +987,7 @@ Who are described in the following sentence? Assert.Contains(response.Result, x => x.FullName == "Josh Simpson"); } - [ConditionalFact] + [Fact] public virtual async Task GetResponseAsync_StructuredOutputInteger() { SkipIfNotEnabled(); @@ -1001,7 +1000,7 @@ To fix this we added another one. How many are there now? Assert.Equal(15, response.Result); } - [ConditionalFact] + [Fact] public virtual async Task GetResponseAsync_StructuredOutputString() { SkipIfNotEnabled(); @@ -1014,7 +1013,7 @@ public virtual async Task GetResponseAsync_StructuredOutputString() Assert.Equal("Jimbo Smith", response.Result); } - [ConditionalFact] + [Fact] public virtual async Task GetResponseAsync_StructuredOutputBool_True() { SkipIfNotEnabled(); @@ -1027,7 +1026,7 @@ Is there at least one software developer from Cardiff? Assert.True(response.Result); } - [ConditionalFact] + [Fact] public virtual async Task GetResponseAsync_StructuredOutputBool_False() { SkipIfNotEnabled(); @@ -1040,7 +1039,7 @@ public virtual async Task GetResponseAsync_StructuredOutputBool_False() Assert.False(response.Result); } - [ConditionalFact] + [Fact] public virtual async Task GetResponseAsync_StructuredOutputEnum() { SkipIfNotEnabled(); @@ -1052,7 +1051,7 @@ Taylor Swift is a famous singer and songwriter. What is her job? Assert.Equal(JobType.PopStar, response.Result); } - [ConditionalFact] + [Fact] public virtual async Task GetResponseAsync_StructuredOutput_WithFunctions() { SkipIfNotEnabled(); @@ -1083,7 +1082,7 @@ public virtual async Task GetResponseAsync_StructuredOutput_WithFunctions() Assert.Equal(expectedPerson.Job, response.Result.Job); } - [ConditionalFact] + [Fact] public virtual async Task GetResponseAsync_StructuredOutput_NonNative() { SkipIfNotEnabled(); @@ -1129,7 +1128,7 @@ private enum JobType Unknown, } - [ConditionalFact] + [Fact] public virtual async Task SummarizingChatReducer_PreservesConversationContext() { SkipIfNotEnabled(); @@ -1171,7 +1170,7 @@ public virtual async Task SummarizingChatReducer_PreservesConversationContext() $"Expected 'hiking' or 'hike' in response: {response.Text}"); } - [ConditionalFact] + [Fact] public virtual async Task SummarizingChatReducer_PreservesSystemMessage() { SkipIfNotEnabled(); @@ -1215,7 +1214,7 @@ public virtual async Task SummarizingChatReducer_PreservesSystemMessage() $"Expected pirate speak in response: {response.Text}"); } - [ConditionalFact] + [Fact] public virtual async Task SummarizingChatReducer_WithFunctionCalls() { SkipIfNotEnabled(); @@ -1266,7 +1265,7 @@ public virtual async Task SummarizingChatReducer_WithFunctionCalls() $"Expected weather comparison in response: {response.Text}"); } - [ConditionalFact] + [Fact] public virtual async Task SummarizingChatReducer_Streaming() { SkipIfNotEnabled(); @@ -1311,7 +1310,7 @@ public virtual async Task SummarizingChatReducer_Streaming() $"Expected 'software' or 'engineer' in response: {responseText}"); } - [ConditionalFact] + [Fact] public virtual async Task SummarizingChatReducer_CustomPrompt() { SkipIfNotEnabled(); @@ -1407,7 +1406,7 @@ protected void SkipIfNotEnabled() if (skipIntegration is not null || ChatClient is null) { - throw new SkipTestException("Client is not enabled."); + Assert.Skip("Client is not enabled."); } } diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/EmbeddingGeneratorIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/EmbeddingGeneratorIntegrationTests.cs index 20423ae9e8b..817dfa1212c 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/EmbeddingGeneratorIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/EmbeddingGeneratorIntegrationTests.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. using System; @@ -16,7 +16,6 @@ using System.Threading.Tasks; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Memory; -using Microsoft.TestUtilities; using OpenTelemetry.Trace; using Xunit; @@ -42,7 +41,7 @@ public void Dispose() protected abstract IEmbeddingGenerator>? CreateEmbeddingGenerator(); - [ConditionalFact] + [Fact] public virtual async Task GenerateEmbedding_CreatesEmbeddingSuccessfully() { SkipIfNotEnabled(); @@ -57,7 +56,7 @@ public virtual async Task GenerateEmbedding_CreatesEmbeddingSuccessfully() Assert.NotEmpty(embeddings[0].Vector.ToArray()); } - [ConditionalFact] + [Fact] public virtual async Task GenerateEmbeddings_CreatesEmbeddingsSuccessfully() { SkipIfNotEnabled(); @@ -79,7 +78,7 @@ public virtual async Task GenerateEmbeddings_CreatesEmbeddingsSuccessfully() }); } - [ConditionalFact] + [Fact] public virtual async Task Caching_SameOutputsForSameInput() { SkipIfNotEnabled(); @@ -102,7 +101,7 @@ public virtual async Task Caching_SameOutputsForSameInput() Assert.Equal(2, callCounter.CallCount); } - [ConditionalFact] + [Fact] public virtual async Task OpenTelemetry_CanEmitTracesAndMetrics() { SkipIfNotEnabled(); @@ -134,7 +133,7 @@ public virtual async Task OpenTelemetry_CanEmitTracesAndMetrics() } #if NET - [ConditionalFact] + [Fact] public async Task Quantization_Binary_EmbeddingsCompareSuccessfully() { SkipIfNotEnabled(); @@ -178,7 +177,7 @@ static byte[] ToArray(BitArray array) Assert.True(distances[2, 3] < distances[1, 3]); } - [ConditionalFact] + [Fact] public async Task Quantization_Half_EmbeddingsCompareSuccessfully() { SkipIfNotEnabled(); @@ -221,7 +220,7 @@ protected void SkipIfNotEnabled() { if (_embeddingGenerator is null) { - throw new SkipTestException("Generator is not enabled."); + Assert.Skip("Generator is not enabled."); } } } diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratingChatClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratingChatClientIntegrationTests.cs index 2cbdcd96abf..9b01b489a34 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratingChatClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratingChatClientIntegrationTests.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.TestUtilities; using Xunit; #pragma warning disable CA2000 // Dispose objects before losing scope @@ -111,7 +110,7 @@ static ChatResponse ValidateChatResponse(ChatResponse response) } } - [ConditionalTheory] + [Theory] [InlineData(false)] // Non-streaming [InlineData(true)] // Streaming public virtual async Task GenerateImage_CallsGenerateFunction_ReturnsDataContent(bool useStreaming) @@ -147,7 +146,7 @@ [new ChatMessage(ChatRole.User, "Please generate an image of a cat")], Assert.False(imageContent.Data.IsEmpty); } - [ConditionalTheory] + [Theory] [InlineData(false)] // Non-streaming [InlineData(true)] // Streaming public virtual async Task EditImage_WithImageInSameRequest_PassesExactDataContent(bool useStreaming) @@ -178,7 +177,7 @@ [new ChatMessage(ChatRole.User, [new TextContent("Please edit this image to add Assert.Equal("original.png", originalImageContent.Name); } - [ConditionalTheory] + [Theory] [InlineData(false)] // Non-streaming [InlineData(true)] // Streaming public virtual async Task GenerateThenEdit_FromChatHistory_EditsGeneratedImage(bool useStreaming) @@ -228,7 +227,7 @@ public virtual async Task GenerateThenEdit_FromChatHistory_EditsGeneratedImage(b Assert.Contains("generated_image_1", editedImage.Name); } - [ConditionalTheory] + [Theory] [InlineData(false)] // Non-streaming [InlineData(true)] // Streaming public virtual async Task MultipleEdits_EditsLatestImage(bool useStreaming) @@ -273,7 +272,7 @@ public virtual async Task MultipleEdits_EditsLatestImage(bool useStreaming) Assert.Equal(secondImage, lastImageToEdit); } - [ConditionalTheory] + [Theory] [InlineData(false)] // Non-streaming [InlineData(true)] // Streaming public virtual async Task MultipleEdits_EditsFirstImage(bool useStreaming) @@ -318,7 +317,7 @@ public virtual async Task MultipleEdits_EditsFirstImage(bool useStreaming) Assert.Equal(firstGeneratedImage, lastImageToEdit); } - [ConditionalTheory] + [Theory] [InlineData(false)] // Non-streaming [InlineData(true)] // Streaming public virtual async Task ImageGeneration_WithOptions_PassesOptionsToGenerator(bool useStreaming) @@ -350,7 +349,7 @@ [new ChatMessage(ChatRole.User, "Generate an image of a castle")], Assert.Equal(new System.Drawing.Size(512, 512), options.ImageSize); } - [ConditionalTheory] + [Theory] [InlineData(false)] // Non-streaming [InlineData(true)] // Streaming public virtual async Task ImageContentHandling_AllImages_ReplacesImagesWithPlaceholders(bool useStreaming) @@ -442,7 +441,7 @@ protected void SkipIfNotEnabled() if (skipIntegration is not null || ChatClient is null) { - throw new SkipTestException("Client is not enabled."); + Assert.Skip("Client is not enabled."); } } } diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratorIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratorIntegrationTests.cs index 76b08941bc5..b07b7ece1db 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratorIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratorIntegrationTests.cs @@ -5,7 +5,6 @@ using System.Diagnostics.CodeAnalysis; using System.IO; using System.Threading.Tasks; -using Microsoft.TestUtilities; using Xunit; #pragma warning disable CA2214 // Do not call overridable methods in constructors @@ -29,7 +28,7 @@ public void Dispose() protected abstract IImageGenerator? CreateGenerator(); - [ConditionalFact] + [Fact] public virtual async Task GenerateImagesAsync_SingleImageGeneration() { SkipIfNotEnabled(); @@ -62,7 +61,7 @@ public virtual async Task GenerateImagesAsync_SingleImageGeneration() } } - [ConditionalFact] + [Fact] public virtual async Task GenerateImagesAsync_MultipleImages() { SkipIfNotEnabled(); @@ -87,7 +86,7 @@ public virtual async Task GenerateImagesAsync_MultipleImages() } } - [ConditionalFact] + [Fact] public virtual async Task EditImagesAsync_SingleImage() { SkipIfNotEnabled(); @@ -129,7 +128,7 @@ protected void SkipIfNotEnabled() if (skipIntegration is not null || _generator is null) { - throw new SkipTestException("Generator is not enabled."); + Assert.Skip("Generator is not enabled."); } } } diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/Microsoft.Extensions.AI.Integration.Tests.csproj b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/Microsoft.Extensions.AI.Integration.Tests.csproj index 0c6f1dba503..8b93086b12e 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/Microsoft.Extensions.AI.Integration.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/Microsoft.Extensions.AI.Integration.Tests.csproj @@ -1,4 +1,4 @@ - + Microsoft.Extensions.AI Opt-in integration tests for Microsoft.Extensions.AI. @@ -70,7 +70,5 @@ - - - + diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/SpeechToTextClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/SpeechToTextClientIntegrationTests.cs index 4d48e67c4da..ef5eaa9c9e8 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/SpeechToTextClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/SpeechToTextClientIntegrationTests.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. using System; @@ -6,7 +6,6 @@ using System.IO; using System.Text; using System.Threading.Tasks; -using Microsoft.TestUtilities; using Xunit; #pragma warning disable CA2214 // Do not call overridable methods in constructors @@ -30,7 +29,7 @@ public void Dispose() protected abstract ISpeechToTextClient? CreateClient(); - [ConditionalFact] + [Fact] public virtual async Task GetTextAsync_SingleAudioRequestMessage() { SkipIfNotEnabled(); @@ -41,7 +40,7 @@ public virtual async Task GetTextAsync_SingleAudioRequestMessage() Assert.Contains("gym", response.Text, StringComparison.OrdinalIgnoreCase); } - [ConditionalFact] + [Fact] public virtual async Task GetStreamingTextAsync_SingleStreamingResponseChoice() { SkipIfNotEnabled(); @@ -59,7 +58,7 @@ public virtual async Task GetStreamingTextAsync_SingleStreamingResponseChoice() Assert.Contains("gym", responseText, StringComparison.OrdinalIgnoreCase); } - [ConditionalTheory] + [Theory] [InlineData("audio001.mp3")] [InlineData("audio001_noid3.mp3")] [InlineData("audio001.wav")] @@ -94,7 +93,7 @@ protected void SkipIfNotEnabled() if (skipIntegration is not null || _client is null) { - throw new SkipTestException("Client is not enabled."); + Assert.Skip("Client is not enabled."); } } } diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/TextToSpeechClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/TextToSpeechClientIntegrationTests.cs index 823a225052a..4fb2b5e50d7 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/TextToSpeechClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/TextToSpeechClientIntegrationTests.cs @@ -1,11 +1,10 @@ -// 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; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; -using Microsoft.TestUtilities; using Xunit; #pragma warning disable CA2214 // Do not call overridable methods in constructors @@ -29,7 +28,7 @@ public void Dispose() protected abstract ITextToSpeechClient? CreateClient(); - [ConditionalFact] + [Fact] public virtual async Task GetAudioAsync_SimpleText_ReturnsAudio() { SkipIfNotEnabled(); @@ -45,7 +44,7 @@ public virtual async Task GetAudioAsync_SimpleText_ReturnsAudio() Assert.StartsWith("audio/", dataContent.MediaType, StringComparison.Ordinal); } - [ConditionalFact] + [Fact] public virtual async Task GetAudioAsync_WithVoice_ReturnsAudio() { SkipIfNotEnabled(); @@ -64,7 +63,7 @@ public virtual async Task GetAudioAsync_WithVoice_ReturnsAudio() Assert.StartsWith("audio/", dataContent.MediaType, StringComparison.Ordinal); } - [ConditionalFact] + [Fact] public virtual async Task GetAudioAsync_WithAudioFormat_ReturnsCorrectMediaType() { SkipIfNotEnabled(); @@ -83,7 +82,7 @@ public virtual async Task GetAudioAsync_WithAudioFormat_ReturnsCorrectMediaType( Assert.Equal("audio/opus", dataContent.MediaType); } - [ConditionalFact] + [Fact] public virtual async Task GetAudioAsync_WithSpeed_ReturnsAudio() { SkipIfNotEnabled(); @@ -101,7 +100,7 @@ public virtual async Task GetAudioAsync_WithSpeed_ReturnsAudio() Assert.False(dataContent.Data.IsEmpty); } - [ConditionalFact] + [Fact] public virtual async Task GetStreamingAudioAsync_SimpleText_ReturnsUpdates() { SkipIfNotEnabled(); @@ -132,7 +131,7 @@ protected void SkipIfNotEnabled() if (skipIntegration is not null || _client is null) { - throw new SkipTestException("Client is not enabled."); + Assert.Skip("Client is not enabled."); } } } diff --git a/test/Libraries/Microsoft.Extensions.AI.OllamaSharp.Integration.Tests/OllamaSharpChatClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.OllamaSharp.Integration.Tests/OllamaSharpChatClientIntegrationTests.cs index 28d3e21fd65..31fbe2fffef 100644 --- a/test/Libraries/Microsoft.Extensions.AI.OllamaSharp.Integration.Tests/OllamaSharpChatClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.OllamaSharp.Integration.Tests/OllamaSharpChatClientIntegrationTests.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. using System; @@ -6,7 +6,6 @@ using System.ComponentModel; using System.Threading; using System.Threading.Tasks; -using Microsoft.TestUtilities; using OllamaSharp; using Xunit; @@ -20,14 +19,14 @@ public class OllamaSharpChatClientIntegrationTests : ChatClientIntegrationTests null; public override Task FunctionInvocation_RequireAny() => - throw new SkipTestException("Ollama does not currently support requiring function invocation."); + Assert.Skip("Ollama does not currently support requiring function invocation."); public override Task FunctionInvocation_RequireSpecific() => - throw new SkipTestException("Ollama does not currently support requiring function invocation."); + Assert.Skip("Ollama does not currently support requiring function invocation."); protected override string? GetModel_MultiModal_DescribeImage() => "llava"; - [ConditionalFact] + [Fact] public async Task PromptBasedFunctionCalling_NoArgs() { SkipIfNotEnabled(); @@ -51,7 +50,7 @@ public async Task PromptBasedFunctionCalling_NoArgs() Assert.Contains(secretNumber.ToString(), response.Text); } - [ConditionalFact] + [Fact] public async Task PromptBasedFunctionCalling_WithArgs() { SkipIfNotEnabled(); @@ -86,7 +85,7 @@ public async Task PromptBasedFunctionCalling_WithArgs() Assert.False(didCallIrrelevantTool); } - [ConditionalFact] + [Fact] public async Task InvalidModelParameter_ThrowsInvalidOperationException() { SkipIfNotEnabled(); diff --git a/test/Libraries/Microsoft.Extensions.AI.OllamaSharp.Integration.Tests/OllamaSharpEmbeddingGeneratorIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.OllamaSharp.Integration.Tests/OllamaSharpEmbeddingGeneratorIntegrationTests.cs index f7775143c36..42310d93467 100644 --- a/test/Libraries/Microsoft.Extensions.AI.OllamaSharp.Integration.Tests/OllamaSharpEmbeddingGeneratorIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.OllamaSharp.Integration.Tests/OllamaSharpEmbeddingGeneratorIntegrationTests.cs @@ -1,9 +1,8 @@ -// 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; using System.Threading.Tasks; -using Microsoft.TestUtilities; using OllamaSharp; using Xunit; @@ -16,7 +15,7 @@ public class OllamaSharpEmbeddingGeneratorIntegrationTests : EmbeddingGeneratorI new OllamaApiClient(endpoint, "all-minilm") : null; - [ConditionalFact] + [Fact] public async Task InvalidModelParameter_ThrowsInvalidOperationException() { SkipIfNotEnabled(); diff --git a/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIAssistantChatClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIAssistantChatClientIntegrationTests.cs index 15f0ebcb73c..70f127982f2 100644 --- a/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIAssistantChatClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIAssistantChatClientIntegrationTests.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. #pragma warning disable CA1822 // Mark members as static @@ -12,7 +12,6 @@ using System.Net.Http; using System.Text.RegularExpressions; using System.Threading.Tasks; -using Microsoft.TestUtilities; using OpenAI.Assistants; using Xunit; @@ -48,7 +47,7 @@ public class OpenAIAssistantChatClientIntegrationTests : ChatClientIntegrationTe public override Task MultiModal_DescribeImage() => Task.CompletedTask; public override Task MultiModal_DescribePdf() => Task.CompletedTask; - [ConditionalFact] + [Fact] public async Task UseCodeInterpreter_ProducesCodeExecutionResults() { SkipIfNotEnabled(); diff --git a/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIHostedFileClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIHostedFileClientIntegrationTests.cs index 2cf739d6427..49e5266f594 100644 --- a/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIHostedFileClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIHostedFileClientIntegrationTests.cs @@ -7,7 +7,6 @@ using System.IO; using System.Text; using System.Threading.Tasks; -using Microsoft.TestUtilities; using Xunit; #pragma warning disable MEAI001 @@ -24,7 +23,7 @@ public void Dispose() _client?.Dispose(); } - [ConditionalFact] + [Fact] public async Task Upload_Download_Delete_Roundtrip() { SkipIfNotEnabled(); @@ -81,7 +80,7 @@ public async Task Upload_Download_Delete_Roundtrip() } } - [ConditionalFact] + [Fact] public async Task Upload_ListFiles_VerifyPresent() { SkipIfNotEnabled(); @@ -112,7 +111,7 @@ public async Task Upload_ListFiles_VerifyPresent() } } - [ConditionalFact] + [Fact] public async Task GetFileInfo_ReturnsMetadata() { SkipIfNotEnabled(); @@ -147,7 +146,7 @@ public async Task GetFileInfo_ReturnsMetadata() } } - [ConditionalFact] + [Fact] public async Task Delete_NonExistent_ReturnsFalse() { SkipIfNotEnabled(); @@ -156,7 +155,7 @@ public async Task Delete_NonExistent_ReturnsFalse() Assert.False(deleted); } - [ConditionalFact] + [Fact] public async Task GetFileInfo_NonExistent_ReturnsNull() { SkipIfNotEnabled(); @@ -165,7 +164,7 @@ public async Task GetFileInfo_NonExistent_ReturnsNull() Assert.Null(fileInfo); } - [ConditionalFact] + [Fact] public async Task Upload_DataContent_Extension() { SkipIfNotEnabled(); @@ -193,7 +192,7 @@ public async Task Upload_DataContent_Extension() } } - [ConditionalFact] + [Fact] public async Task Download_AsDataContent_Extension() { SkipIfNotEnabled(); @@ -222,7 +221,7 @@ public async Task Download_AsDataContent_Extension() } } - [ConditionalFact] + [Fact] public async Task Upload_DownloadTo_Extension() { SkipIfNotEnabled(); @@ -262,7 +261,7 @@ public async Task Upload_DownloadTo_Extension() } } - [ConditionalFact] + [Fact] public async Task Container_Upload_Download_Delete_Roundtrip() { SkipIfNotEnabled(); @@ -332,7 +331,7 @@ public async Task Container_Upload_Download_Delete_Roundtrip() Assert.True(deleted); } - [ConditionalFact] + [Fact] public async Task CodeInterpreter_ProducesDownloadableOutputs() { SkipIfNotEnabled(); @@ -382,7 +381,7 @@ public async Task CodeInterpreter_ProducesDownloadableOutputs() Assert.True(ms.Length > 0); } - [ConditionalFact] + [Fact] public async Task CodeInterpreter_Upload_ProcessedByCodeInterpreter() { SkipIfNotEnabled(); @@ -460,7 +459,7 @@ private void SkipIfNotEnabled() if (skipIntegration is not null || _client is null) { - throw new SkipTestException("Client is not enabled."); + Assert.Skip("Client is not enabled."); } } } diff --git a/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientIntegrationTests.cs index 28a485dfae7..047450de19e 100644 --- a/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientIntegrationTests.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Text.Json; using System.Threading.Tasks; -using Microsoft.TestUtilities; using OpenAI.Responses; using Xunit; @@ -31,7 +30,7 @@ public class OpenAIResponseClientIntegrationTests : ChatClientIntegrationTests // Test structure doesn't make sense with Responses. public override Task Caching_AfterFunctionInvocation_FunctionOutputUnchangedAsync() => Task.CompletedTask; - [ConditionalFact] + [Fact] public async Task UseCodeInterpreter_ProducesCodeExecutionResults() { SkipIfNotEnabled(); @@ -75,7 +74,7 @@ public async Task UseCodeInterpreter_ProducesCodeExecutionResults() } } - [ConditionalFact] + [Fact] public async Task UseWebSearch_AnnotationsReflectResults() { SkipIfNotEnabled(); @@ -134,7 +133,7 @@ public async Task UseWebSearch_AnnotationsReflectResults() }); } - [ConditionalTheory] + [Theory] [InlineData(false, "gpt-image-1-mini")] [InlineData(true, "gpt-image-2")] public async Task UseImageGeneration_ProducesImageContent(bool streaming, string imageModel) @@ -143,7 +142,7 @@ public async Task UseImageGeneration_ProducesImageContent(bool streaming, string if (TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is not true) { - throw new SkipTestException("Image generation tool requires gpt-5.4 or later."); + Assert.Skip("Image generation tool requires gpt-5.4 or later."); } var chatOptions = new ChatOptions @@ -187,7 +186,7 @@ public async Task UseImageGeneration_ProducesImageContent(bool streaming, string File.WriteAllBytes(tempPath, imageContent.Data.ToArray()); } - [ConditionalFact] + [Fact] public async Task RemoteMCP_ListTools() { SkipIfNotEnabled(); @@ -204,7 +203,7 @@ public async Task RemoteMCP_ListTools() Assert.Contains("ask_question", response.Text); } - [ConditionalFact] + [Fact] public async Task RemoteMCP_CallTool_ApprovalNeverRequired() { SkipIfNotEnabled(); @@ -242,7 +241,7 @@ await client.GetStreamingResponseAsync(Prompt, chatOptions).ToChatResponseAsync( } } - [ConditionalFact] + [Fact] public async Task RemoteMCP_CallTool_ApprovalRequired() { SkipIfNotEnabled(); @@ -311,14 +310,14 @@ await client.GetStreamingResponseAsync(input, chatOptions).ToChatResponseAsync() } } - [ConditionalFact] + [Fact] public async Task RemoteMCP_DeferLoadingTools() { SkipIfNotEnabled(); if (TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is not true) { - throw new SkipTestException("Tool search requires gpt-5.4 or later."); + Assert.Skip("Tool search requires gpt-5.4 or later."); } var mcpTool = new HostedMcpServerTool("deepwiki", new Uri("https://mcp.deepwiki.com/mcp")) @@ -355,7 +354,7 @@ public async Task RemoteMCP_DeferLoadingTools() Assert.Contains(rawJsons, json => json.Contains("\"type\":\"tool_search_output\"") || json.Contains("\"type\": \"tool_search_output\"")); } - [ConditionalFact] + [Fact] public async Task GetResponseAsync_BackgroundResponses() { SkipIfNotEnabled(); @@ -383,7 +382,7 @@ public async Task GetResponseAsync_BackgroundResponses() Assert.Contains("whale", response.Text, StringComparison.OrdinalIgnoreCase); } - [ConditionalFact] + [Fact] public async Task GetResponseAsync_BackgroundResponses_WithFunction() { SkipIfNotEnabled(); @@ -418,7 +417,7 @@ public async Task GetResponseAsync_BackgroundResponses_WithFunction() Assert.Equal(1, callCount); } - [ConditionalFact] + [Fact] public async Task GetStreamingResponseAsync_BackgroundResponses() { SkipIfNotEnabled(); @@ -439,7 +438,7 @@ public async Task GetStreamingResponseAsync_BackgroundResponses() Assert.Contains("Paris", responseText, StringComparison.OrdinalIgnoreCase); } - [ConditionalFact] + [Fact] public async Task GetStreamingResponseAsync_BackgroundResponses_StreamResumption() { SkipIfNotEnabled(); @@ -477,7 +476,7 @@ public async Task GetStreamingResponseAsync_BackgroundResponses_StreamResumption Assert.Contains("Paris", responseText, StringComparison.OrdinalIgnoreCase); } - [ConditionalFact] + [Fact] public async Task GetStreamingResponseAsync_BackgroundResponses_WithFunction() { SkipIfNotEnabled(); @@ -503,14 +502,14 @@ public async Task GetStreamingResponseAsync_BackgroundResponses_WithFunction() Assert.Equal(1, callCount); } - [ConditionalFact] + [Fact] public async Task RemoteMCP_Connector() { SkipIfNotEnabled(); if (TestRunnerConfiguration.Instance["RemoteMCP:ConnectorAccessToken"] is not string { Length: > 0 } accessToken) { - throw new SkipTestException( + Assert.Skip( "To run this test, set a value for RemoteMCP:ConnectorAccessToken. " + "You can obtain one by following https://platform.openai.com/docs/guides/tools-connectors-mcp?quickstart-panels=connector#authorizing-a-connector."); } @@ -563,7 +562,7 @@ await client.GetStreamingResponseAsync(input, chatOptions).ToChatResponseAsync() } } - [ConditionalFact] + [Fact] public async Task ToolCallResult_TextContent() { SkipIfNotEnabled(); @@ -583,7 +582,7 @@ public async Task ToolCallResult_TextContent() Assert.Contains("42", response.Text); } - [ConditionalFact] + [Fact] public async Task ToolCallResult_MultipleAIContents() { SkipIfNotEnabled(); @@ -611,7 +610,7 @@ public async Task ToolCallResult_MultipleAIContents() Assert.Contains("72", response.Text); } - [ConditionalFact] + [Fact] public async Task ToolCallResult_ImageDataContent() { SkipIfNotEnabled(); @@ -636,7 +635,7 @@ public async Task ToolCallResult_ImageDataContent() $"Expected response to mention logo or colors, but got: {response.Text}"); } - [ConditionalFact] + [Fact] public async Task ToolCallResult_PdfDataContent() { SkipIfNotEnabled(); @@ -656,7 +655,7 @@ public async Task ToolCallResult_PdfDataContent() Assert.Contains("Hello World", response.Text, StringComparison.OrdinalIgnoreCase); } - [ConditionalFact] + [Fact] public async Task ToolCallResult_MixedContentWithImage() { SkipIfNotEnabled(); @@ -688,7 +687,7 @@ public async Task ToolCallResult_MixedContentWithImage() $"Expected response to mention analysis or image content, but got: {response.Text}"); } - [ConditionalFact] + [Fact] public async Task ReasoningContent_NonStreaming_RoundtripsEncryptedContent() { SkipIfNotEnabled(); @@ -768,7 +767,7 @@ public async Task ReasoningContent_NonStreaming_RoundtripsEncryptedContent() Assert.Contains("encrypted", ex.Message, StringComparison.OrdinalIgnoreCase); } - [ConditionalFact] + [Fact] public async Task ReasoningContent_Streaming_RoundtripsEncryptedContent() { // This test requires a reasoning model with encrypted content support. @@ -854,14 +853,14 @@ public async Task ReasoningContent_Streaming_RoundtripsEncryptedContent() Assert.Contains("encrypted", ex.Message, StringComparison.OrdinalIgnoreCase); } - [ConditionalFact] + [Fact] public async Task UseToolSearch_WithDeferredFunctions() { SkipIfNotEnabled(); if (TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is not true) { - throw new SkipTestException("Tool search requires gpt-5.4 or later."); + Assert.Skip("Tool search requires gpt-5.4 or later."); } AIFunction getWeather = AIFunctionFactory.Create(() => "Sunny, 72°F", "GetWeather", "Gets the current weather."); @@ -893,14 +892,14 @@ public async Task UseToolSearch_WithDeferredFunctions() Assert.Contains(rawJsons, json => json.Contains("\"type\":\"tool_search_output\"") || json.Contains("\"type\": \"tool_search_output\"")); } - [ConditionalFact] + [Fact] public async Task UseToolSearch_OnlyToolSearchNoFunctions_Throws() { SkipIfNotEnabled(); if (TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is not true) { - throw new SkipTestException("Tool search requires gpt-5.4 or later."); + Assert.Skip("Tool search requires gpt-5.4 or later."); } // HostedToolSearchTool with no deferred tools — the API rejects this with 400 @@ -914,14 +913,14 @@ await Assert.ThrowsAsync(() => })); } - [ConditionalFact] + [Fact] public async Task UseToolSearch_WithNonDeferredFunctionsOnly_Throws() { SkipIfNotEnabled(); if (TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is not true) { - throw new SkipTestException("Tool search requires gpt-5.4 or later."); + Assert.Skip("Tool search requires gpt-5.4 or later."); } // HostedToolSearchTool with DeferredTools explicitly set to empty — no tools are deferred. @@ -941,14 +940,14 @@ await Assert.ThrowsAsync(() => })); } - [ConditionalFact] + [Fact] public async Task UseToolSearch_DeferLoadingOnNonDeferrableTool_Throws() { SkipIfNotEnabled(); if (TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is not true) { - throw new SkipTestException("Tool search requires gpt-5.4 or later."); + Assert.Skip("Tool search requires gpt-5.4 or later."); } // Force defer_loading on a code_interpreter tool via Patch — the API should reject this. @@ -970,14 +969,14 @@ await Assert.ThrowsAsync(() => })); } - [ConditionalFact] + [Fact] public async Task UseToolSearch_NamespaceWithDescription_RoundTrips() { SkipIfNotEnabled(); if (TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is not true) { - throw new SkipTestException("Tool search requires gpt-5.4 or later."); + Assert.Skip("Tool search requires gpt-5.4 or later."); } AIFunction getWeather = AIFunctionFactory.Create(() => "Sunny, 72°F", "GetWeather", "Gets the current weather."); @@ -1015,14 +1014,14 @@ public async Task UseToolSearch_NamespaceWithDescription_RoundTrips() Assert.Contains(rawJsons, json => json.Contains("\"type\":\"tool_search_output\"") || json.Contains("\"type\": \"tool_search_output\"")); } - [ConditionalFact] + [Fact] public async Task UseToolSearch_TwoNamespacesWithDescriptions_RoundTrips() { SkipIfNotEnabled(); if (TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is not true) { - throw new SkipTestException("Tool search requires gpt-5.4 or later."); + Assert.Skip("Tool search requires gpt-5.4 or later."); } AIFunction getWeather = AIFunctionFactory.Create(() => "Sunny, 72°F", "GetWeather", "Gets the current weather."); diff --git a/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAITextToSpeechClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAITextToSpeechClientIntegrationTests.cs index 686fda917e1..f52b640a646 100644 --- a/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAITextToSpeechClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAITextToSpeechClientIntegrationTests.cs @@ -1,9 +1,8 @@ -// 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.Linq; using System.Threading.Tasks; -using Microsoft.TestUtilities; using Xunit; #pragma warning disable MEAI001 @@ -17,13 +16,13 @@ public class OpenAITextToSpeechClientIntegrationTests : TextToSpeechClientIntegr .GetAudioClient(TestRunnerConfiguration.Instance["OpenAI:TextToSpeechModel"] ?? "tts-1") .AsITextToSpeechClient(); - [ConditionalFact] + [Fact] public async Task GetStreamingAudioAsync_StreamingModel_ReturnsMultipleUpdatesWithUsage() { var openAIClient = IntegrationTestHelpers.GetOpenAIClient(); if (openAIClient is null) { - throw new SkipTestException("Client is not enabled."); + Assert.Skip("Client is not enabled."); } using ITextToSpeechClient client = openAIClient diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/DistributedCacheTests.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/DistributedCacheTests.cs index 0e86c742c5a..5c6beb925a2 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/DistributedCacheTests.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/DistributedCacheTests.cs @@ -8,7 +8,7 @@ using Microsoft.Extensions.Caching.Hybrid.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Internal; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Extensions.Caching.Hybrid.Tests; diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/ExpirationTests.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/ExpirationTests.cs index 562ba8ae98f..9a528e854b5 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/ExpirationTests.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/ExpirationTests.cs @@ -1,11 +1,11 @@ -// 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.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Internal; -using Xunit.Abstractions; +using Xunit; using static Microsoft.Extensions.Caching.Hybrid.Tests.DistributedCacheTests; using static Microsoft.Extensions.Caching.Hybrid.Tests.L2Tests; diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/HybridCacheEventSourceTests.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/HybridCacheEventSourceTests.cs index 8e23143475f..a6a8a866045 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/HybridCacheEventSourceTests.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/HybridCacheEventSourceTests.cs @@ -1,9 +1,9 @@ -// 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.Tracing; using Microsoft.Extensions.Caching.Hybrid.Internal; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Extensions.Caching.Hybrid.Tests; @@ -11,7 +11,7 @@ public class HybridCacheEventSourceTests(ITestOutputHelper log, TestEventListene { // see notes in TestEventListener for context on fixture usage - [SkippableFact] + [Fact] public void MatchesNameAndGuid() { // Assert @@ -19,7 +19,7 @@ public void MatchesNameAndGuid() Assert.Equal(Guid.Parse("b3aca39e-5dc9-5e21-f669-b72225b66cfc"), listener.Source.Guid); // from name } - [SkippableFact] + [Fact] public async Task LocalCacheHit() { AssertEnabled(); @@ -32,7 +32,7 @@ public async Task LocalCacheHit() listener.AssertRemainingCountersZero(); } - [SkippableFact] + [Fact] public async Task LocalCacheMiss() { AssertEnabled(); @@ -45,7 +45,7 @@ public async Task LocalCacheMiss() listener.AssertRemainingCountersZero(); } - [SkippableFact] + [Fact] public async Task DistributedCacheGet() { AssertEnabled(); @@ -58,7 +58,7 @@ public async Task DistributedCacheGet() listener.AssertRemainingCountersZero(); } - [SkippableFact] + [Fact] public async Task DistributedCacheHit() { AssertEnabled(); @@ -72,7 +72,7 @@ public async Task DistributedCacheHit() listener.AssertRemainingCountersZero(); } - [SkippableFact] + [Fact] public async Task DistributedCacheMiss() { AssertEnabled(); @@ -86,7 +86,7 @@ public async Task DistributedCacheMiss() listener.AssertRemainingCountersZero(); } - [SkippableFact] + [Fact] public async Task DistributedCacheFailed() { AssertEnabled(); @@ -99,7 +99,7 @@ public async Task DistributedCacheFailed() listener.AssertRemainingCountersZero(); } - [SkippableFact] + [Fact] public async Task DistributedCacheCanceled() { AssertEnabled(); @@ -112,7 +112,7 @@ public async Task DistributedCacheCanceled() listener.AssertRemainingCountersZero(); } - [SkippableFact] + [Fact] public async Task UnderlyingDataQueryStart() { AssertEnabled(); @@ -126,7 +126,7 @@ public async Task UnderlyingDataQueryStart() listener.AssertRemainingCountersZero(); } - [SkippableFact] + [Fact] public async Task UnderlyingDataQueryComplete() { AssertEnabled(); @@ -140,7 +140,7 @@ public async Task UnderlyingDataQueryComplete() listener.AssertRemainingCountersZero(); } - [SkippableFact] + [Fact] public async Task UnderlyingDataQueryFailed() { AssertEnabled(); @@ -154,7 +154,7 @@ public async Task UnderlyingDataQueryFailed() listener.AssertRemainingCountersZero(); } - [SkippableFact] + [Fact] public async Task UnderlyingDataQueryCanceled() { AssertEnabled(); @@ -168,7 +168,7 @@ public async Task UnderlyingDataQueryCanceled() listener.AssertRemainingCountersZero(); } - [SkippableFact] + [Fact] public async Task LocalCacheWrite() { AssertEnabled(); @@ -181,7 +181,7 @@ public async Task LocalCacheWrite() listener.AssertRemainingCountersZero(); } - [SkippableFact] + [Fact] public async Task DistributedCacheWrite() { AssertEnabled(); @@ -194,7 +194,7 @@ public async Task DistributedCacheWrite() listener.AssertRemainingCountersZero(); } - [SkippableFact] + [Fact] public async Task StampedeJoin() { AssertEnabled(); @@ -207,7 +207,7 @@ public async Task StampedeJoin() listener.AssertRemainingCountersZero(); } - [SkippableFact] + [Fact] public async Task TagInvalidated() { AssertEnabled(); @@ -225,7 +225,7 @@ private void AssertEnabled() // including this data for visibility when tests fail - ETW subsystem can be ... weird log.WriteLine($".NET {Environment.Version} on {Environment.OSVersion}, {IntPtr.Size * 8}-bit"); - Skip.IfNot(listener.Source.IsEnabled(), "Event source not enabled"); + if (!(listener.Source.IsEnabled())) Assert.Skip("Event source not enabled"); } private async Task AssertCountersAsync() @@ -240,6 +240,6 @@ private async Task AssertCountersAsync() // fundamentally working. We're not meant to be testing that // the counters system *itself* works! - Skip.If(count == 0, "No counters received"); + if (count == 0) Assert.Skip("No counters received"); } } diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/L2Tests.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/L2Tests.cs index f5be5b5277d..e54ac679ae2 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/L2Tests.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/L2Tests.cs @@ -8,7 +8,7 @@ using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Extensions.Caching.Hybrid.Tests; diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LocalInvalidationTests.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LocalInvalidationTests.cs index 6efc4b14d45..0f1829e170c 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LocalInvalidationTests.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LocalInvalidationTests.cs @@ -1,11 +1,11 @@ -// 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.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Hybrid.Internal; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection; -using Xunit.Abstractions; +using Xunit; using static Microsoft.Extensions.Caching.Hybrid.Tests.L2Tests; namespace Microsoft.Extensions.Caching.Hybrid.Tests; diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LogCollector.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LogCollector.cs index 553fe1f1cd4..0ef9d975867 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LogCollector.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/LogCollector.cs @@ -1,8 +1,8 @@ -// 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.Extensions.Logging; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Extensions.Caching.Hybrid.Tests; diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/Microsoft.Extensions.Caching.Hybrid.Tests.csproj b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/Microsoft.Extensions.Caching.Hybrid.Tests.csproj index 3cd6a56dca5..b7bd1009b63 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/Microsoft.Extensions.Caching.Hybrid.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/Microsoft.Extensions.Caching.Hybrid.Tests.csproj @@ -1,7 +1,7 @@  - $(NetCoreTargetFrameworks)$(ConditionalNet462) + $(NetCoreTargetFrameworks);net472 enable enable true @@ -20,7 +20,6 @@ - diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/PayloadTests.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/PayloadTests.cs index 6ee4a8a5558..169b400bf42 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/PayloadTests.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/PayloadTests.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. using System.Buffers; @@ -7,7 +7,7 @@ using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Xunit.Abstractions; +using Xunit; using static Microsoft.Extensions.Caching.Hybrid.Tests.DistributedCacheTests; using static Microsoft.Extensions.Caching.Hybrid.Tests.L2Tests; diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/RedisTests.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/RedisTests.cs index 133db1f7ae4..026adafcefe 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/RedisTests.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/RedisTests.cs @@ -5,7 +5,7 @@ using Microsoft.Extensions.Caching.StackExchangeRedis; using Microsoft.Extensions.DependencyInjection; using StackExchange.Redis; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Extensions.Caching.Hybrid.Tests; diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/SizeTests.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/SizeTests.cs index 8085a4318c0..1f8c99287b4 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/SizeTests.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/SizeTests.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. using System.Buffers; @@ -7,7 +7,7 @@ using Microsoft.Extensions.Caching.Hybrid.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Extensions.Caching.Hybrid.Tests; diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/SqlServerTests.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/SqlServerTests.cs index e2859ec9f0b..33b123539f6 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/SqlServerTests.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/SqlServerTests.cs @@ -3,7 +3,7 @@ using Microsoft.Data.SqlClient; using Microsoft.Extensions.DependencyInjection; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Extensions.Caching.Hybrid.Tests; diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/UnreliableL2Tests.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/UnreliableL2Tests.cs index bba5020f58b..d01be3d7c07 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/UnreliableL2Tests.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/UnreliableL2Tests.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. using System.Diagnostics.CodeAnalysis; @@ -7,7 +7,7 @@ using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Extensions.Caching.Hybrid.Tests; diff --git a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Microsoft.Extensions.DataIngestion.Tests.csproj b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Microsoft.Extensions.DataIngestion.Tests.csproj index 1266db69e0f..62218c3fd38 100644 --- a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Microsoft.Extensions.DataIngestion.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Microsoft.Extensions.DataIngestion.Tests.csproj @@ -1,4 +1,4 @@ - + @@ -14,9 +14,7 @@ - - - + diff --git a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/DocumentReaderConformanceTests.cs b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/DocumentReaderConformanceTests.cs index d4993ad2cea..ad281fea900 100644 --- a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/DocumentReaderConformanceTests.cs +++ b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/DocumentReaderConformanceTests.cs @@ -8,7 +8,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.DataIngestion.Tests.Utils; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.DataIngestion.Readers.Tests; @@ -19,7 +18,7 @@ public abstract class DocumentReaderConformanceTests protected abstract IngestionDocumentReader CreateDocumentReader(bool extractImages = false); - [ConditionalFact] + [Fact] public async Task ThrowsWhenIdentifierIsNotProvided() { var reader = CreateDocumentReader(); @@ -32,7 +31,7 @@ public async Task ThrowsWhenIdentifierIsNotProvided() await Assert.ThrowsAsync("identifier", async () => await reader.ReadAsync(stream, identifier: string.Empty, mediaType: "some")); } - [ConditionalFact] + [Fact] public async Task ThrowsIfCancellationRequestedStream() { var reader = CreateDocumentReader(); @@ -43,7 +42,7 @@ public async Task ThrowsIfCancellationRequestedStream() await Assert.ThrowsAsync(async () => await reader.ReadAsync(stream, "id", "mediaType", cts.Token)); } - [ConditionalFact] + [Fact] public async Task ThrowsIfCancellationRequestedFile() { string filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName() + ".txt"); @@ -74,7 +73,7 @@ public async Task ThrowsIfCancellationRequestedFile() "https://www.bondcap.com/report/pdf/Trends_Artificial_Intelligence.pdf", // PDF file (presentation) ]; - [ConditionalTheory] + [Theory] [MemberData(nameof(Links))] public virtual async Task SupportsStreams(string source) { @@ -87,7 +86,7 @@ await response.Content.ReadAsStreamAsync(), SimpleAsserts(document, source, source); } - [ConditionalTheory] + [Theory] [MemberData(nameof(Links))] public virtual async Task SupportsFiles(string source) { @@ -105,7 +104,7 @@ public virtual async Task SupportsFiles(string source) } } - [ConditionalFact] + [Fact] public virtual Task SupportsImages() => SupportsImagesCore( new("https://winprotocoldocs-bhdugrdyduf5h2e4.b02.azurefd.net/MC-SQLR/%5bMC-SQLR%5d.pdf")); // SQL Server Resolution Protocol @@ -128,7 +127,7 @@ protected async Task SupportsImagesCore(Uri source) } } - [ConditionalFact] + [Fact] public virtual async Task SupportsTables() { string[,] expected = @@ -172,7 +171,7 @@ protected static async Task DownloadAsync(Uri uri) } catch (Exception ex) { - throw new SkipTestException($"Unable to download the test file: '{ex.Message}'"); + Assert.Skip($"Unable to download the test file: '{ex.Message}'"); } } diff --git a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionAttribute.cs b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionAttribute.cs index b0169a54c1c..2316c1694d8 100644 --- a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionAttribute.cs +++ b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionAttribute.cs @@ -1,24 +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 System; using System.ComponentModel; using System.Diagnostics; using System.Text; -using Microsoft.TestUtilities; namespace Microsoft.Extensions.DataIngestion.Readers.Tests; /// -/// This class exists because currently the local copy of can't ignore tests that throw . +/// Checks whether MarkItDown is installed and accessible. Used to conditionally skip tests. /// [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)] -public class MarkItDownConditionAttribute : Attribute, ITestCondition +public class MarkItDownConditionAttribute : Attribute { internal static readonly Lazy IsInstalled = new(CanInvokeMarkItDown); - public bool IsMet => IsInstalled.Value; - public string SkipReason => "MarkItDown is not installed or not accessible."; private static bool CanInvokeMarkItDown() diff --git a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownReaderTests.cs b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownReaderTests.cs index e506ea15ca1..c778a75b848 100644 --- a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownReaderTests.cs +++ b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownReaderTests.cs @@ -1,10 +1,9 @@ -// 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; using System.Linq; using System.Threading.Tasks; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.DataIngestion.Readers.Tests; @@ -15,7 +14,7 @@ public class MarkItDownReaderTests : DocumentReaderConformanceTests protected override IngestionDocumentReader CreateDocumentReader(bool extractImages = false) => MarkItDownConditionAttribute.IsInstalled.Value ? new MarkItDownReader(extractImages: extractImages) - : throw new SkipTestException("MarkItDown is not installed"); + : Assert.Skip("MarkItDown is not installed"); protected override void SimpleAsserts(IngestionDocument document, string source, string expectedId) { @@ -40,7 +39,7 @@ protected override void SimpleAsserts(IngestionDocument document, string source, // The original purpose of the MarkItDown library was to support text-only LLMs. // Source: https://github.com/microsoft/markitdown/issues/56#issuecomment-2546357264 // It can extract images, but the support is limited to some formats like docx. - [ConditionalFact] + [Fact] public override Task SupportsImages() => SupportsImagesCore( new("https://winprotocoldocs-bhdugrdyduf5h2e4.b02.azurefd.net/MC-SQLR/%5bMC-SQLR%5d-240423.docx")); // SQL Server Resolution Protocol. } diff --git a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkdownReaderTests.cs b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkdownReaderTests.cs index 0e0ac10ca91..a93b5cd4c43 100644 --- a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkdownReaderTests.cs +++ b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkdownReaderTests.cs @@ -1,11 +1,10 @@ -// 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; using System.IO; using System.Linq; using System.Threading.Tasks; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.DataIngestion.Readers.Tests; @@ -19,15 +18,15 @@ public class MarkdownReaderTests : DocumentReaderConformanceTests "https://raw.githubusercontent.com/microsoft/markitdown/main/README.md" ]; - [ConditionalTheory] + [Theory] [MemberData(nameof(Links))] public override Task SupportsStreams(string source) => base.SupportsStreams(source); - [ConditionalTheory] + [Theory] [MemberData(nameof(Links))] public override Task SupportsFiles(string source) => base.SupportsFiles(source); - [ConditionalFact] + [Fact] public override async Task SupportsTables() { string markdownContent = """ @@ -59,7 +58,7 @@ public override async Task SupportsTables() Assert.Equal(expected, documentTable.Cells.Map(element => element!.GetMarkdown().Trim())); } - [ConditionalFact] + [Fact] public async Task SupportsTablesWithoutTrailingPipes() { // Markdown tables without trailing pipes (|) at the end of each row should be parsed correctly. @@ -100,7 +99,7 @@ public async Task SupportsTablesWithoutTrailingPipes() Assert.Null(documentTable.Cells[3, 2]); // Empty description cell is null } - [ConditionalFact] + [Fact] public override async Task SupportsImages() { string contentType1 = "image/png"; @@ -142,7 +141,7 @@ JPEG is also fine! Assert.Equal("Three", images[2].AlternativeText); } - [ConditionalFact] + [Fact] public async Task SupportsTablesWithImages() { byte[] imageBytes = Enumerable.Range(55, 111).Select(i => (byte)i).ToArray(); @@ -174,7 +173,7 @@ public async Task SupportsTablesWithImages() Assert.Equal("Latest logo", img.AlternativeText); } - [ConditionalFact] + [Fact] public async Task SupportsInlineHtml() { string markdownContent = "This has [1] inline HTML."; @@ -186,7 +185,7 @@ public async Task SupportsInlineHtml() Assert.Equal(markdownContent, paragraph.GetMarkdown()); } - [ConditionalFact] + [Fact] public async Task SupportsMultipleInlineHtmlElements() { string markdownContent = """ diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs index 3b48570e8b7..554491fb1e3 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs @@ -9,7 +9,6 @@ using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux; using Microsoft.Extensions.Logging.Testing; using Microsoft.Extensions.Time.Testing; -using Microsoft.TestUtilities; using Moq; using Xunit; @@ -142,14 +141,15 @@ public class LinuxResourceHealthCheckTests }, }; - [ConditionalTheory] + [Theory] [MemberData(nameof(Data))] - [OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux-specific test.")] public async Task TestCpuAndMemoryChecks_WithMetrics( HealthStatus expected, double utilization, ulong memoryUsed, ulong totalMemory, ResourceUsageThresholds cpuThresholds, ResourceUsageThresholds memoryThresholds, string expectedDescription) { + if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux-specific test."); + var fakeClock = new FakeTimeProvider(); var dataTracker = new Mock(); var logger = new FakeLogger(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests.csproj b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests.csproj index dcd6d4e40db..3d0296419ac 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests.csproj @@ -5,9 +5,7 @@ - - - + diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs index 44083e56f6d..120d32fa92e 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.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. using System; @@ -13,17 +13,20 @@ using Microsoft.Extensions.Logging.Testing; using Microsoft.Extensions.Options; using Microsoft.Extensions.Time.Testing; -using Microsoft.TestUtilities; using Moq; using Xunit; using static Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Interop.JobObjectInfo; namespace Microsoft.Extensions.Diagnostics.HealthChecks.Test; -[OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Not supported on MacOs.")] public class ResourceHealthCheckExtensionsTests { - [ConditionalFact] + public ResourceHealthCheckExtensionsTests() + { + if (OperatingSystem.IsMacOS()) Assert.Skip("Skipped on macOS"); + } + + [Fact] public async Task AddResourceHealthCheck() { var dataTracker = new Mock(); @@ -43,7 +46,7 @@ public async Task AddResourceHealthCheck() dataTracker.Verify(tracker => tracker.GetUtilization(samplingWindow), Times.Once); } - [ConditionalFact] + [Fact] public async Task AddResourceHealthCheck_WithCustomResourceMonitorAddedAfterInternalResourceMonitor_OverridesIt() { var dataTracker = new Mock(); @@ -63,7 +66,7 @@ public async Task AddResourceHealthCheck_WithCustomResourceMonitorAddedAfterInte dataTracker.Verify(tracker => tracker.GetUtilization(samplingWindow), Times.Once); } - [ConditionalFact] + [Fact] public void AddResourceHealthCheck_RegistersInternalResourceMonitoring() { var dataTracker = new Mock(); @@ -87,7 +90,7 @@ public void AddResourceHealthCheck_RegistersInternalResourceMonitoring() Assert.NotNull(resourceMonitoringOptions); } - [ConditionalFact] + [Fact] public async Task AddResourceHealthCheck_WithTags() { var dataTracker = new Mock(); @@ -107,7 +110,7 @@ public async Task AddResourceHealthCheck_WithTags() dataTracker.Verify(tracker => tracker.GetUtilization(samplingWindow), Times.Once); } - [ConditionalFact] + [Fact] public void AddResourceHealthCheck_WithTags_RegistersInternalResourceMonitoring() { var serviceCollection = new ServiceCollection(); @@ -122,7 +125,7 @@ public void AddResourceHealthCheck_WithTags_RegistersInternalResourceMonitoring( Assert.NotNull(resourceMonitor); } - [ConditionalFact] + [Fact] public async Task AddResourceHealthCheck_WithTags_WithCustomResourceMonitorAddedAfterInternalResourceMonitor_OverridesIt() { var dataTracker = new Mock(); @@ -142,7 +145,7 @@ public async Task AddResourceHealthCheck_WithTags_WithCustomResourceMonitorAdded dataTracker.Verify(tracker => tracker.GetUtilization(samplingWindow), Times.Once); } - [ConditionalFact] + [Fact] public async Task AddResourceHealthCheck_WithTagsEnumerable() { var dataTracker = new Mock(); @@ -162,7 +165,7 @@ public async Task AddResourceHealthCheck_WithTagsEnumerable() dataTracker.Verify(tracker => tracker.GetUtilization(samplingWindow), Times.Once); } - [ConditionalFact] + [Fact] public void AddResourceHealthCheck_WithTagsEnumerable_RegistersInternalResourceMonitoring() { var serviceCollection = new ServiceCollection(); @@ -177,7 +180,7 @@ public void AddResourceHealthCheck_WithTagsEnumerable_RegistersInternalResourceM Assert.NotNull(resourceMonitor); } - [ConditionalFact] + [Fact] public async Task AddResourceHealthCheck_WithAction() { var dataTracker = new Mock(); @@ -200,7 +203,7 @@ public async Task AddResourceHealthCheck_WithAction() dataTracker.Verify(tracker => tracker.GetUtilization(samplingWindow), Times.Once); } - [ConditionalFact] + [Fact] public void AddResourceHealthCheck_WithAction_RegistersInternalResourceMonitoring() { var serviceCollection = new ServiceCollection(); @@ -218,7 +221,7 @@ public void AddResourceHealthCheck_WithAction_RegistersInternalResourceMonitorin Assert.NotNull(resourceMonitor); } - [ConditionalFact] + [Fact] public async Task AddResourceHealthCheck_WithActionAndTags() { var dataTracker = new Mock(); @@ -242,7 +245,7 @@ public async Task AddResourceHealthCheck_WithActionAndTags() dataTracker.Verify(tracker => tracker.GetUtilization(samplingWindow), Times.Once); } - [ConditionalFact] + [Fact] public void AddResourceHealthCheck_WithActionAndTags_RegistersInternalResourceMonitoring() { var serviceCollection = new ServiceCollection(); @@ -261,7 +264,7 @@ public void AddResourceHealthCheck_WithActionAndTags_RegistersInternalResourceMo Assert.NotNull(resourceMonitor); } - [ConditionalFact] + [Fact] public async Task AddResourceHealthCheck_WithActionAndTagsEnumerable() { var dataTracker = new Mock(); @@ -285,7 +288,7 @@ public async Task AddResourceHealthCheck_WithActionAndTagsEnumerable() dataTracker.Verify(tracker => tracker.GetUtilization(samplingWindow), Times.Once); } - [ConditionalFact] + [Fact] public void AddResourceHealthCheck_WithActionAndTagsEnumerable_RegistersInternalResourceMonitoring() { var serviceCollection = new ServiceCollection(); @@ -304,7 +307,7 @@ public void AddResourceHealthCheck_WithActionAndTagsEnumerable_RegistersInternal Assert.NotNull(resourceMonitor); } - [ConditionalFact] + [Fact] public async Task AddResourceHealthCheck_WithConfigurationSection() { var dataTracker = new Mock(); @@ -323,7 +326,7 @@ public async Task AddResourceHealthCheck_WithConfigurationSection() dataTracker.Verify(tracker => tracker.GetUtilization(samplingWindow), Times.Once); } - [ConditionalFact] + [Fact] public void AddResourceHealthCheck_WithConfigurationSection_RegistersInternalResourceMonitoring() { var serviceCollection = new ServiceCollection(); @@ -338,7 +341,7 @@ public void AddResourceHealthCheck_WithConfigurationSection_RegistersInternalRes Assert.NotNull(resourceMonitor); } - [ConditionalFact] + [Fact] public async Task AddResourceHealthCheck_WithConfigurationSectionAndTags() { var dataTracker = new Mock(); @@ -359,7 +362,7 @@ public async Task AddResourceHealthCheck_WithConfigurationSectionAndTags() dataTracker.Verify(tracker => tracker.GetUtilization(samplingWindow), Times.Once); } - [ConditionalFact] + [Fact] public void AddResourceHealthCheck_WithConfigurationSectionAndTags_RegistersInternalResourceMonitoring() { var serviceCollection = new ServiceCollection(); @@ -375,7 +378,7 @@ public void AddResourceHealthCheck_WithConfigurationSectionAndTags_RegistersInte Assert.NotNull(resourceMonitor); } - [ConditionalFact] + [Fact] public async Task AddResourceHealthCheck_WithConfigurationSectionAndTagsEnumerable() { var dataTracker = new Mock(); @@ -396,7 +399,7 @@ public async Task AddResourceHealthCheck_WithConfigurationSectionAndTagsEnumerab dataTracker.Verify(tracker => tracker.GetUtilization(samplingWindow), Times.Once); } - [ConditionalFact] + [Fact] public void AddResourceHealthCheck_WithConfigurationSectionAndTagsEnumerable_RegistersInternalResourceMonitoring() { var serviceCollection = new ServiceCollection(); @@ -413,7 +416,7 @@ public void AddResourceHealthCheck_WithConfigurationSectionAndTagsEnumerable_Reg Assert.NotNull(resourceMonitor); } - [ConditionalFact] + [Fact] public void ConfigureResourceUtilizationHealthCheck_WithAction() { TimeSpan samplingWindow = TimeSpan.FromSeconds(1); @@ -435,7 +438,7 @@ public void ConfigureResourceUtilizationHealthCheck_WithAction() Assert.Equal(0.4, options.CpuThresholds.UnhealthyUtilizationPercentage); } - [ConditionalFact] + [Fact] public void ConfigureResourceUtilizationHealthCheck_WithConfigurationSection() { TimeSpan samplingWindow = TimeSpan.FromSeconds(5); @@ -464,14 +467,15 @@ public void TestNullChecks() Assert.Throws(() => ((IHealthChecksBuilder)null!).AddResourceUtilizationHealthCheck((IConfigurationSection)null!)); } - [ConditionalTheory] + [Theory] [ClassData(typeof(HealthCheckTestData))] - [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX, SkipReason = "Windows-specific test.")] public async Task TestCpuAndMemoryChecks_WithMetrics( HealthStatus expected, double utilization, ulong memoryUsed, ulong totalMemory, ResourceUsageThresholds cpuThresholds, ResourceUsageThresholds memoryThresholds, string expectedDescription) { + if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Windows-specific test."); + var logger = new FakeLogger(); var fakeClock = new FakeTimeProvider(); var dataTracker = new Mock(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs index 4db8794a29f..a70d354362a 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.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. using System; @@ -10,15 +10,18 @@ using Microsoft.Extensions.Logging.Testing; using Microsoft.Extensions.Time.Testing; using Microsoft.Shared.Instruments; -using Microsoft.TestUtilities; using Moq; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Linux; -[OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux specific tests")] public class AcceptanceTest { + public AcceptanceTest() + { + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Windows/macOS"); + } + [Fact] public async Task LinuxUtilizationProvider_MeasuredWithKubernetesMetadata() { diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests.csproj b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests.csproj index e964e6aa3e0..a8a58ef0559 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests.csproj @@ -1,4 +1,4 @@ - + Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test @@ -9,9 +9,7 @@ - - - + diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs index 8c7d9acf373..567f359ddc5 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.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. using System; @@ -19,17 +19,17 @@ using Microsoft.Extensions.Options; using Microsoft.Extensions.Time.Testing; using Microsoft.Shared.Instruments; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; public sealed class AcceptanceTest { - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux specific tests")] + [Fact] public void Adding_Linux_Resource_Utilization_Allows_To_Query_Snapshot_Provider() { + if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux specific tests"); + using var services = new ServiceCollection() .AddResourceMonitoring() .BuildServiceProvider(); @@ -40,11 +40,12 @@ public void Adding_Linux_Resource_Utilization_Allows_To_Query_Snapshot_Provider( Assert.NotEqual(default, provider.GetSnapshot()); } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux specific tests")] + [Fact] [SuppressMessage("Minor Code Smell", "S3257:Declarations and initializations should be as concise as possible", Justification = "Broken analyzer.")] public void Adding_Linux_Resource_Utilization_Can_Be_Configured_With_Section() { + if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux specific tests"); + var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -70,10 +71,11 @@ public void Adding_Linux_Resource_Utilization_Can_Be_Configured_With_Section() Assert.Equal(memoryRefresh, options.Value.MemoryConsumptionRefreshInterval); } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux specific tests")] + [Fact] public void Adding_Linux_Resource_Utilization_Can_Be_Configured_With_Action() { + if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux specific tests"); + var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -92,11 +94,12 @@ public void Adding_Linux_Resource_Utilization_Can_Be_Configured_With_Action() Assert.Equal(memoryRefresh, options.Value.MemoryConsumptionRefreshInterval); } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux specific tests")] + [Fact] [SuppressMessage("Minor Code Smell", "S3257:Declarations and initializations should be as concise as possible", Justification = "Broken analyzer.")] public void Adding_Linux_Resource_Utilization_With_Section_Registers_SnapshotProvider_Cgroupv1() { + if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux specific tests"); + var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -141,11 +144,12 @@ public void Adding_Linux_Resource_Utilization_With_Section_Registers_SnapshotPro Assert.Equal(100_000UL, provider.Resources.MaximumMemoryInBytes); } - [ConditionalFact] - [OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux specific tests")] + [Fact] [SuppressMessage("Minor Code Smell", "S3257:Declarations and initializations should be as concise as possible", Justification = "Broken analyzer.")] public void Adding_Linux_Resource_Utilization_With_Section_Registers_SnapshotProvider_Cgroupv2() { + if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux specific tests"); + var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -190,11 +194,12 @@ public void Adding_Linux_Resource_Utilization_With_Section_Registers_SnapshotPro Assert.Equal(100_000UL, provider.Resources.MaximumMemoryInBytes); } - [ConditionalFact] + [Theory] [CombinatorialData] - [OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux specific tests")] public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgroupsv1() { + if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux specific tests"); + var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); var fileSystem = new HardcodedValueFileSystem(new Dictionary @@ -289,11 +294,12 @@ public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgrou return Task.CompletedTask; } - [ConditionalFact] + [Theory] [CombinatorialData] - [OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux specific tests")] public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgroupsv2() { + if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux specific tests"); + var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); var fileSystem = new HardcodedValueFileSystem(new Dictionary @@ -398,11 +404,12 @@ public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgrou return Task.CompletedTask; } - [ConditionalFact] + [Theory] [CombinatorialData] - [OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux specific tests")] public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgroupsv2_Using_LinuxCalculationV2() { + if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux specific tests"); + var fileSystem = new HardcodedValueFileSystem(new Dictionary { { new FileInfo("/proc/self/cgroup"), "0::/fakeslice"}, diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs index 1f7738bb030..dc4e6646de8 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs @@ -1,18 +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; using System.Collections.Generic; using System.IO; using System.Linq; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Disk.Test; -[OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux specific tests")] public class DiskStatsReaderTests { + public DiskStatsReaderTests() + { + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Windows/macOS"); + } + private static readonly string[] _skipDevicePrefixes = new[] { "ram", "loop", "dm-" }; [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs index 80ebc818894..a6f0c2321ee 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.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. using System; @@ -11,15 +11,18 @@ using Microsoft.Extensions.Logging.Testing; using Microsoft.Extensions.Time.Testing; using Microsoft.Shared.Instruments; -using Microsoft.TestUtilities; using Moq; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Disk.Test; -[OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux specific tests")] public class LinuxSystemDiskMetricsTests { + public LinuxSystemDiskMetricsTests() + { + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Windows/macOS"); + } + private static readonly string[] _skipDevicePrefixes = new[] { "ram", "loop", "dm-" }; private readonly FakeLogger _fakeLogger = new(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxNetworkMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxNetworkMetricsTests.cs index 40536a3245c..5cc5c1924cd 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxNetworkMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxNetworkMetricsTests.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. using System; @@ -10,15 +10,16 @@ using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Helpers; using Microsoft.Extensions.Time.Testing; using Microsoft.Shared.Instruments; -using Microsoft.TestUtilities; using Moq; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; -[OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux specific tests")] public class LinuxNetworkMetricsTests { + // Class-level skip condition + // Skip: if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Windows/macOS"); + private readonly Mock _tcpStateInfoProvider = new(); private readonly DateTimeOffset _startTime = DateTimeOffset.UtcNow; private FakeTimeProvider _timeProvider; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs index 3820ec254e0..d3dc1f3e95f 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.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. using System; @@ -8,16 +8,19 @@ using System.IO; using System.Threading.Tasks; using Microsoft.Shared.Pools; -using Microsoft.TestUtilities; using Moq; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; -[OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux specific tests")] public sealed class LinuxUtilizationParserCgroupV1Tests { - [ConditionalTheory] + public LinuxUtilizationParserCgroupV1Tests() + { + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Windows/macOS"); + } + + [Theory] [InlineData("DFIJEUWGHFWGBWEFWOMDOWKSLA")] [InlineData("")] [InlineData("________________________Asdasdasdas dd")] @@ -40,7 +43,7 @@ public void Parser_Throws_When_Data_Is_Invalid(string line) Assert.Throws(() => parser.GetCgroupRequestCpuV2()); } - [ConditionalFact] + [Fact] public void Parser_Can_Read_Host_And_Cgroup_Available_Cpu_Count() { var parser = new LinuxUtilizationParserCgroupV1(new FileNamesOnlyFileSystem(TestResources.TestFilesLocation), new FakeUserHz(100)); @@ -51,7 +54,7 @@ public void Parser_Can_Read_Host_And_Cgroup_Available_Cpu_Count() Assert.Equal(1.0, cgroupCpuCount); } - [ConditionalFact] + [Fact] public void Parser_Provides_Total_Available_Memory_In_Bytes() { var fs = new FileNamesOnlyFileSystem(TestResources.TestFilesLocation); @@ -62,7 +65,7 @@ public void Parser_Provides_Total_Available_Memory_In_Bytes() Assert.Equal(16_233_760UL * 1024, totalMem); } - [ConditionalTheory] + [Theory] [InlineData("----------------------")] [InlineData("@ @#dddada")] [InlineData("1231234124124")] @@ -93,7 +96,7 @@ public void When_Calling_GetMemoryUsageInBytes_Parser_Throws_When_MemoryStat_Doe Assert.Contains("total_inactive_file", r.Message); } - [ConditionalTheory] + [Theory] [InlineData("----------------------")] [InlineData("@ @#dddada")] [InlineData("_1231234124124")] @@ -119,7 +122,7 @@ public void When_Calling_GetMemoryUsageInBytes_Parser_Throws_When_UsageInBytes_D Assert.Contains("/sys/fs/cgroup/memory/memory.usage_in_bytes", r.Message); } - [ConditionalTheory] + [Theory] [InlineData(10, 1)] [InlineData(23, 22)] [InlineData(100000, 10000)] @@ -138,7 +141,7 @@ public void When_Calling_GetMemoryUsageInBytes_Parser_Throws_When_Inactive_Memor Assert.Contains("lesser than", r.Message); } - [ConditionalTheory] + [Theory] [InlineData("Mem")] [InlineData("MemTotal:")] [InlineData("MemTotal: 120")] @@ -164,7 +167,7 @@ public void When_Calling_GetHostAvailableMemory_Parser_Throws_When_MemInfo_Does_ Assert.Contains("/proc/meminfo", r.Message); } - [ConditionalTheory] + [Theory] [InlineData("kB", 231, 236544)] [InlineData("MB", 287, 300_941_312)] [InlineData("GB", 372, 399_431_958_528)] @@ -183,7 +186,7 @@ public void When_Calling_GetHostAvailableMemory_Parser_Correctly_Transforms_Supp Assert.Equal(bytes, memory); } - [ConditionalTheory] + [Theory] [InlineData("0-11", 12)] [InlineData("0", 1)] [InlineData("1000", 1)] @@ -210,7 +213,7 @@ public void When_No_Cgroup_Cpu_Limits_Are_Not_Set_We_Get_Available_Cpus_From_Cpu Assert.Equal(result, cpus); } - [ConditionalTheory] + [Theory] [InlineData("-11")] [InlineData("0-")] [InlineData("d-22")] @@ -238,7 +241,7 @@ public void Parser_Throws_When_CpuSet_Has_Invalid_Content(string content) Assert.Contains("/sys/fs/cgroup/cpuset/cpuset.cpus", r.Message); } - [ConditionalTheory] + [Theory] [InlineData("-1", "18")] [InlineData("18", "-1")] [InlineData("18", "")] @@ -259,7 +262,7 @@ public void When_Quota_And_Period_Are_Minus_One_It_Fallbacks_To_Cpuset(string qu Assert.Contains("/sys/fs/cgroup/cpuset/cpuset.cpus", r.Message); } - [ConditionalTheory] + [Theory] [InlineData("dd1d", "18")] [InlineData("-18", "18")] [InlineData("\r\r\r\r\r", "18")] @@ -287,7 +290,7 @@ public void Parser_Throws_When_Cgroup_Cpu_Files_Contain_Invalid_Data(string quot Assert.Contains("/sys/fs/cgroup/cpu/cpu.cfs_", r.Message); } - [ConditionalFact] + [Fact] public void ReadingCpuUsage_Does_Not_Throw_For_Valid_Input() { var f = new HardcodedValueFileSystem(new Dictionary @@ -301,7 +304,7 @@ public void ReadingCpuUsage_Does_Not_Throw_For_Valid_Input() Assert.Null(r); } - [ConditionalFact] + [Fact] public void ReadingTotalMemory_Does_Not_Throw_For_Valid_Input() { var f = new HardcodedValueFileSystem(new Dictionary @@ -316,7 +319,7 @@ public void ReadingTotalMemory_Does_Not_Throw_For_Valid_Input() Assert.Null(r); } - [ConditionalTheory] + [Theory] [InlineData("2569530367000")] [InlineData(" 2569530 36700 245693 4860924 82283 0 4360 0dsa 0 0 asdasd @@@@")] [InlineData("asdasd 2569530 36700 245693 4860924 82283 0 4360 0 0 0")] @@ -337,7 +340,7 @@ public void ReadingCpuUsage_Does_Throws_For_Valid_Input(string content) Assert.Contains("proc/stat", r.Message); } - [ConditionalTheory] + [Theory] [InlineData("-1")] [InlineData("")] public void Parser_Throws_When_Cgroup_Cpu_Shares_Files_Contain_Invalid_Data(string content) @@ -354,7 +357,7 @@ public void Parser_Throws_When_Cgroup_Cpu_Shares_Files_Contain_Invalid_Data(stri Assert.Contains("/sys/fs/cgroup/cpu/cpu.shares", r.Message); } - [ConditionalFact] + [Fact] public async Task ThreadSafetyAsync() { var f1 = new HardcodedValueFileSystem(new Dictionary diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs index 648b5e5afc6..3a759b69fda 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.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. using System; @@ -7,19 +7,22 @@ using System.IO; using System.Threading.Tasks; using Microsoft.Shared.Pools; -using Microsoft.TestUtilities; using Moq; using VerifyXunit; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; -[OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux specific tests")] public sealed class LinuxUtilizationParserCgroupV2Tests { + public LinuxUtilizationParserCgroupV2Tests() + { + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Windows/macOS"); + } + private const string VerifiedDataDirectory = "Verified"; - [ConditionalTheory] + [Theory] [InlineData("DFIJEUWGHFWGBWEFWOMDOWKSLA")] [InlineData("")] [InlineData("________________________Asdasdasdas dd")] @@ -43,7 +46,7 @@ public void Throws_When_Data_Is_Invalid(string line) Assert.Throws(() => parser.GetCgroupPeriodsIntervalInMicroSecondsV2()); } - [ConditionalFact] + [Fact] public void Can_Read_Host_And_Cgroup_Available_Cpu_Count() { var parser = new LinuxUtilizationParserCgroupV2(new FileNamesOnlyFileSystem(TestResources.TestFilesLocation), new FakeUserHz(100)); @@ -54,7 +57,7 @@ public void Can_Read_Host_And_Cgroup_Available_Cpu_Count() Assert.Equal(2.0, cgroupCpuCount); } - [ConditionalFact] + [Fact] public void Provides_Total_Available_Memory_In_Bytes() { var fs = new FileNamesOnlyFileSystem(TestResources.TestFilesLocation); @@ -65,7 +68,7 @@ public void Provides_Total_Available_Memory_In_Bytes() Assert.Equal(16_233_760UL * 1024, totalMem); } - [ConditionalTheory] + [Theory] [InlineData("----------------------")] [InlineData("@ @#dddada")] [InlineData("1231234124124")] @@ -95,7 +98,7 @@ public Task Throws_When_TotalInactiveFile_Is_Invalid(string content) return Verifier.Verify(r).UseParameters(content).UseDirectory(VerifiedDataDirectory); } - [ConditionalTheory] + [Theory] [InlineData("----------------------")] [InlineData("@ @#dddada")] [InlineData("_1231234124124")] @@ -120,7 +123,7 @@ public Task Throws_When_UsageInBytes_Is_Invalid(string content) return Verifier.Verify(r).UseParameters(content).UseDirectory(VerifiedDataDirectory); } - [ConditionalTheory] + [Theory] [InlineData("max\n", 134_796_910_592ul)] [InlineData("1000000\n", 1_000_000ul)] public void Returns_Available_Memory_When_AvailableMemoryInBytes_Is_Valid(string content, ulong expectedResult) @@ -137,7 +140,7 @@ public void Returns_Available_Memory_When_AvailableMemoryInBytes_Is_Valid(string Assert.Equal(expectedResult, result); } - [ConditionalTheory] + [Theory] [InlineData("Suspicious12312312")] [InlineData("string@")] [InlineData("string12312")] @@ -154,7 +157,7 @@ public Task Throws_When_AvailableMemoryInBytes_Doesnt_Contain_Just_A_Number(stri return Verifier.Verify(r).UseParameters(content).UseDirectory(VerifiedDataDirectory); } - [ConditionalFact] + [Fact] public Task Throws_When_UsageInBytes_Doesnt_Contain_A_Number() { var regexPatternforSlices = @"\w+.slice"; @@ -169,7 +172,7 @@ public Task Throws_When_UsageInBytes_Doesnt_Contain_A_Number() return Verifier.Verify(r).UseDirectory(VerifiedDataDirectory); } - [ConditionalFact] + [Fact] public void Returns_Memory_Usage_When_Memory_Usage_Is_Valid() { // When memory usage is a positive number @@ -195,7 +198,7 @@ public void Returns_Memory_Usage_When_Memory_Usage_Is_Valid() Assert.Equal(0, r); } - [ConditionalTheory] + [Theory] [InlineData(104343, 1)] [InlineData(23423, 22)] [InlineData(10000, 100)] @@ -213,7 +216,7 @@ public Task Throws_When_Inactive_Memory_Is_Bigger_Than_Total_Memory(int inactive return Verifier.Verify(r).UseParameters(inactive, total).UseDirectory(VerifiedDataDirectory); } - [ConditionalTheory] + [Theory] [InlineData("Mem")] [InlineData("MemTotal:")] [InlineData("MemTotal: 120")] @@ -238,7 +241,7 @@ public Task Throws_When_MemInfo_Does_Not_Contain_TotalMemory(string totalMemory) return Verifier.Verify(r).UseParameters(totalMemory).UseDirectory(VerifiedDataDirectory); } - [ConditionalTheory] + [Theory] [InlineData("kB", 231, 236_544)] [InlineData("MB", 287, 300_941_312)] [InlineData("GB", 372, 399_431_958_528)] @@ -256,7 +259,7 @@ public void Transforms_Supported_Units_To_Bytes(string unit, int value, ulong by Assert.Equal(bytes, memory); } - [ConditionalTheory] + [Theory] [InlineData("0-11", 12)] [InlineData("0", 1)] [InlineData("1000", 1)] @@ -282,7 +285,7 @@ public void Gets_Available_Cpus_From_CpuSetCpus_When_Cpu_Limits_Not_Set(string c Assert.Equal(result, cpus); } - [ConditionalTheory] + [Theory] [InlineData("0::/")] [InlineData("0::/fakeslice")] public void Gets_Available_Cpus_From_CpuSetCpusFromSlices_When_Cpu_Limits_Not_Set(string slicepath) @@ -300,7 +303,7 @@ public void Gets_Available_Cpus_From_CpuSetCpusFromSlices_When_Cpu_Limits_Not_Se Assert.Equal(2, cpus); } - [ConditionalTheory] + [Theory] [InlineData("100", 1)] [InlineData("1", 0.001953125)] [InlineData("10000", 256)] @@ -320,7 +323,7 @@ public void Calculates_Cpu_Request_From_Cpu_WeightInSlices(string content, float } // Based on https://github.com/kubernetes/website/blob/main/content/en/blog/_posts/2026-01-30-new-cgroup-v1-to-v2-conversion-formula/index.md#new-conversion-formula - [ConditionalTheory] + [Theory] [InlineData("100", 1)] [InlineData("1", 0.001953125)] [InlineData("10000", 256)] @@ -338,7 +341,7 @@ public void Calculates_Cpu_Request_From_Cpu_Weight(string content, float result) Assert.Equal(result, r); } - [ConditionalFact] + [Fact] public void Gets_Available_Cpus_From_CpuSetCpus_When_Cpu_Max_Set_To_Max_() { var f = new HardcodedValueFileSystem(new Dictionary @@ -353,7 +356,7 @@ public void Gets_Available_Cpus_From_CpuSetCpus_When_Cpu_Max_Set_To_Max_() Assert.Equal(3, cpus); } - [ConditionalTheory] + [Theory] [InlineData("-11")] [InlineData("0-")] [InlineData("d-22")] @@ -379,7 +382,7 @@ public Task Throws_When_CpuSet_Has_Invalid_Content(string content) return Verifier.Verify(r).UseParameters(content).UseDirectory(VerifiedDataDirectory); } - [ConditionalFact] + [Fact] public Task Fallsback_To_Cpuset_When_Quota_And_Period_Are_Minus_One_() { var f = new HardcodedValueFileSystem(new Dictionary @@ -394,7 +397,7 @@ public Task Fallsback_To_Cpuset_When_Quota_And_Period_Are_Minus_One_() return Verifier.Verify(r).UseDirectory(VerifiedDataDirectory); } - [ConditionalTheory] + [Theory] [InlineData("dd1d", "18")] [InlineData("-18", "18")] [InlineData("\r\r\r\r\r", "18")] @@ -419,7 +422,7 @@ public Task Throws_When_Cgroup_Cpu_Files_Contain_Invalid_Data(string quota, stri return Verifier.Verify(r).UseParameters(quota, period).UseDirectory(VerifiedDataDirectory); } - [ConditionalFact] + [Fact] public void Reads_CpuUsage_When_Valid_Input() { var f = new HardcodedValueFileSystem(new Dictionary @@ -433,7 +436,7 @@ public void Reads_CpuUsage_When_Valid_Input() Assert.Equal(77_994_900_000_000, r); } - [ConditionalTheory] + [Theory] [InlineData("0::/", "usage_usec 222222\nnr_periods 50", "222222000", "50")] [InlineData("0::/fakeslice", "usage_usec 222222\nnr_periods 75", "222222000", "75")] public void Reads_CpuUsageFromSlices_When_Valid_Input(string slicepath, string content, string expectedUsage, string expectedPeriods) @@ -454,7 +457,7 @@ public void Reads_CpuUsageFromSlices_When_Valid_Input(string slicepath, string c Assert.Equal(expectedPeriods, periods.ToString()); } - [ConditionalFact] + [Fact] public void Reads_TotalMemory_When_Valid_Input() { var f = new HardcodedValueFileSystem(new Dictionary @@ -469,7 +472,7 @@ public void Reads_TotalMemory_When_Valid_Input() Assert.Null(r); } - [ConditionalTheory] + [Theory] [InlineData("2569530367000")] [InlineData(" 2569530 36700 245693 4860924 82283 0 4360 0dsa")] [InlineData("asdasd 2569530 36700 245693 4860924 82283 0 4360 0 0 0")] @@ -489,7 +492,7 @@ public Task Throws_When_CpuUsage_Invalid(string content) return Verifier.Verify(r).UseParameters(content).UseDirectory(VerifiedDataDirectory); } - [ConditionalTheory] + [Theory] [InlineData("usage_", 12222)] [InlineData("dasd", -1)] [InlineData("@#dddada", 342322)] @@ -506,7 +509,7 @@ public Task Throws_When_CpuAcctUsage_Has_Invalid_Content_Both_Parts(string conte return Verifier.Verify(r).UseParameters(content, value).UseDirectory(VerifiedDataDirectory); } - [ConditionalTheory] + [Theory] [InlineData(-32131)] [InlineData(-1)] [InlineData(-15.323)] @@ -523,7 +526,7 @@ public Task Throws_When_Usage_Usec_Has_Negative_Value(int value) return Verifier.Verify(r).UseParameters(value).UseDirectory(VerifiedDataDirectory); } - [ConditionalTheory] + [Theory] [InlineData("-1")] [InlineData("dasrz3424")] [InlineData("0")] @@ -541,7 +544,7 @@ public Task Throws_When_Cgroup_Cpu_Weight_Files_Contain_Invalid_Data(string cont return Verifier.Verify(r).UseParameters(content).UseDirectory(VerifiedDataDirectory); } - [ConditionalTheory] + [Theory] [InlineData("0::/", "filename", "/sys/fs/cgroup/filename")] [InlineData("0::/filesystem.slice", "filename", "/sys/fs/cgroup/filesystem.slice/filename")] [InlineData("0::/filesystem.slice/", "filename", "/sys/fs/cgroup/filesystem.slice/filename")] @@ -558,7 +561,7 @@ public void Create_Path_From_Proc_Self_Cgroup(string content, string filename, s Assert.Equal(result, r); } - [ConditionalFact] + [Fact] public async Task Is_Thread_Safe_Async() { var f1 = new HardcodedValueFileSystem(new Dictionary diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs index 4e2a0008e7a..aa4c5099a51 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.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. using System; @@ -11,19 +11,22 @@ using Microsoft.Extensions.Logging.Testing; using Microsoft.Extensions.Time.Testing; using Microsoft.Shared.Instruments; -using Microsoft.TestUtilities; using Moq; using VerifyXunit; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; -[OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux specific tests")] public sealed class LinuxUtilizationProviderTests { + public LinuxUtilizationProviderTests() + { + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Windows/macOS"); + } + private const string VerifiedDataDirectory = "Verified"; - [ConditionalFact] + [Theory] [CombinatorialData] public void Provider_Registers_Instruments() { @@ -108,7 +111,7 @@ public void Provider_Registers_Instruments() Assert.Equal(0.5, samples.Single(i => i.instrument.Name == ResourceUtilizationInstruments.ProcessMemoryUtilization).value); } - [ConditionalFact] + [Theory] [CombinatorialData] public void Provider_Registers_Instruments_CgroupV2() { @@ -182,7 +185,7 @@ public void Provider_Registers_Instruments_CgroupV2() Assert.Equal(1, samples.Single(i => i.instrument.Name == ResourceUtilizationInstruments.ProcessMemoryUtilization).value); } - [ConditionalFact] + [Fact] public Task Provider_EmitsLogRecord() { var meterName = Guid.NewGuid().ToString(); @@ -229,7 +232,7 @@ public void Provider_Creates_Meter_With_Correct_Name() Assert.Equal(ResourceUtilizationInstruments.MeterName, meter.Name); } - [ConditionalFact] + [Theory] [CombinatorialData] public void Provider_Registers_Instruments_CgroupV2_WithoutHostCpu() { @@ -436,7 +439,7 @@ public void Provider_GetMeasurementWithRetry_UnhandledException_DoesNotBlockFutu parserMock.Verify(p => p.GetMemoryUsageInBytes(), Times.Exactly(5)); } - [ConditionalFact] + [Fact] public void Provider_WithZeroToOneRangeFalse_AndCalculationV1_ReturnsHundredBasedValues() { var logger = new FakeLogger(); @@ -513,7 +516,7 @@ public void Provider_WithZeroToOneRangeFalse_AndCalculationV1_ReturnsHundredBase Assert.Equal(1_048_576, memoryUsage); } - [ConditionalFact] + [Fact] public void Provider_WithZeroToOneRangeTrue_AndCalculationV1_ReturnsNormalizedValues() { var logger = new FakeLogger(); @@ -590,7 +593,7 @@ public void Provider_WithZeroToOneRangeTrue_AndCalculationV1_ReturnsNormalizedVa Assert.Equal(1_048_576, memoryUsage); } - [ConditionalFact] + [Fact] public void Provider_WithZeroToOneRangeFalse_AndCalculationV2_ReturnsHundredBasedValues() { var logger = new FakeLogger(); @@ -663,7 +666,7 @@ public void Provider_WithZeroToOneRangeFalse_AndCalculationV2_ReturnsHundredBase } } - [ConditionalFact] + [Fact] public void Provider_WithZeroToOneRangeTrue_AndCalculationV2_ReturnsNormalizedValues() { var logger = new FakeLogger(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs index 9746d8395a5..248278f1772 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.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. using System; @@ -6,15 +6,18 @@ using System.Linq; using System.Text; using Microsoft.Shared.Pools; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; -[OSSkipCondition(OperatingSystems.Windows | OperatingSystems.MacOSX, SkipReason = "Linux specific tests")] public sealed class OSFileSystemTests { - [ConditionalFact] + public OSFileSystemTests() + { + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Windows/macOS"); + } + + [Fact] public void GetDirectoryNames_ReturnsDirectoryNames() { var fileSystem = new OSFileSystem(); @@ -24,7 +27,7 @@ public void GetDirectoryNames_ReturnsDirectoryNames() Assert.Single(directoryNames); } - [ConditionalFact] + [Fact] public void Reading_First_File_Line_Works() { const string Content = "Name: cat"; @@ -37,7 +40,7 @@ public void Reading_First_File_Line_Works() Assert.Equal(Content, s); } - [ConditionalFact] + [Fact] public void Reading_The_Whole_File_Works() { const string Content = "user 1399428\nsystem 1124053\n"; @@ -51,7 +54,7 @@ public void Reading_The_Whole_File_Works() Assert.Equal(Content, s); } - [ConditionalTheory] + [Theory] [InlineData(128)] [InlineData(256)] [InlineData(512)] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests.csproj b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests.csproj index ff2cd26412f..b88534f1408 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests.csproj @@ -1,4 +1,4 @@ - + Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test Unit tests for Microsoft.Extensions.Diagnostics.ResourceMonitoring @@ -18,7 +18,5 @@ - - - + diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs index d2e3d5d8292..11b1ccf8cc5 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs @@ -1,18 +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; using System.Linq; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Publishers; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test; -[OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Not supported on MacOs.")] public sealed class ResourceMonitoringBuilderTests { - [ConditionalFact(Skip = "Not supported on MacOs.")] + public ResourceMonitoringBuilderTests() + { + if (OperatingSystem.IsMacOS()) Assert.Skip("Skipped on macOS"); + } + + [Fact(Skip = "Not supported on MacOs.")] public void AddPublisher_CalledOnce_AddsSinglePublisherToServiceCollection() { using var provider = new ServiceCollection() @@ -33,7 +37,7 @@ public void AddPublisher_CalledOnce_AddsSinglePublisherToServiceCollection() Assert.IsAssignableFrom(publishersArray.First()); } - [ConditionalFact] + [Fact] public void AddPublisher_CalledMultipleTimes_AddsMultiplePublishersToServiceCollection() { using var provider = new ServiceCollection() diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs index 875fbb67158..0f1227a3df7 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.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. using System; @@ -11,17 +11,17 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting.Testing; using Microsoft.Extensions.Options; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test; public sealed class ResourceMonitoringExtensionsTests { - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Not supported on MacOs.")] - [ConditionalFact] + [Fact] public void Throw_Null_When_Registration_Ingredients_Null() { + if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + var services = new ServiceCollection(); Assert.Throws(() => ((IResourceMonitorBuilder)null!).ConfigureMonitor(_ => { })); @@ -30,10 +30,11 @@ public void Throw_Null_When_Registration_Ingredients_Null() Assert.Throws(() => services.AddResourceMonitoring((b) => b.ConfigureMonitor((Action)null!))); } - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Not supported on MacOs.")] - [ConditionalFact] + [Fact] public void AddsResourceMonitoringService_ToServicesCollection() { + if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + using var provider = new ServiceCollection() .AddLogging() .AddSingleton(TimeProvider.System) @@ -51,10 +52,11 @@ public void AddsResourceMonitoringService_ToServicesCollection() Assert.IsAssignableFrom(trackerService); } - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Not supported on MacOs.")] - [ConditionalFact] + [Fact] public void AddsResourceMonitoringService_ToServicesCollection_NoArgs() { + if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + using var provider = new ServiceCollection() .AddLogging() .AddSingleton(TimeProvider.System) @@ -68,10 +70,11 @@ public void AddsResourceMonitoringService_ToServicesCollection_NoArgs() Assert.IsAssignableFrom(trackerService); } - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Not supported on MacOs.")] - [ConditionalFact] + [Fact] public void AddsResourceMonitoringService_AsHostedService() { + if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + using var provider = new ServiceCollection() .AddLogging() .AddSingleton(TimeProvider.System) @@ -90,10 +93,11 @@ public void AddsResourceMonitoringService_AsHostedService() Assert.IsAssignableFrom(trackerService); } - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Not supported on MacOs.")] - [ConditionalFact] + [Fact] public void ConfigureResourceUtilization_InitializeTrackerProperly() { + if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + using var host = FakeHost.CreateBuilder() .ConfigureServices(services => { @@ -117,10 +121,11 @@ public void ConfigureResourceUtilization_InitializeTrackerProperly() Assert.NotNull(publisher); } - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Not supported on MacOs.")] - [ConditionalFact] + [Fact] public void ConfigureMonitor_GivenOptionsDelegate_InitializeTrackerWithOptionsProperly() { + if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + const int SamplingWindowValue = 3; const int CalculationPeriodValue = 2; @@ -146,10 +151,11 @@ public void ConfigureMonitor_GivenOptionsDelegate_InitializeTrackerWithOptionsPr Assert.Equal(TimeSpan.FromSeconds(CalculationPeriodValue), options!.Value.PublishingWindow); } - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Not supported on MacOs.")] - [ConditionalFact] + [Fact] public void ConfigureMonitor_GivenIConfigurationSection_InitializeTrackerWithOptionsProperly() { + if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + const int SamplingWindowValue = 3; const int CalculationPeriod = 2; const int SamplingPeriodValue = 1; @@ -188,10 +194,11 @@ public void ConfigureMonitor_GivenIConfigurationSection_InitializeTrackerWithOpt Assert.Equal(TimeSpan.FromSeconds(CalculationPeriod), options!.Value.PublishingWindow); } - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Not supported on MacOs.")] - [ConditionalFact] + [Fact] public void Registering_Resource_Utilization_Adds_Only_One_Object_Of_Type_ResourceUtilizationService_To_DI_Container() { + if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + using var host = FakeHost.CreateBuilder() .ConfigureServices(services => { @@ -212,10 +219,11 @@ public void Registering_Resource_Utilization_Adds_Only_One_Object_Of_Type_Resour Assert.Same(tracker as ResourceMonitorService, background as ResourceMonitorService); } - [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.Windows, SkipReason = "For MacOs only.")] - [ConditionalFact] + [Fact] public void AddResourceMonitoringInternal_WhenMacOs_ReturnsSameServiceCollection() { + if ((OperatingSystem.IsWindows() || OperatingSystem.IsLinux())) Assert.Skip("For MacOs only."); + var services = new ServiceCollection(); // Act @@ -226,10 +234,11 @@ public void AddResourceMonitoringInternal_WhenMacOs_ReturnsSameServiceCollection Assert.DoesNotContain(services, s => s.ServiceType == typeof(ISnapshotProvider)); } - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Not supported on MacOs.")] - [ConditionalFact] + [Fact] public void AddResourceMonitoring_AddsISnapshotProvider() { + if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + var services = new ServiceCollection(); // Act @@ -240,10 +249,11 @@ public void AddResourceMonitoring_AddsISnapshotProvider() Assert.Contains(services, s => s.ServiceType == typeof(ISnapshotProvider)); } - [OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Not supported on MacOs.")] - [ConditionalFact] + [Fact] public void AddResourceMonitoringInternal_CallsConfigureDelegate() { + if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + var services = new ServiceCollection(); bool delegateCalled = false; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs index f2131afd3f5..f2e937c2908 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs @@ -1,23 +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; using System.Runtime.Versioning; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; using Microsoft.Extensions.Time.Testing; -using Microsoft.TestUtilities; using Moq; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Disk.Test; [SupportedOSPlatform("windows")] -[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX, SkipReason = "Windows specific.")] public class WindowsDiskIoRatePerfCounterTests { + public WindowsDiskIoRatePerfCounterTests() + { + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + } + private const string CategoryName = "LogicalDisk"; - [ConditionalFact] + [Fact] public void DiskReadsPerfCounter_Per60Seconds() { const string CounterName = WindowsDiskPerfCounterNames.DiskReadsCounter; @@ -64,7 +67,7 @@ public void DiskReadsPerfCounter_Per60Seconds() Assert.Equal(660, ratePerfCounters.TotalCountDict["D:"]); // 450 + 3.5 * 60 = 660 } - [ConditionalFact] + [Fact] public void DiskWriteBytesPerfCounter_Per30Seconds() { const string CounterName = WindowsDiskPerfCounterNames.DiskWriteBytesCounter; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs index 4daf808240b..c909581b9ac 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs @@ -5,19 +5,22 @@ using System.Runtime.Versioning; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; using Microsoft.Extensions.Time.Testing; -using Microsoft.TestUtilities; using Moq; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Disk.Test; [SupportedOSPlatform("windows")] -[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX, SkipReason = "Windows specific.")] public class WindowsDiskIoTimePerfCounterTests { + public WindowsDiskIoTimePerfCounterTests() + { + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + } + private const string CategoryName = "LogicalDisk"; - [ConditionalFact] + [Fact] public void DiskReadsPerfCounter_Per60Seconds() { const string CounterName = WindowsDiskPerfCounterNames.DiskReadsCounter; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs index a592aacce19..945ca7e43dc 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.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. using System; @@ -12,20 +12,23 @@ using Microsoft.Extensions.Logging.Testing; using Microsoft.Extensions.Time.Testing; using Microsoft.Shared.Instruments; -using Microsoft.TestUtilities; using Moq; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Disk.Test; [SupportedOSPlatform("windows")] -[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX, SkipReason = "Windows specific.")] public class WindowsDiskMetricsTests { + public WindowsDiskMetricsTests() + { + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + } + private const string CategoryName = "LogicalDisk"; private readonly FakeLogger _fakeLogger = new(); - [ConditionalFact] + [Fact] public void Creates_Meter_With_Correct_Name() { using var meterFactory = new TestMeterFactory(); @@ -43,7 +46,7 @@ public void Creates_Meter_With_Correct_Name() Assert.Equal(ResourceUtilizationInstruments.MeterName, meter.Name); } - [ConditionalFact] + [Fact] public void DiskOperationMetricsTest() { using var meterFactory = new TestMeterFactory(); @@ -117,7 +120,7 @@ public void DiskOperationMetricsTest() Assert.Equal(5700, measurements.Last(x => x.MatchesTags(writeTag, deviceTagD)).Value); // 3600 + 35 * 60 = 5700 } - [ConditionalFact] + [Fact] public void DiskIoBytesMetricsTest() { using var meterFactory = new TestMeterFactory(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs index ea20aad2d65..219411ec4e3 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs @@ -1,8 +1,8 @@ -// 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; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Interop; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; @@ -12,10 +12,14 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; /// /// These tests are added for coverage reasons, but the code doesn't have /// the necessary environment predictability to really test it. -[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX, SkipReason = "Windows specific.")] public sealed class MemoryInfoTests { - [ConditionalFact] + public MemoryInfoTests() + { + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + } + + [Fact] public void GetGlobalMemory() { var memoryStatus = new MemoryInfo().GetMemoryStatus(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs index 768fd268175..544ed532bc9 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs @@ -1,17 +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 System; using System.Runtime.Versioning; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; [SupportedOSPlatform("windows")] -[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX, SkipReason = "Windows specific.")] public class PerformanceCounterFactoryTests { - [ConditionalFact] + public PerformanceCounterFactoryTests() + { + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + } + + [Fact] public void GetInstanceNameTest() { var performanceCounterFactory = new PerformanceCounterFactory(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs index f27646ae327..5224c60bbce 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs @@ -1,17 +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 System; using System.Runtime.Versioning; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; [SupportedOSPlatform("windows")] -[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX, SkipReason = "Windows specific.")] public class PerformanceCounterWrapperTests { - [ConditionalFact] + public PerformanceCounterWrapperTests() + { + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + } + + [Fact] public void GetInstanceNameTest() { var wrapper = new PerformanceCounterWrapper("Processor", "% Processor Time", "_Total"); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/ProcessInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/ProcessInfoTests.cs index ab83f2677df..cda6bb24da8 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/ProcessInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/ProcessInfoTests.cs @@ -1,8 +1,7 @@ -// 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.Extensions.Diagnostics.ResourceMonitoring.Windows.Interop; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; @@ -14,7 +13,7 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; /// the necessary environment predictability to really test it. public sealed class ProcessInfoTests { - [ConditionalFact] + [Fact] public void GetCurrentProcessMemoryUsage() { var workingSet64 = new ProcessInfo().GetCurrentProcessMemoryUsage(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs index a0e9485bd00..54c814ccccc 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs @@ -1,8 +1,8 @@ -// 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; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Interop; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; @@ -12,13 +12,17 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; /// /// These tests are added for coverage reasons, but the code doesn't have /// the necessary environment predictability to really test it. -[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX, SkipReason = "Windows specific.")] public sealed class SystemInfoTests { + public SystemInfoTests() + { + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + } + /// /// Get basic system info. /// - [ConditionalFact] + [Fact] public void GetSystemInfo() { var sysInfo = new SystemInfo().GetSystemInfo(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Tcp6TableInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Tcp6TableInfoTests.cs index a5dfdb5c170..e070885c4e6 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Tcp6TableInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Tcp6TableInfoTests.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. using System; @@ -6,7 +6,6 @@ using System.Runtime.InteropServices; using System.Threading; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Network; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; @@ -15,9 +14,13 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; /// Keep this Test to distinguish different tests for IPv6. /// [Collection("Tcp Connection Tests")] -[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX, SkipReason = "Windows specific.")] public sealed class Tcp6TableInfoTests { + public Tcp6TableInfoTests() + { + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + } + public static readonly TimeSpan DefaultTimeSpan = TimeSpan.FromSeconds(5); public static DateTimeOffset StartTimestamp = DateTimeOffset.UtcNow; public static DateTimeOffset NextTimestamp = StartTimestamp.Add(DefaultTimeSpan); @@ -226,7 +229,7 @@ public static uint FakeGetTcp6TableWithFakeInformation(IntPtr pTcp6Table, ref ui return (uint)NTSTATUS.Success; } - [ConditionalFact] + [Fact] public void Test_Tcp6TableInfo_Get_UnsuccessfulStatus_All_The_Time() { var options = new ResourceMonitoringOptions @@ -243,7 +246,7 @@ public void Test_Tcp6TableInfo_Get_UnsuccessfulStatus_All_The_Time() }); } - [ConditionalFact] + [Fact] public void Test_Tcp6TableInfo_Get_InsufficientBuffer_Then_Get_InvalidParameter() { var options = new ResourceMonitoringOptions @@ -259,7 +262,7 @@ public void Test_Tcp6TableInfo_Get_InsufficientBuffer_Then_Get_InvalidParameter( }); } - [ConditionalFact] + [Fact] public void Test_Tcp6TableInfo_Get_Correct_Information() { StartTimestamp = DateTimeOffset.UtcNow; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/TcpTableInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/TcpTableInfoTests.cs index 8c88fc123dd..f46cc8b6c73 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/TcpTableInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/TcpTableInfoTests.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. using System; @@ -6,15 +6,18 @@ using System.Runtime.InteropServices; using System.Threading; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Network; -using Microsoft.TestUtilities; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; [Collection("Tcp Connection Tests")] -[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX, SkipReason = "Windows specific.")] public sealed class TcpTableInfoTests { + public TcpTableInfoTests() + { + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + } + public static readonly TimeSpan DefaultTimeSpan = TimeSpan.FromSeconds(5); public static DateTimeOffset StartTimestamp = DateTimeOffset.UtcNow; public static DateTimeOffset NextTimestamp = StartTimestamp.Add(DefaultTimeSpan); @@ -169,7 +172,7 @@ public static unsafe uint FakeGetTcpTableWithFakeInformation(IntPtr pTcpTable, r return (uint)NTSTATUS.Success; } - [ConditionalFact] + [Fact] public void Test_TcpTableInfo_Get_UnsuccessfulStatus_All_The_Time() { var options = new ResourceMonitoringOptions @@ -185,7 +188,7 @@ public void Test_TcpTableInfo_Get_UnsuccessfulStatus_All_The_Time() }); } - [ConditionalFact] + [Fact] public void Test_TcpTableInfo_Get_InsufficientBuffer_Then_Get_InvalidParameter() { var options = new ResourceMonitoringOptions @@ -201,7 +204,7 @@ public void Test_TcpTableInfo_Get_InsufficientBuffer_Then_Get_InvalidParameter() }); } - [ConditionalFact] + [Fact] public void Test_TcpTableInfo_Get_Correct_Information() { StartTimestamp = DateTimeOffset.UtcNow; @@ -262,7 +265,7 @@ public void Test_TcpTableInfo_Get_Correct_Information() Assert.Equal(2, tcpStateInfo.DeleteTcbCount); } - [ConditionalFact] + [Fact] public void Test_TcpTableInfo_CalculateCount_default_branch() { TcpStateInfo tcpStateInfo = new(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs index bafb5816eb9..c70a1511450 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs @@ -1,21 +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. +using System; using System.Diagnostics.Metrics; using System.Linq; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Helpers; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Network; using Microsoft.Shared.Instruments; -using Microsoft.TestUtilities; using Moq; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; -[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX, SkipReason = "Windows specific.")] public class WindowsNetworkMetricsTests { - [ConditionalFact] + public WindowsNetworkMetricsTests() + { + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + } + + [Fact] public void Creates_Meter_With_Correct_Name() { using var meterFactory = new TestMeterFactory(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsSnapshotProviderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsSnapshotProviderTests.cs index 32cf5117aac..d92a87fa361 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsSnapshotProviderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsSnapshotProviderTests.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. using System; @@ -12,16 +12,17 @@ using Microsoft.Extensions.Options; using Microsoft.Extensions.Time.Testing; using Microsoft.Shared.Instruments; -using Microsoft.TestUtilities; using Moq; using VerifyXunit; using Xunit; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; -[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX, SkipReason = "Windows specific.")] public sealed class WindowsSnapshotProviderTests { + // Class-level skip condition + // Skip: if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + private const string VerifiedDataDirectory = "Verified"; private readonly Mock _meterFactoryMock; @@ -39,7 +40,7 @@ public WindowsSnapshotProviderTests() _fakeLogger = new FakeLogger(); } - [ConditionalFact] + [Fact] public void BasicConstructor() { var provider = new WindowsSnapshotProvider(_fakeLogger, _meterFactoryMock.Object, _options); @@ -51,7 +52,7 @@ public void BasicConstructor() Assert.Equal(memoryStatus.TotalPhys, provider.Resources.MaximumMemoryInBytes); } - [ConditionalFact] + [Fact] public void GetSnapshot_DoesNotThrowExceptions() { var provider = new WindowsSnapshotProvider(_fakeLogger, _meterFactoryMock.Object, _options); @@ -60,7 +61,7 @@ public void GetSnapshot_DoesNotThrowExceptions() Assert.Null(exception); } - [ConditionalFact] + [Fact] public Task SnapshotProvider_EmitsLogRecord() { var provider = new WindowsSnapshotProvider(_fakeLogger, _meterFactoryMock.Object, _options); @@ -71,7 +72,7 @@ public Task SnapshotProvider_EmitsLogRecord() return Verifier.Verify(logRecords[0]).UseDirectory(VerifiedDataDirectory); } - [ConditionalTheory] + [Theory] [CombinatorialData] public void SnapshotProvider_EmitsCpuMetrics(bool useZeroToOneRange) { @@ -112,7 +113,7 @@ public void SnapshotProvider_EmitsCpuMetrics(bool useZeroToOneRange) Assert.Equal(0.05 * multiplier, metricCollector.LastMeasurement?.Value); // Still consuming 5% of the CPU } - [ConditionalTheory] + [Theory] [CombinatorialData] public void SnapshotProvider_EmitsMemoryMetrics(bool useZeroToOneRange) { @@ -162,7 +163,7 @@ public void SnapshotProvider_EmitsMemoryMetrics(bool useZeroToOneRange) Assert.Equal(1 * multiplier, Math.Round(metricCollector.LastMeasurement.Value)); // Consuming 100% of the memory } - [ConditionalFact] + [Fact] public void Provider_Returns_MemoryConsumption() { // This is a synthetic test to have full test coverage: @@ -170,7 +171,7 @@ public void Provider_Returns_MemoryConsumption() Assert.InRange(usage, 0, long.MaxValue); } - [ConditionalFact] + [Fact] public void Provider_Creates_Meter_With_Correct_Name() { using var meterFactory = new TestMeterFactory(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.Testing.Tests/Logging/FakeLogCollectorTests.LogEnumeration.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.Testing.Tests/Logging/FakeLogCollectorTests.LogEnumeration.cs index 9ded05209d5..cf5a748542f 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.Testing.Tests/Logging/FakeLogCollectorTests.LogEnumeration.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.Testing.Tests/Logging/FakeLogCollectorTests.LogEnumeration.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. using System; @@ -8,7 +8,6 @@ using System.Threading; using System.Threading.Tasks; using Xunit; -using Xunit.Abstractions; namespace Microsoft.Extensions.Logging.Testing.Test.Logging; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.Testing.Tests/Logging/FakeLogCollectorTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.Testing.Tests/Logging/FakeLogCollectorTests.cs index 63ce2a7e718..8a5b8aad268 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.Testing.Tests/Logging/FakeLogCollectorTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.Testing.Tests/Logging/FakeLogCollectorTests.cs @@ -1,11 +1,10 @@ -// 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; using System.Globalization; using Microsoft.Extensions.Time.Testing; using Xunit; -using Xunit.Abstractions; namespace Microsoft.Extensions.Logging.Testing.Test.Logging; @@ -14,6 +13,15 @@ public partial class FakeLogCollectorTests private class Output : ITestOutputHelper { public string Last { get; private set; } = string.Empty; + public string Output1 => Last; + string ITestOutputHelper.Output => Output1; + + public void Write(string message) + { + Last += message; + } + + public void Write(string format, params object[] args) => Write(string.Format(CultureInfo.InvariantCulture, format, args)); public void WriteLine(string message) { diff --git a/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/CancellationTests.cs b/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/CancellationTests.cs index 786882afc1d..1e19807c7f4 100644 --- a/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/CancellationTests.cs +++ b/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/CancellationTests.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Sockets; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Extensions.ServiceDiscovery.Dns.Resolver.Tests; diff --git a/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/LoopbackDnsTestBase.cs b/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/LoopbackDnsTestBase.cs index 6d2aba6cb64..ca3fecddcd8 100644 --- a/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/LoopbackDnsTestBase.cs +++ b/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/LoopbackDnsTestBase.cs @@ -9,7 +9,7 @@ using Microsoft.Extensions.Options; using Microsoft.Extensions.ServiceDiscovery.Dns.Tests; using Microsoft.Extensions.Time.Testing; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Extensions.ServiceDiscovery.Dns.Resolver.Tests; diff --git a/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/ResolveAddressesTests.cs b/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/ResolveAddressesTests.cs index 0a6c97a26c1..cc1940d7d14 100644 --- a/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/ResolveAddressesTests.cs +++ b/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/ResolveAddressesTests.cs @@ -3,7 +3,7 @@ using System.Net; using System.Net.Sockets; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Extensions.ServiceDiscovery.Dns.Resolver.Tests; diff --git a/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/ResolveServiceTests.cs b/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/ResolveServiceTests.cs index 82ca3175789..1ff9c1c8738 100644 --- a/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/ResolveServiceTests.cs +++ b/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/ResolveServiceTests.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Net; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Extensions.ServiceDiscovery.Dns.Resolver.Tests; diff --git a/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/RetryTests.cs b/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/RetryTests.cs index 3d6f3724484..a8017223851 100644 --- a/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/RetryTests.cs +++ b/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/RetryTests.cs @@ -3,7 +3,7 @@ using System.Net; using System.Net.Sockets; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Extensions.ServiceDiscovery.Dns.Resolver.Tests; diff --git a/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/TcpFailoverTests.cs b/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/TcpFailoverTests.cs index b2891cfb512..a6a4769b7fc 100644 --- a/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/TcpFailoverTests.cs +++ b/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/TcpFailoverTests.cs @@ -3,7 +3,7 @@ using System.Net; using System.Net.Sockets; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Extensions.ServiceDiscovery.Dns.Resolver.Tests; diff --git a/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/XunitLoggerFactoryExtensions.cs b/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/XunitLoggerFactoryExtensions.cs index 6667688f16e..71a4a9907df 100644 --- a/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/XunitLoggerFactoryExtensions.cs +++ b/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/XunitLoggerFactoryExtensions.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. using System; @@ -9,7 +9,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Extensions.ServiceDiscovery.Dns.Tests; diff --git a/test/ProjectTemplates/Infrastructure/DotNetNewCommand.cs b/test/ProjectTemplates/Infrastructure/DotNetNewCommand.cs index e013d0d4e4e..ba0ed105755 100644 --- a/test/ProjectTemplates/Infrastructure/DotNetNewCommand.cs +++ b/test/ProjectTemplates/Infrastructure/DotNetNewCommand.cs @@ -1,9 +1,9 @@ -// 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; using System.Threading.Tasks; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Shared.ProjectTemplates.Tests; diff --git a/test/ProjectTemplates/Infrastructure/MessageSinkTestOutputHelper.cs b/test/ProjectTemplates/Infrastructure/MessageSinkTestOutputHelper.cs index 6118a0ad4e2..3b3e5e2b740 100644 --- a/test/ProjectTemplates/Infrastructure/MessageSinkTestOutputHelper.cs +++ b/test/ProjectTemplates/Infrastructure/MessageSinkTestOutputHelper.cs @@ -1,7 +1,7 @@ -// 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 Xunit.Abstractions; +using Xunit; using Xunit.Sdk; namespace Microsoft.Shared.ProjectTemplates.Tests; @@ -9,19 +9,36 @@ namespace Microsoft.Shared.ProjectTemplates.Tests; public sealed class MessageSinkTestOutputHelper : ITestOutputHelper { private readonly IMessageSink _messageSink; + private string _output = string.Empty; public MessageSinkTestOutputHelper(IMessageSink messageSink) { _messageSink = messageSink; } + public string Output => _output; + + public void Write(string message) + { + _output += message; + _messageSink.OnMessage(new DiagnosticMessage(message)); + } + + public void Write(string format, params object[] args) + { + _messageSink.OnMessage(new DiagnosticMessage(format, args)); + _output += string.Format(System.Globalization.CultureInfo.InvariantCulture, format, args); + } + public void WriteLine(string message) { + _output += message + Environment.NewLine; _messageSink.OnMessage(new DiagnosticMessage(message)); } public void WriteLine(string format, params object[] args) { + _output += string.Format(System.Globalization.CultureInfo.InvariantCulture, format, args) + Environment.NewLine; _messageSink.OnMessage(new DiagnosticMessage(format, args)); } } diff --git a/test/ProjectTemplates/Infrastructure/TemplateExecutionTestBase.cs b/test/ProjectTemplates/Infrastructure/TemplateExecutionTestBase.cs index 188f5022fd1..3c60679c82a 100644 --- a/test/ProjectTemplates/Infrastructure/TemplateExecutionTestBase.cs +++ b/test/ProjectTemplates/Infrastructure/TemplateExecutionTestBase.cs @@ -1,10 +1,9 @@ -// 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; using System.Threading.Tasks; using Xunit; -using Xunit.Abstractions; namespace Microsoft.Shared.ProjectTemplates.Tests; diff --git a/test/ProjectTemplates/Infrastructure/TemplateExecutionTestClassFixtureBase.cs b/test/ProjectTemplates/Infrastructure/TemplateExecutionTestClassFixtureBase.cs index 4c9939d960a..8083774b029 100644 --- a/test/ProjectTemplates/Infrastructure/TemplateExecutionTestClassFixtureBase.cs +++ b/test/ProjectTemplates/Infrastructure/TemplateExecutionTestClassFixtureBase.cs @@ -1,11 +1,10 @@ -// 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; using System.IO; using System.Threading.Tasks; using Xunit; -using Xunit.Abstractions; namespace Microsoft.Shared.ProjectTemplates.Tests; diff --git a/test/ProjectTemplates/Infrastructure/TestCommand.cs b/test/ProjectTemplates/Infrastructure/TestCommand.cs index dfe89030cad..8cb9fa2a687 100644 --- a/test/ProjectTemplates/Infrastructure/TestCommand.cs +++ b/test/ProjectTemplates/Infrastructure/TestCommand.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. using System; @@ -7,7 +7,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using Xunit.Abstractions; +using Xunit; namespace Microsoft.Shared.ProjectTemplates.Tests; diff --git a/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/AIAgentWebAPIExecutionTests.cs b/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/AIAgentWebAPIExecutionTests.cs index 675fb642aa6..68674e9016e 100644 --- a/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/AIAgentWebAPIExecutionTests.cs +++ b/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/AIAgentWebAPIExecutionTests.cs @@ -5,7 +5,6 @@ using System.Threading.Tasks; using Microsoft.Shared.ProjectTemplates.Tests; using Xunit; -using Xunit.Abstractions; using static Microsoft.Shared.ProjectTemplates.Tests.TemplateTestUtilities; namespace Microsoft.Agents.AI.ProjectTemplates.Tests; diff --git a/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/AIAgentWebAPISnapshotTests.cs b/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/AIAgentWebAPISnapshotTests.cs index a93915e3252..4e8ed5e1b75 100644 --- a/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/AIAgentWebAPISnapshotTests.cs +++ b/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/AIAgentWebAPISnapshotTests.cs @@ -7,7 +7,6 @@ using Microsoft.TemplateEngine.Authoring.TemplateVerifier; using Microsoft.TemplateEngine.TestHelper; using Xunit; -using Xunit.Abstractions; using static Microsoft.Shared.ProjectTemplates.Tests.TemplateTestUtilities; namespace Microsoft.Agents.AI.ProjectTemplates.Tests; diff --git a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebExecutionTests.cs b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebExecutionTests.cs index 513f4cf0394..7cd46fa6b27 100644 --- a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebExecutionTests.cs +++ b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebExecutionTests.cs @@ -1,12 +1,10 @@ -// 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.Generic; using System.Threading.Tasks; using Microsoft.Shared.ProjectTemplates.Tests; -using Microsoft.TestUtilities; using Xunit; -using Xunit.Abstractions; using static Microsoft.Shared.ProjectTemplates.Tests.TemplateTestUtilities; namespace Microsoft.Extensions.AI.Templates.Tests; @@ -105,7 +103,7 @@ public async Task CreateRestoreAndBuild_AspireProjectName() /// Set the environment variable AI_TEMPLATES_TEST_PROJECT_NAMES to "true" or "1" /// to enable it. /// - [ConditionalTheory] + [Theory] [EnvironmentVariableCondition("AI_TEMPLATES_TEST_PROJECT_NAMES", "true", "1")] [InlineData("dot.name")] [InlineData("project.123")] diff --git a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebSnapshotTests.cs b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebSnapshotTests.cs index dbe71cdbdef..78940fd60b9 100644 --- a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebSnapshotTests.cs +++ b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebSnapshotTests.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. using System.Threading.Tasks; @@ -7,7 +7,6 @@ using Microsoft.TemplateEngine.Authoring.TemplateVerifier; using Microsoft.TemplateEngine.TestHelper; using Xunit; -using Xunit.Abstractions; using static Microsoft.Shared.ProjectTemplates.Tests.TemplateTestUtilities; namespace Microsoft.Extensions.AI.Templates.Tests; diff --git a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Microsoft.Extensions.AI.Templates.Tests.csproj b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Microsoft.Extensions.AI.Templates.Tests.csproj index da35b77fca9..a8bc07b9b05 100644 --- a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Microsoft.Extensions.AI.Templates.Tests.csproj +++ b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Microsoft.Extensions.AI.Templates.Tests.csproj @@ -1,4 +1,4 @@ - + Tests for Microsoft.Extensions.AI.Templates. @@ -19,10 +19,6 @@ - - - - diff --git a/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/McpServerExecutionTests.cs b/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/McpServerExecutionTests.cs index 48aaee30a1c..345a3a27181 100644 --- a/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/McpServerExecutionTests.cs +++ b/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/McpServerExecutionTests.cs @@ -1,11 +1,10 @@ -// 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.Generic; using System.Threading.Tasks; using Microsoft.Shared.ProjectTemplates.Tests; using Xunit; -using Xunit.Abstractions; using static Microsoft.Shared.ProjectTemplates.Tests.TemplateTestUtilities; namespace Microsoft.Extensions.AI.Templates.Tests; diff --git a/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/McpServerSnapshotTests.cs b/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/McpServerSnapshotTests.cs index 60e38c0f504..629f2307e0f 100644 --- a/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/McpServerSnapshotTests.cs +++ b/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/McpServerSnapshotTests.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. using System.Threading.Tasks; @@ -7,7 +7,6 @@ using Microsoft.TemplateEngine.Authoring.TemplateVerifier; using Microsoft.TemplateEngine.TestHelper; using Xunit; -using Xunit.Abstractions; namespace Microsoft.Extensions.AI.Templates.Tests; diff --git a/test/Shared/Shared.Tests.csproj b/test/Shared/Shared.Tests.csproj index 2764d5f5d5d..7b661aa1ab6 100644 --- a/test/Shared/Shared.Tests.csproj +++ b/test/Shared/Shared.Tests.csproj @@ -7,7 +7,7 @@ $(NoWarn);CA1716;S104 $(TestNetCoreTargetFrameworks) - $(TestNetCoreTargetFrameworks)$(ConditionalNet462) + $(TestNetCoreTargetFrameworks);net472 diff --git a/test/TestUtilities/TestUtilities.csproj b/test/TestUtilities/TestUtilities.csproj deleted file mode 100644 index d9e307f1e6d..00000000000 --- a/test/TestUtilities/TestUtilities.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - Microsoft.TestUtilities - Microsoft.TestUtilities - $(TestNetCoreTargetFrameworks)$(ConditionalNet462) - - - - - - - - diff --git a/test/TestUtilities/XUnit/ConditionalFactAttribute.cs b/test/TestUtilities/XUnit/ConditionalFactAttribute.cs deleted file mode 100644 index 92077e27dbc..00000000000 --- a/test/TestUtilities/XUnit/ConditionalFactAttribute.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// Borrowed from https://github.com/dotnet/aspnetcore/blob/95ed45c67/src/Testing/src/xunit/ - -using System; -using Xunit; -using Xunit.Sdk; - -namespace Microsoft.TestUtilities; - -[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] -[XunitTestCaseDiscoverer("Microsoft.TestUtilities." + nameof(ConditionalFactDiscoverer), "Microsoft.TestUtilities")] -public class ConditionalFactAttribute : FactAttribute -{ -} diff --git a/test/TestUtilities/XUnit/ConditionalFactDiscoverer.cs b/test/TestUtilities/XUnit/ConditionalFactDiscoverer.cs deleted file mode 100644 index e007d95860a..00000000000 --- a/test/TestUtilities/XUnit/ConditionalFactDiscoverer.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// Borrowed from https://github.com/dotnet/aspnetcore/blob/95ed45c67/src/Testing/src/xunit/ - -using Xunit.Abstractions; -using Xunit.Sdk; - -// Do not change this namespace without changing the usage in ConditionalFactAttribute -namespace Microsoft.TestUtilities; - -internal sealed class ConditionalFactDiscoverer : FactDiscoverer -{ - private readonly IMessageSink _diagnosticMessageSink; - - public ConditionalFactDiscoverer(IMessageSink diagnosticMessageSink) - : base(diagnosticMessageSink) - { - _diagnosticMessageSink = diagnosticMessageSink; - } - - protected override IXunitTestCase CreateTestCase(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute) - { - var skipReason = testMethod.EvaluateSkipConditions(); - return skipReason != null - ? new SkippedTestCase(skipReason, _diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), TestMethodDisplayOptions.None, testMethod) - : new SkippedFactTestCase(DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), - discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod); // Test case skippable at runtime. - } -} diff --git a/test/TestUtilities/XUnit/ConditionalTheoryAttribute.cs b/test/TestUtilities/XUnit/ConditionalTheoryAttribute.cs deleted file mode 100644 index d5f23068dd0..00000000000 --- a/test/TestUtilities/XUnit/ConditionalTheoryAttribute.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// Borrowed from https://github.com/dotnet/aspnetcore/blob/95ed45c67/src/Testing/src/xunit/ - -using System; -using Xunit; -using Xunit.Sdk; - -namespace Microsoft.TestUtilities; - -[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] -[XunitTestCaseDiscoverer("Microsoft.TestUtilities." + nameof(ConditionalTheoryDiscoverer), "Microsoft.TestUtilities")] -public class ConditionalTheoryAttribute : TheoryAttribute -{ -} diff --git a/test/TestUtilities/XUnit/ConditionalTheoryDiscoverer.cs b/test/TestUtilities/XUnit/ConditionalTheoryDiscoverer.cs deleted file mode 100644 index e30b5206c8c..00000000000 --- a/test/TestUtilities/XUnit/ConditionalTheoryDiscoverer.cs +++ /dev/null @@ -1,95 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// Borrowed from https://github.com/dotnet/aspnetcore/blob/95ed45c67/src/Testing/src/xunit/ - -using System.Collections.Generic; -using Xunit.Abstractions; -using Xunit.Sdk; - -// Do not change this namespace without changing the usage in ConditionalTheoryAttribute -namespace Microsoft.TestUtilities; - -internal sealed class ConditionalTheoryDiscoverer : TheoryDiscoverer -{ - public ConditionalTheoryDiscoverer(IMessageSink diagnosticMessageSink) - : base(diagnosticMessageSink) - { - } - - private sealed class OptionsWithPreEnumerationEnabled : ITestFrameworkDiscoveryOptions - { - private const string PreEnumerateTheories = "xunit.discovery.PreEnumerateTheories"; - - private readonly ITestFrameworkDiscoveryOptions _original; - - public OptionsWithPreEnumerationEnabled(ITestFrameworkDiscoveryOptions original) - { - _original = original; - } - - public TValue GetValue(string name) - => (name == PreEnumerateTheories) ? (TValue)(object)true : _original.GetValue(name); - - public void SetValue(string name, TValue value) - => _original.SetValue(name, value); - } - - public override IEnumerable Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute) - => base.Discover(new OptionsWithPreEnumerationEnabled(discoveryOptions), testMethod, theoryAttribute); - - protected override IEnumerable CreateTestCasesForTheory(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute) - { - var skipReason = testMethod.EvaluateSkipConditions(); - return skipReason != null - ? new[] { new SkippedTestCase(skipReason, DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), TestMethodDisplayOptions.None, testMethod) } - : base.CreateTestCasesForTheory(discoveryOptions, testMethod, theoryAttribute); - } - - protected override IEnumerable CreateTestCasesForDataRow(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute, object[]? dataRow) - { - var skipReason = testMethod.EvaluateSkipConditions(); - if (skipReason == null && dataRow?.Length > 0) - { - var obj = dataRow[0]; - if (obj != null) - { - var type = obj.GetType(); - var property = type.GetProperty("Skip"); - if (property != null && property.PropertyType.Equals(typeof(string))) - { - skipReason = property.GetValue(obj) as string; - } - } - } - - if (skipReason != null) - { - return base.CreateTestCasesForSkippedDataRow(discoveryOptions, testMethod, theoryAttribute, dataRow, skipReason); - } - - // Create test cases that can handle runtime SkipTestException - return new[] - { - new SkippedTheoryTestCase( - DiagnosticMessageSink, - discoveryOptions.MethodDisplayOrDefault(), - discoveryOptions.MethodDisplayOptionsOrDefault(), - testMethod, - dataRow) - }; - } - - protected override IEnumerable CreateTestCasesForSkippedDataRow( - ITestFrameworkDiscoveryOptions discoveryOptions, - ITestMethod testMethod, - IAttributeInfo theoryAttribute, - object[] dataRow, - string skipReason) - { - return new[] - { - new WORKAROUND_SkippedDataRowTestCase(DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, skipReason, dataRow), - }; - } -} diff --git a/test/TestUtilities/XUnit/EnvironmentVariableConditionAttribute.cs b/test/TestUtilities/XUnit/EnvironmentVariableConditionAttribute.cs deleted file mode 100644 index 45a54409047..00000000000 --- a/test/TestUtilities/XUnit/EnvironmentVariableConditionAttribute.cs +++ /dev/null @@ -1,86 +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.Linq; - -namespace Microsoft.TestUtilities; - -/// -/// Skips a test based on the value of an environment variable. -/// -[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)] -public class EnvironmentVariableConditionAttribute : Attribute, ITestCondition -{ - private string? _currentValue; - - /// - /// Initializes a new instance of the class. - /// - /// Name of the environment variable. - /// Value(s) of the environment variable to match for the condition. - /// - /// By default, the test will be run if the value of the variable matches any of the supplied values. - /// Set to False to run the test only if the value does not match. - /// - public EnvironmentVariableConditionAttribute(string variableName, params string[] values) - { - if (string.IsNullOrEmpty(variableName)) - { - throw new ArgumentException("Value cannot be null or empty.", nameof(variableName)); - } - - if (values == null || values.Length == 0) - { - throw new ArgumentException("You must supply at least one value to match.", nameof(values)); - } - - VariableName = variableName; - Values = values; - } - - /// - /// Gets or sets a value indicating whether the test should run if the value of the variable matches any - /// of the supplied values. If False, the test runs only if the value does not match any of the - /// supplied values. Default is True. - /// - public bool RunOnMatch { get; set; } = true; - - /// - /// Gets the name of the environment variable. - /// - public string VariableName { get; } - - /// - /// Gets the value(s) of the environment variable to match for the condition. - /// - public string[] Values { get; } - - /// - /// Gets a value indicating whether the condition is met for the configured environment variable and values. - /// - public bool IsMet - { - get - { - _currentValue ??= Environment.GetEnvironmentVariable(VariableName); - var hasMatched = Values.Any(value => string.Equals(value, _currentValue, StringComparison.OrdinalIgnoreCase)); - - return RunOnMatch ? hasMatched : !hasMatched; - } - } - - /// - /// Gets a value indicating the reason the test was skipped. - /// - public string SkipReason - { - get - { - var value = _currentValue ?? "(null)"; - - return $"Test skipped on environment variable with name '{VariableName}' and value '{value}' " + - $"for the '{nameof(RunOnMatch)}' value of '{RunOnMatch}'."; - } - } -} diff --git a/test/TestUtilities/XUnit/ITestCondition.cs b/test/TestUtilities/XUnit/ITestCondition.cs deleted file mode 100644 index 347f3c69007..00000000000 --- a/test/TestUtilities/XUnit/ITestCondition.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// Borrowed from https://github.com/dotnet/aspnetcore/blob/95ed45c67/src/Testing/src/xunit/ - -namespace Microsoft.TestUtilities; - -public interface ITestCondition -{ - bool IsMet { get; } - - string SkipReason { get; } -} diff --git a/test/TestUtilities/XUnit/OSSkipConditionAttribute.cs b/test/TestUtilities/XUnit/OSSkipConditionAttribute.cs deleted file mode 100644 index 586b53d3fcb..00000000000 --- a/test/TestUtilities/XUnit/OSSkipConditionAttribute.cs +++ /dev/null @@ -1,69 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// Borrowed from https://github.com/dotnet/aspnetcore/blob/95ed45c67/src/Testing/src/xunit/ - -using System; -#if NETCOREAPP || NET471_OR_GREATER -using System.Runtime.InteropServices; -#endif - -namespace Microsoft.TestUtilities; - -#pragma warning disable CA1019 // Define accessors for attribute arguments -[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)] -public class OSSkipConditionAttribute : Attribute, ITestCondition -{ - private readonly OperatingSystems _excludedOperatingSystem; - private readonly OperatingSystems _osPlatform; - - public OSSkipConditionAttribute(OperatingSystems operatingSystem) - : this(operatingSystem, GetCurrentOS()) - { - } - - // to enable unit testing - internal OSSkipConditionAttribute(OperatingSystems operatingSystem, OperatingSystems osPlatform) - { - _excludedOperatingSystem = operatingSystem; - _osPlatform = osPlatform; - } - - public bool IsMet - { - get - { - var skip = (_excludedOperatingSystem & _osPlatform) == _osPlatform; - - // Since a test would be executed only if 'IsMet' is true, return false if we want to skip - return !skip; - } - } - - public string SkipReason { get; set; } = "Test cannot run on this operating system."; - - private static OperatingSystems GetCurrentOS() - { -#if NETCOREAPP || NET471_OR_GREATER - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return OperatingSystems.Windows; - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - return OperatingSystems.Linux; - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - return OperatingSystems.MacOSX; - } - - throw new PlatformNotSupportedException(); -#else - // RuntimeInformation API is only available in .NET Framework 4.7.1+ - // .NET Framework 4.7 and below can only run on Windows. - return OperatingSystems.Windows; -#endif - } -} -#pragma warning restore CA1019 // Define accessors for attribute arguments diff --git a/test/TestUtilities/XUnit/OperatingSystems.cs b/test/TestUtilities/XUnit/OperatingSystems.cs deleted file mode 100644 index 3bee3bac969..00000000000 --- a/test/TestUtilities/XUnit/OperatingSystems.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// Borrowed from https://github.com/dotnet/aspnetcore/blob/95ed45c67/src/Testing/src/xunit/ - -using System; - -namespace Microsoft.TestUtilities; - -[Flags] -public enum OperatingSystems -{ - Linux = 1, - MacOSX = 2, - Windows = 4, -} diff --git a/test/TestUtilities/XUnit/SkipTestException.cs b/test/TestUtilities/XUnit/SkipTestException.cs deleted file mode 100644 index 70f7d53c7d8..00000000000 --- a/test/TestUtilities/XUnit/SkipTestException.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// Borrowed from https://github.com/dotnet/aspnetcore/blob/95ed45c67/src/Testing/src/xunit/ - -using System; - -namespace Microsoft.TestUtilities; - -public class SkipTestException : Exception -{ - public SkipTestException(string reason) - : base(reason) - { - } -} diff --git a/test/TestUtilities/XUnit/SkippedFactTestCase.cs b/test/TestUtilities/XUnit/SkippedFactTestCase.cs deleted file mode 100644 index 79ace15ea6e..00000000000 --- a/test/TestUtilities/XUnit/SkippedFactTestCase.cs +++ /dev/null @@ -1,42 +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.Threading; -using System.Threading.Tasks; -using Xunit.Abstractions; -using Xunit.Sdk; - -namespace Microsoft.TestUtilities; - -public class SkippedFactTestCase : XunitTestCase -{ - [Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes", error: true)] - public SkippedFactTestCase() - { - } - - public SkippedFactTestCase( - IMessageSink diagnosticMessageSink, TestMethodDisplay defaultMethodDisplay, TestMethodDisplayOptions defaultMethodDisplayOptions, - ITestMethod testMethod, object[]? testMethodArguments = null) - : base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, testMethodArguments) - { - } - - public override async Task RunAsync(IMessageSink diagnosticMessageSink, - IMessageBus messageBus, - object[] constructorArguments, - ExceptionAggregator aggregator, - CancellationTokenSource cancellationTokenSource) - { - using SkippedTestMessageBus skipMessageBus = new(messageBus); - var result = await base.RunAsync(diagnosticMessageSink, skipMessageBus, constructorArguments, aggregator, cancellationTokenSource); - if (skipMessageBus.SkippedTestCount > 0) - { - result.Failed -= skipMessageBus.SkippedTestCount; - result.Skipped += skipMessageBus.SkippedTestCount; - } - - return result; - } -} diff --git a/test/TestUtilities/XUnit/SkippedTestCase.cs b/test/TestUtilities/XUnit/SkippedTestCase.cs deleted file mode 100644 index 7b59125ffb8..00000000000 --- a/test/TestUtilities/XUnit/SkippedTestCase.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// Borrowed from https://github.com/dotnet/aspnetcore/blob/95ed45c67/src/Testing/src/xunit/ - -#nullable disable - -using System; -using Xunit.Abstractions; -using Xunit.Sdk; - -namespace Microsoft.TestUtilities; - -public class SkippedTestCase : XunitTestCase -{ - private string _skipReason; - - [Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] - public SkippedTestCase() - { - } - - public SkippedTestCase( - string skipReason, - IMessageSink diagnosticMessageSink, - TestMethodDisplay defaultMethodDisplay, - TestMethodDisplayOptions defaultMethodDisplayOptions, - ITestMethod testMethod, - object[] testMethodArguments = null) - : base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, testMethodArguments) - { - _skipReason = skipReason; - } - - protected override string GetSkipReason(IAttributeInfo factAttribute) - => _skipReason ?? base.GetSkipReason(factAttribute); - - public override void Deserialize(IXunitSerializationInfo data) - { - _skipReason = data.GetValue(nameof(_skipReason)); - - // We need to call base after reading our value, because Deserialize will call - // into GetSkipReason. - base.Deserialize(data); - } - - public override void Serialize(IXunitSerializationInfo data) - { - base.Serialize(data); - data.AddValue(nameof(_skipReason), _skipReason); - } -} diff --git a/test/TestUtilities/XUnit/SkippedTestMessageBus.cs b/test/TestUtilities/XUnit/SkippedTestMessageBus.cs deleted file mode 100644 index 230586852b8..00000000000 --- a/test/TestUtilities/XUnit/SkippedTestMessageBus.cs +++ /dev/null @@ -1,44 +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.Linq; -using Xunit.Abstractions; -using Xunit.Sdk; - -namespace Microsoft.TestUtilities; - -/// Implements message bus to communicate tests skipped via SkipTestException. -public sealed class SkippedTestMessageBus : IMessageBus -{ - private readonly IMessageBus _innerBus; - - public SkippedTestMessageBus(IMessageBus innerBus) - { - _innerBus = innerBus; - } - - public int SkippedTestCount { get; private set; } - - public void Dispose() - { - // nothing to dispose - } - - public bool QueueMessage(IMessageSinkMessage message) - { - var testFailed = message as ITestFailed; - - if (testFailed != null) - { - var exceptionType = testFailed.ExceptionTypes.FirstOrDefault(); - if (exceptionType == typeof(SkipTestException).FullName) - { - SkippedTestCount++; - return _innerBus.QueueMessage(new TestSkipped(testFailed.Test, testFailed.Messages.FirstOrDefault())); - } - } - - // Nothing we care about, send it on its way - return _innerBus.QueueMessage(message); - } -} diff --git a/test/TestUtilities/XUnit/SkippedTheoryTestCase.cs b/test/TestUtilities/XUnit/SkippedTheoryTestCase.cs deleted file mode 100644 index e91a8f762d5..00000000000 --- a/test/TestUtilities/XUnit/SkippedTheoryTestCase.cs +++ /dev/null @@ -1,49 +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.Threading; -using System.Threading.Tasks; -using Xunit.Abstractions; -using Xunit.Sdk; - -namespace Microsoft.TestUtilities; - -/// -/// A test case for ConditionalTheory that can handle runtime SkipTestException -/// by wrapping the message bus with SkippedTestMessageBus. -/// -public class SkippedTheoryTestCase : XunitTestCase -{ - [Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes", error: true)] - public SkippedTheoryTestCase() - { - } - - public SkippedTheoryTestCase( - IMessageSink diagnosticMessageSink, - TestMethodDisplay defaultMethodDisplay, - TestMethodDisplayOptions defaultMethodDisplayOptions, - ITestMethod testMethod, - object[]? testMethodArguments = null) - : base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, testMethodArguments) - { - } - - public override async Task RunAsync(IMessageSink diagnosticMessageSink, - IMessageBus messageBus, - object[] constructorArguments, - ExceptionAggregator aggregator, - CancellationTokenSource cancellationTokenSource) - { - using SkippedTestMessageBus skipMessageBus = new(messageBus); - var result = await base.RunAsync(diagnosticMessageSink, skipMessageBus, constructorArguments, aggregator, cancellationTokenSource); - if (skipMessageBus.SkippedTestCount > 0) - { - result.Failed -= skipMessageBus.SkippedTestCount; - result.Skipped += skipMessageBus.SkippedTestCount; - } - - return result; - } -} \ No newline at end of file diff --git a/test/TestUtilities/XUnit/TestMethodExtensions.cs b/test/TestUtilities/XUnit/TestMethodExtensions.cs deleted file mode 100644 index 88356330daf..00000000000 --- a/test/TestUtilities/XUnit/TestMethodExtensions.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// Borrowed from https://github.com/dotnet/aspnetcore/blob/95ed45c67/src/Testing/src/xunit/ - -using System.Linq; -using Xunit.Abstractions; -using Xunit.Sdk; - -namespace Microsoft.TestUtilities; - -public static class TestMethodExtensions -{ - public static string? EvaluateSkipConditions(this ITestMethod testMethod) - { - var testClass = testMethod.TestClass.Class; - var assembly = testMethod.TestClass.TestCollection.TestAssembly.Assembly; - var conditionAttributes = testMethod.Method - .GetCustomAttributes(typeof(ITestCondition)) - .Concat(testClass.GetCustomAttributes(typeof(ITestCondition))) - .Concat(assembly.GetCustomAttributes(typeof(ITestCondition))) - .OfType() - .Select(attributeInfo => attributeInfo.Attribute); - - foreach (ITestCondition condition in conditionAttributes.OfType()) - { - if (!condition.IsMet) - { - return condition.SkipReason; - } - } - - return null; - } -} diff --git a/test/TestUtilities/XUnit/WORKAROUND_SkippedDataRowTestCase.cs b/test/TestUtilities/XUnit/WORKAROUND_SkippedDataRowTestCase.cs deleted file mode 100644 index 123dba2fa48..00000000000 --- a/test/TestUtilities/XUnit/WORKAROUND_SkippedDataRowTestCase.cs +++ /dev/null @@ -1,88 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -// Borrowed from https://github.com/dotnet/aspnetcore/blob/95ed45c67/src/Testing/src/xunit/ - -using System; -using System.ComponentModel; -using Xunit.Abstractions; -using Xunit.Sdk; - -namespace Microsoft.TestUtilities; - -// This is a workaround for https://github.com/xunit/xunit/issues/1782 - as such, this code is a copy-paste -// from xUnit with the exception of fixing the bug. -// -// This will only work with [ConditionalTheory]. -internal sealed class WORKAROUND_SkippedDataRowTestCase : XunitTestCase -{ - private string? _skipReason; - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] - public WORKAROUND_SkippedDataRowTestCase() - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The message sink used to send diagnostic messages. - /// Default method display to use (when not customized). - /// The test method this test case belongs to. - /// The reason that this test case will be skipped. - /// The arguments for the test method. - [Obsolete("Please call the constructor which takes TestMethodDisplayOptions")] - public WORKAROUND_SkippedDataRowTestCase(IMessageSink diagnosticMessageSink, - TestMethodDisplay defaultMethodDisplay, - ITestMethod testMethod, - string skipReason, - object[]? testMethodArguments = null) - : this(diagnosticMessageSink, defaultMethodDisplay, TestMethodDisplayOptions.None, testMethod, skipReason, testMethodArguments) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The message sink used to send diagnostic messages. - /// Default method display to use (when not customized). - /// Default method display options to use (when not customized). - /// The test method this test case belongs to. - /// The reason that this test case will be skipped. - /// The arguments for the test method. - public WORKAROUND_SkippedDataRowTestCase(IMessageSink diagnosticMessageSink, - TestMethodDisplay defaultMethodDisplay, - TestMethodDisplayOptions defaultMethodDisplayOptions, - ITestMethod testMethod, - string skipReason, - object[]? testMethodArguments = null) - : base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, testMethodArguments) - { - _skipReason = skipReason; - } - - /// - public override void Deserialize(IXunitSerializationInfo data) - { - // SkipReason has to be read before we call base.Deserialize, this is the workaround. - _skipReason = data.GetValue("SkipReason"); - - base.Deserialize(data); - } - - /// - protected override string? GetSkipReason(IAttributeInfo factAttribute) - { - return _skipReason; - } - - /// - public override void Serialize(IXunitSerializationInfo data) - { - base.Serialize(data); - - data.AddValue("SkipReason", _skipReason); - } -} From 3d227382fa502e69af0be3b824c95ce307699707 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Jul 2026 13:42:37 +0000 Subject: [PATCH 02/19] Fix xUnit v3 migration: IAsyncLifetime ValueTask, type conflicts, missing usings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix IAsyncLifetime implementations to return ValueTask (xUnit v3 requirement) - Add xunit.core/xunit.extensibility.core exclusions for ProjectTemplate tests - Fix Fact→Theory for data-driven tests with CombinatorialData - Add missing 'using System;' for OperatingSystem references --- eng/packages/Tests.props | 3 +++ .../AzureStorage/AzureResponseCacheTests.cs | 4 ++-- .../AzureStorage/AzureResultStoreTests.cs | 4 ++-- .../DiskBased/DiskBasedResponseCacheTests.cs | 4 ++-- .../DiskBased/DiskBasedResultStoreTests.cs | 4 ++-- .../Microsoft.Agents.AI.ProjectTemplates.Tests.csproj | 6 +++++- .../Microsoft.Extensions.AI.Templates.Tests.csproj | 6 +++++- .../Microsoft.McpServer.ProjectTemplates.Tests.csproj | 6 +++++- 8 files changed, 26 insertions(+), 11 deletions(-) diff --git a/eng/packages/Tests.props b/eng/packages/Tests.props index 5f80b404aa6..af48fbcea90 100644 --- a/eng/packages/Tests.props +++ b/eng/packages/Tests.props @@ -35,6 +35,9 @@ + + + diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResponseCacheTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResponseCacheTests.cs index 2f936621147..025980febc0 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResponseCacheTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResponseCacheTests.cs @@ -35,9 +35,9 @@ public AzureResponseCacheTests() _dirClient = _fsClient?.GetDirectoryClient(Path.GetRandomFileName()); } - public Task InitializeAsync() => Task.CompletedTask; + public ValueTask InitializeAsync() => ValueTask.CompletedTask; - public async Task DisposeAsync() + public async ValueTask DisposeAsync() { if (Settings.Current.Configured) { diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResultStoreTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResultStoreTests.cs index 62163d5e681..b2cb06c822c 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResultStoreTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResultStoreTests.cs @@ -35,9 +35,9 @@ public AzureResultStoreTests() _dirClient = _fsClient?.GetDirectoryClient(Path.GetRandomFileName()); } - public Task InitializeAsync() => Task.CompletedTask; + public ValueTask InitializeAsync() => ValueTask.CompletedTask; - public async Task DisposeAsync() + public async ValueTask DisposeAsync() { if (_dirClient is not null) { diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResponseCacheTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResponseCacheTests.cs index 8305fe8ddb3..a74b6fbf8ff 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResponseCacheTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResponseCacheTests.cs @@ -22,9 +22,9 @@ private string UseTempStoragePath() return path; } - public Task InitializeAsync() => Task.CompletedTask; + public ValueTask InitializeAsync() => ValueTask.CompletedTask; - public Task DisposeAsync() + public ValueTask DisposeAsync() { foreach (string path in _tempStorage) { diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResultStoreTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResultStoreTests.cs index 77cabfd7ffd..d9859a762d3 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResultStoreTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResultStoreTests.cs @@ -21,9 +21,9 @@ private string UseTempStoragePath() return path; } - public Task InitializeAsync() => Task.CompletedTask; + public ValueTask InitializeAsync() => ValueTask.CompletedTask; - public Task DisposeAsync() + public ValueTask DisposeAsync() { foreach (string path in _tempStorage) { diff --git a/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/Microsoft.Agents.AI.ProjectTemplates.Tests.csproj b/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/Microsoft.Agents.AI.ProjectTemplates.Tests.csproj index df94c9d0841..84e6e9ddd79 100644 --- a/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/Microsoft.Agents.AI.ProjectTemplates.Tests.csproj +++ b/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/Microsoft.Agents.AI.ProjectTemplates.Tests.csproj @@ -11,7 +11,11 @@ - + + build + + + diff --git a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Microsoft.Extensions.AI.Templates.Tests.csproj b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Microsoft.Extensions.AI.Templates.Tests.csproj index a8bc07b9b05..36723c4536c 100644 --- a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Microsoft.Extensions.AI.Templates.Tests.csproj +++ b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Microsoft.Extensions.AI.Templates.Tests.csproj @@ -11,7 +11,11 @@ - + + build + + + diff --git a/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/Microsoft.McpServer.ProjectTemplates.Tests.csproj b/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/Microsoft.McpServer.ProjectTemplates.Tests.csproj index 7548fbfe084..47cbd2948f8 100644 --- a/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/Microsoft.McpServer.ProjectTemplates.Tests.csproj +++ b/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/Microsoft.McpServer.ProjectTemplates.Tests.csproj @@ -11,7 +11,11 @@ - + + build + + + From de66fb7b053546279ec53ad40de88d430b591fbf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Jul 2026 14:32:56 +0000 Subject: [PATCH 03/19] Fix XunitLoggerProvider v2/v3 ITestOutputHelper type mismatch with adapter class Create TestOutputHelperAdapter to bridge xUnit v3's Xunit.ITestOutputHelper to xUnit v2's Xunit.Abstractions.ITestOutputHelper expected by Microsoft.TemplateEngine.TestHelper.XunitLoggerProvider. --- eng/packages/Tests.props | 3 --- test/Directory.Packages.props | 6 +++++ ...Microsoft.Gen.Logging.HelperLibrary.csproj | 3 +++ .../DiskBased/DiskBasedResponseCacheTests.cs | 2 +- .../DiskBased/DiskBasedResultStoreTests.cs | 2 +- .../OllamaSharpChatClientIntegrationTests.cs | 10 ++++++-- .../OpenAIResponseClientIntegrationTests.cs | 1 + .../TagSetTests.cs | 2 +- .../Readers/DocumentReaderConformanceTests.cs | 1 + .../Readers/MarkItDownReaderTests.cs | 11 ++++++--- .../MessageSinkTestOutputHelper.cs | 12 +++++----- .../TemplateExecutionTestBase.cs | 1 + .../TemplateExecutionTestClassFixtureBase.cs | 7 +++--- .../Infrastructure/TestOutputHelperAdapter.cs | 23 +++++++++++++++++++ .../AIAgentWebAPISnapshotTests.cs | 2 +- ...ft.Agents.AI.ProjectTemplates.Tests.csproj | 3 ++- .../AIChatWebExecutionTests.cs | 6 ++++- .../AIChatWebSnapshotTests.cs | 2 +- ...osoft.Extensions.AI.Templates.Tests.csproj | 3 ++- .../McpServerSnapshotTests.cs | 2 +- ...ft.McpServer.ProjectTemplates.Tests.csproj | 3 ++- 21 files changed, 78 insertions(+), 27 deletions(-) create mode 100644 test/ProjectTemplates/Infrastructure/TestOutputHelperAdapter.cs diff --git a/eng/packages/Tests.props b/eng/packages/Tests.props index af48fbcea90..5f80b404aa6 100644 --- a/eng/packages/Tests.props +++ b/eng/packages/Tests.props @@ -35,9 +35,6 @@ - - - diff --git a/test/Directory.Packages.props b/test/Directory.Packages.props index 010335bc108..0dc0c30db82 100644 --- a/test/Directory.Packages.props +++ b/test/Directory.Packages.props @@ -3,4 +3,10 @@ + + + + + + diff --git a/test/Generators/Microsoft.Gen.Logging/HelperLibrary/Microsoft.Gen.Logging.HelperLibrary.csproj b/test/Generators/Microsoft.Gen.Logging/HelperLibrary/Microsoft.Gen.Logging.HelperLibrary.csproj index 65fa2220f3a..e9e877bf1d7 100644 --- a/test/Generators/Microsoft.Gen.Logging/HelperLibrary/Microsoft.Gen.Logging.HelperLibrary.csproj +++ b/test/Generators/Microsoft.Gen.Logging/HelperLibrary/Microsoft.Gen.Logging.HelperLibrary.csproj @@ -2,6 +2,9 @@ Microsoft.Gen.Logging.Test Test classes for Microsoft.Gen.Logging.Generated.Tests. + + Library + false diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResponseCacheTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResponseCacheTests.cs index a74b6fbf8ff..7697f0aeece 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResponseCacheTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResponseCacheTests.cs @@ -40,7 +40,7 @@ public ValueTask DisposeAsync() } } - return Task.CompletedTask; + return ValueTask.CompletedTask; } internal override bool IsConfigured => true; diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResultStoreTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResultStoreTests.cs index d9859a762d3..e199ffe3c7a 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResultStoreTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResultStoreTests.cs @@ -39,7 +39,7 @@ public ValueTask DisposeAsync() } } - return Task.CompletedTask; + return ValueTask.CompletedTask; } public override bool IsConfigured => true; diff --git a/test/Libraries/Microsoft.Extensions.AI.OllamaSharp.Integration.Tests/OllamaSharpChatClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.OllamaSharp.Integration.Tests/OllamaSharpChatClientIntegrationTests.cs index 31fbe2fffef..475c9dfa1cf 100644 --- a/test/Libraries/Microsoft.Extensions.AI.OllamaSharp.Integration.Tests/OllamaSharpChatClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.OllamaSharp.Integration.Tests/OllamaSharpChatClientIntegrationTests.cs @@ -18,11 +18,17 @@ public class OllamaSharpChatClientIntegrationTests : ChatClientIntegrationTests new OllamaApiClient(endpoint, "llama3.2") : null; - public override Task FunctionInvocation_RequireAny() => + public override Task FunctionInvocation_RequireAny() + { Assert.Skip("Ollama does not currently support requiring function invocation."); + return Task.CompletedTask; // Unreachable + } - public override Task FunctionInvocation_RequireSpecific() => + public override Task FunctionInvocation_RequireSpecific() + { Assert.Skip("Ollama does not currently support requiring function invocation."); + return Task.CompletedTask; // Unreachable + } protected override string? GetModel_MultiModal_DescribeImage() => "llava"; diff --git a/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientIntegrationTests.cs index 047450de19e..ae9d6f38169 100644 --- a/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientIntegrationTests.cs @@ -512,6 +512,7 @@ public async Task RemoteMCP_Connector() Assert.Skip( "To run this test, set a value for RemoteMCP:ConnectorAccessToken. " + "You can obtain one by following https://platform.openai.com/docs/guides/tools-connectors-mcp?quickstart-panels=connector#authorizing-a-connector."); + return; // Unreachable, but needed for definite assignment of 'accessToken'. } await RunAsync(false, false); diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/TagSetTests.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/TagSetTests.cs index 818dac7b45c..71e59c76fc5 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/TagSetTests.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/TagSetTests.cs @@ -165,7 +165,7 @@ string Create() { const string Alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"; var len = rand.Next(3, 8); -#if NET462 +#if NETFRAMEWORK char[] chars = new char[len]; #else Span chars = stackalloc char[len]; diff --git a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/DocumentReaderConformanceTests.cs b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/DocumentReaderConformanceTests.cs index ad281fea900..3fc4f10c6f8 100644 --- a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/DocumentReaderConformanceTests.cs +++ b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/DocumentReaderConformanceTests.cs @@ -172,6 +172,7 @@ protected static async Task DownloadAsync(Uri uri) catch (Exception ex) { Assert.Skip($"Unable to download the test file: '{ex.Message}'"); + throw; // Unreachable, but needed to satisfy compiler return requirement. } } diff --git a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownReaderTests.cs b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownReaderTests.cs index c778a75b848..fc22029aaeb 100644 --- a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownReaderTests.cs +++ b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownReaderTests.cs @@ -12,9 +12,14 @@ namespace Microsoft.Extensions.DataIngestion.Readers.Tests; public class MarkItDownReaderTests : DocumentReaderConformanceTests { protected override IngestionDocumentReader CreateDocumentReader(bool extractImages = false) - => MarkItDownConditionAttribute.IsInstalled.Value - ? new MarkItDownReader(extractImages: extractImages) - : Assert.Skip("MarkItDown is not installed"); + { + if (!MarkItDownConditionAttribute.IsInstalled.Value) + { + Assert.Skip("MarkItDown is not installed"); + } + + return new MarkItDownReader(extractImages: extractImages); + } protected override void SimpleAsserts(IngestionDocument document, string source, string expectedId) { diff --git a/test/ProjectTemplates/Infrastructure/MessageSinkTestOutputHelper.cs b/test/ProjectTemplates/Infrastructure/MessageSinkTestOutputHelper.cs index 3b3e5e2b740..b01ec6432ad 100644 --- a/test/ProjectTemplates/Infrastructure/MessageSinkTestOutputHelper.cs +++ b/test/ProjectTemplates/Infrastructure/MessageSinkTestOutputHelper.cs @@ -21,24 +21,24 @@ public MessageSinkTestOutputHelper(IMessageSink messageSink) public void Write(string message) { _output += message; - _messageSink.OnMessage(new DiagnosticMessage(message)); + _messageSink.OnMessage(new Xunit.v3.DiagnosticMessage(message)); } public void Write(string format, params object[] args) { - _messageSink.OnMessage(new DiagnosticMessage(format, args)); + _messageSink.OnMessage(new Xunit.v3.DiagnosticMessage(format, args)); _output += string.Format(System.Globalization.CultureInfo.InvariantCulture, format, args); } public void WriteLine(string message) { - _output += message + Environment.NewLine; - _messageSink.OnMessage(new DiagnosticMessage(message)); + _output += message + System.Environment.NewLine; + _messageSink.OnMessage(new Xunit.v3.DiagnosticMessage(message)); } public void WriteLine(string format, params object[] args) { - _output += string.Format(System.Globalization.CultureInfo.InvariantCulture, format, args) + Environment.NewLine; - _messageSink.OnMessage(new DiagnosticMessage(format, args)); + _output += string.Format(System.Globalization.CultureInfo.InvariantCulture, format, args) + System.Environment.NewLine; + _messageSink.OnMessage(new Xunit.v3.DiagnosticMessage(format, args)); } } diff --git a/test/ProjectTemplates/Infrastructure/TemplateExecutionTestBase.cs b/test/ProjectTemplates/Infrastructure/TemplateExecutionTestBase.cs index 3c60679c82a..14d29102bfe 100644 --- a/test/ProjectTemplates/Infrastructure/TemplateExecutionTestBase.cs +++ b/test/ProjectTemplates/Infrastructure/TemplateExecutionTestBase.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; using Xunit; +using Xunit.Sdk; namespace Microsoft.Shared.ProjectTemplates.Tests; diff --git a/test/ProjectTemplates/Infrastructure/TemplateExecutionTestClassFixtureBase.cs b/test/ProjectTemplates/Infrastructure/TemplateExecutionTestClassFixtureBase.cs index 8083774b029..ed35526a3f8 100644 --- a/test/ProjectTemplates/Infrastructure/TemplateExecutionTestClassFixtureBase.cs +++ b/test/ProjectTemplates/Infrastructure/TemplateExecutionTestClassFixtureBase.cs @@ -5,6 +5,7 @@ using System.IO; using System.Threading.Tasks; using Xunit; +using Xunit.Sdk; namespace Microsoft.Shared.ProjectTemplates.Tests; @@ -42,7 +43,7 @@ protected TemplateExecutionTestClassFixtureBase(TemplateExecutionTestConfigurati _sandboxProjectsPath = Path.Combine(_sandboxOutput, "projects"); } - public async Task InitializeAsync() + public async ValueTask InitializeAsync() { // Here, we clear execution test output from the previous test run, if it exists. // It's critical that this clearing happens *before* the tests start, *not* after they complete. @@ -156,9 +157,9 @@ public void SetCurrentTestOutputHelper(ITestOutputHelper? outputHelper) _currentTestOutputHelper = outputHelper; } - public Task DisposeAsync() + public ValueTask DisposeAsync() { // Only here to implement IAsyncLifetime. Not currently used. - return Task.CompletedTask; + return ValueTask.CompletedTask; } } diff --git a/test/ProjectTemplates/Infrastructure/TestOutputHelperAdapter.cs b/test/ProjectTemplates/Infrastructure/TestOutputHelperAdapter.cs new file mode 100644 index 00000000000..dd60c4a1a87 --- /dev/null +++ b/test/ProjectTemplates/Infrastructure/TestOutputHelperAdapter.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.Shared.ProjectTemplates.Tests; + +/// +/// Adapts xUnit v3's to xUnit v2's +/// for use with libraries +/// that still depend on the v2 interface. +/// +internal sealed class TestOutputHelperAdapter : Xunit.Abstractions.ITestOutputHelper +{ + private readonly Xunit.ITestOutputHelper _inner; + + public TestOutputHelperAdapter(Xunit.ITestOutputHelper inner) + { + _inner = inner; + } + + public void WriteLine(string message) => _inner.WriteLine(message); + + public void WriteLine(string format, params object[] args) => _inner.WriteLine(format, args); +} diff --git a/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/AIAgentWebAPISnapshotTests.cs b/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/AIAgentWebAPISnapshotTests.cs index 4e8ed5e1b75..ac9906b1e45 100644 --- a/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/AIAgentWebAPISnapshotTests.cs +++ b/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/AIAgentWebAPISnapshotTests.cs @@ -18,7 +18,7 @@ public class AIAgentWebAPISnapshotTests : TemplateSnapshotTestBase public AIAgentWebAPISnapshotTests(ITestOutputHelper log) { #pragma warning disable CA2000 // Dispose objects before losing scope - _log = new XunitLoggerProvider(log).CreateLogger("TestRun"); + _log = new XunitLoggerProvider(new TestOutputHelperAdapter(log)).CreateLogger("TestRun"); #pragma warning restore CA2000 // Dispose objects before losing scope } diff --git a/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/Microsoft.Agents.AI.ProjectTemplates.Tests.csproj b/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/Microsoft.Agents.AI.ProjectTemplates.Tests.csproj index 84e6e9ddd79..8801f8af566 100644 --- a/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/Microsoft.Agents.AI.ProjectTemplates.Tests.csproj +++ b/test/ProjectTemplates/Microsoft.Agents.AI.ProjectTemplates.IntegrationTests/Microsoft.Agents.AI.ProjectTemplates.Tests.csproj @@ -12,8 +12,9 @@ - build + build;buildTransitive + diff --git a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebExecutionTests.cs b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebExecutionTests.cs index 7cd46fa6b27..74bfd3ffdd6 100644 --- a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebExecutionTests.cs +++ b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebExecutionTests.cs @@ -104,7 +104,6 @@ public async Task CreateRestoreAndBuild_AspireProjectName() /// to enable it. /// [Theory] - [EnvironmentVariableCondition("AI_TEMPLATES_TEST_PROJECT_NAMES", "true", "1")] [InlineData("dot.name")] [InlineData("project.123")] [InlineData("space name")] @@ -115,6 +114,11 @@ public async Task CreateRestoreAndBuild_AspireProjectName() [InlineData("nomatch")] public async Task CreateRestoreAndBuild_AspireProjectName_Variants(string projectName) { + string? envValue = System.Environment.GetEnvironmentVariable("AI_TEMPLATES_TEST_PROJECT_NAMES"); + Assert.SkipUnless( + string.Equals(envValue, "true", System.StringComparison.OrdinalIgnoreCase) || envValue == "1", + "Set the environment variable AI_TEMPLATES_TEST_PROJECT_NAMES to 'true' or '1' to enable this test."); + await CreateRestoreAndBuild(projectName, ["--aspire", "--provider", "azureopenai"]); } } diff --git a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebSnapshotTests.cs b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebSnapshotTests.cs index 78940fd60b9..ddc3b050580 100644 --- a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebSnapshotTests.cs +++ b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AIChatWebSnapshotTests.cs @@ -23,7 +23,7 @@ public class AIChatWebSnapshotTests : TemplateSnapshotTestBase public AIChatWebSnapshotTests(ITestOutputHelper log) { #pragma warning disable CA2000 // Dispose objects before losing scope - _log = new XunitLoggerProvider(log).CreateLogger("TestRun"); + _log = new XunitLoggerProvider(new TestOutputHelperAdapter(log)).CreateLogger("TestRun"); #pragma warning restore CA2000 // Dispose objects before losing scope } diff --git a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Microsoft.Extensions.AI.Templates.Tests.csproj b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Microsoft.Extensions.AI.Templates.Tests.csproj index 36723c4536c..cc01093d8b0 100644 --- a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Microsoft.Extensions.AI.Templates.Tests.csproj +++ b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Microsoft.Extensions.AI.Templates.Tests.csproj @@ -12,8 +12,9 @@ - build + build;buildTransitive + diff --git a/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/McpServerSnapshotTests.cs b/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/McpServerSnapshotTests.cs index 629f2307e0f..00d23071fc6 100644 --- a/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/McpServerSnapshotTests.cs +++ b/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/McpServerSnapshotTests.cs @@ -17,7 +17,7 @@ public class McpServerSnapshotTests : TemplateSnapshotTestBase public McpServerSnapshotTests(ITestOutputHelper log) { #pragma warning disable CA2000 // Dispose objects before losing scope - _log = new XunitLoggerProvider(log).CreateLogger("TestRun"); + _log = new XunitLoggerProvider(new TestOutputHelperAdapter(log)).CreateLogger("TestRun"); #pragma warning restore CA2000 // Dispose objects before losing scope } diff --git a/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/Microsoft.McpServer.ProjectTemplates.Tests.csproj b/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/Microsoft.McpServer.ProjectTemplates.Tests.csproj index 47cbd2948f8..0f210f7268b 100644 --- a/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/Microsoft.McpServer.ProjectTemplates.Tests.csproj +++ b/test/ProjectTemplates/Microsoft.McpServer.ProjectTemplates.IntegrationTests/Microsoft.McpServer.ProjectTemplates.Tests.csproj @@ -12,8 +12,9 @@ - build + build;buildTransitive + From d3b5748a4c7aa0ad6772725d74d50713653b9838 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Jul 2026 14:56:13 +0000 Subject: [PATCH 04/19] Remove reference to non-existent test/TestUtilities/TestUtilities.csproj from Slngen.ps1 --- scripts/Slngen.ps1 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/Slngen.ps1 b/scripts/Slngen.ps1 index 1980f458e94..5924fcb03ea 100755 --- a/scripts/Slngen.ps1 +++ b/scripts/Slngen.ps1 @@ -169,10 +169,6 @@ Push-Location $RepositoryPath try { [System.Collections.ArrayList]$Globs = @() - if (!$OnlySources) { - $Globs += "test/TestUtilities/TestUtilities.csproj" - } - if (!$All) { foreach ($Keyword in $Keywords) { $Globs += "src/**/*$($Keyword)*/**/*.*sproj" From a2fa86fcb9b2057fa5a9c62bd35fcd896cf2cb1b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Jul 2026 15:51:17 +0000 Subject: [PATCH 05/19] Fix IDE0011, IDE0055, xUnit1006, CA1822 warnings treated as errors in CI - Add braces to all `if (...) Assert.Skip(...)` statements (IDE0011/IDE0055) - Change [Theory][CombinatorialData] to [Fact] for parameterless methods (xUnit1006) - Make MarkItDownConditionAttribute.SkipReason static (CA1822) --- .../FakeCertificateFactoryTests.cs | 10 +++- .../DiskBased/PathValidationTests.cs | 55 +++++++++++++++---- .../HybridCacheEventSourceTests.cs | 10 +++- .../Readers/MarkItDownConditionAttribute.cs | 2 +- .../Linux/LinuxResourceHealthCheckTests.cs | 5 +- .../ResourceHealthCheckExtensionsTests.cs | 10 +++- .../Linux/AcceptanceTest.cs | 5 +- .../Linux/AcceptanceTest.cs | 49 ++++++++++++----- .../Linux/Disk/DiskStatsReaderTests.cs | 5 +- .../Linux/Disk/LinuxSystemDiskMetricsTests.cs | 5 +- .../LinuxUtilizationParserCgroupV1Tests.cs | 5 +- .../LinuxUtilizationParserCgroupV2Tests.cs | 5 +- .../Linux/LinuxUtilizationProviderTests.cs | 14 ++--- .../Linux/OSFileSystemTests.cs | 5 +- .../ResourceMonitoringBuilderTests.cs | 5 +- .../ResourceMonitoringExtensionsTests.cs | 55 +++++++++++++++---- .../Disk/WindowsDiskIoRatePerfCounterTests.cs | 5 +- .../Disk/WindowsDiskIoTimePerfCounterTests.cs | 5 +- .../Windows/Disk/WindowsDiskMetricsTests.cs | 5 +- .../Windows/MemoryInfoTests.cs | 5 +- .../Windows/PerformanceCounterFactoryTests.cs | 5 +- .../Windows/PerformanceCounterWrapperTests.cs | 5 +- .../Windows/SystemInfoTests.cs | 5 +- .../Windows/Tcp6TableInfoTests.cs | 5 +- .../Windows/TcpTableInfoTests.cs | 5 +- .../Windows/WindowsNetworkMetricsTests.cs | 5 +- 26 files changed, 227 insertions(+), 68 deletions(-) diff --git a/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs b/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs index b8aab2bd227..b8a1d5a4597 100644 --- a/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs +++ b/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs @@ -27,7 +27,10 @@ public void Create_CreatesCertificate() [InlineData(true)] public void GenerateRsa_RunsOnWindows_GeneratesRsa(bool runsOnWindows) { - if (OperatingSystem.IsLinux()) Assert.Skip("Skipped on Linux"); + if (OperatingSystem.IsLinux()) + { + Assert.Skip("Skipped on Linux"); + } Assert.NotNull(FakeSslCertificateFactory.GenerateRsa(runsOnWindows)); } @@ -35,7 +38,10 @@ public void GenerateRsa_RunsOnWindows_GeneratesRsa(bool runsOnWindows) [Fact] public void GenerateRsa_DoesNotRunOnWindows_GeneratesRsa() { - if (OperatingSystem.IsWindows()) Assert.Skip("Skipped on Windows"); + if (OperatingSystem.IsWindows()) + { + Assert.Skip("Skipped on Windows"); + } Assert.NotNull(FakeSslCertificateFactory.GenerateRsa(runsOnWindows: false)); } diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/PathValidationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/PathValidationTests.cs index 38c39cd9e50..fbb67c80a50 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/PathValidationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/PathValidationTests.cs @@ -259,7 +259,10 @@ await Assert.ThrowsAsync(() => [Fact] public void EnsureWithinRoot_UncPath_ChildPath_ReturnsResolved() { - if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } string root = @"\\server\share\data"; string child = @"\\server\share\data\sub\file.txt"; @@ -272,7 +275,10 @@ public void EnsureWithinRoot_UncPath_ChildPath_ReturnsResolved() [Fact] public void EnsureWithinRoot_UncPath_DifferentShare_Throws() { - if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } string root = @"\\server\share\data"; string other = @"\\server\share\other\file.txt"; @@ -284,7 +290,10 @@ public void EnsureWithinRoot_UncPath_DifferentShare_Throws() [Fact] public void EnsureWithinRoot_UncPath_DotDotEscapes_Throws() { - if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } string root = @"\\server\share\data"; string escaped = @"\\server\share\data\..\other"; @@ -296,7 +305,10 @@ public void EnsureWithinRoot_UncPath_DotDotEscapes_Throws() [Fact] public void EnsureWithinRoot_UncPath_SiblingWithPrefix_Throws() { - if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } string root = @"\\server\share\data"; string sibling = @"\\server\share\data-sibling\file.txt"; @@ -308,7 +320,10 @@ public void EnsureWithinRoot_UncPath_SiblingWithPrefix_Throws() [Fact] public void EnsureWithinRoot_UncPath_PathEqualsRoot_DoesNotThrow() { - if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } string root = @"\\server\share\data"; @@ -324,7 +339,10 @@ public void EnsureWithinRoot_UncPath_PathEqualsRoot_DoesNotThrow() [Fact] public void EnsureWithinRoot_ShortPathRoot_LongPathChild_DocumentedBehavior() { - if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } // Short (8.3) paths are NOT consistently normalized by Path.GetFullPath // across .NET versions. This test documents that if the root uses a short @@ -373,7 +391,10 @@ public void EnsureWithinRoot_ShortPathRoot_LongPathChild_DocumentedBehavior() [Fact] public void EnsureWithinRoot_ConsistentShortPaths_Works() { - if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } // When both root and child are constructed from the same short-path // string via Path.Combine, EnsureWithinRoot succeeds because @@ -412,7 +433,10 @@ public void EnsureWithinRoot_ConsistentShortPaths_Works() [Fact] public void EnsureWithinRoot_AltSeparatorInRoot_Works() { - if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } // Forward slash is an alternate directory separator on Windows. string root = Path.GetTempPath().Replace('\\', '/') + "testroot"; @@ -446,7 +470,10 @@ public void EnsureWithinRoot_CaseMismatch_BehavesPerPlatform() [Fact] public void EnsureWithinRoot_DriveRoot_ChildPath_Works() { - if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } string root = @"C:\"; string child = @"C:\some\nested\file.txt"; @@ -459,7 +486,10 @@ public void EnsureWithinRoot_DriveRoot_ChildPath_Works() [Fact] public void EnsureWithinRoot_DriveRoot_DifferentDrive_Throws() { - if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } string root = @"C:\data"; string other = @"D:\data\file.txt"; @@ -471,7 +501,10 @@ public void EnsureWithinRoot_DriveRoot_DifferentDrive_Throws() [Fact] public void EnsureWithinRoot_UnixAbsoluteRoot_ChildPath_Works() { - if (OperatingSystem.IsWindows()) Assert.Skip("Skipped on Windows"); + if (OperatingSystem.IsWindows()) + { + Assert.Skip("Skipped on Windows"); + } string root = "/tmp/testroot"; string child = "/tmp/testroot/sub/file.txt"; diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/HybridCacheEventSourceTests.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/HybridCacheEventSourceTests.cs index a6a8a866045..de59bd6023f 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/HybridCacheEventSourceTests.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/HybridCacheEventSourceTests.cs @@ -225,7 +225,10 @@ private void AssertEnabled() // including this data for visibility when tests fail - ETW subsystem can be ... weird log.WriteLine($".NET {Environment.Version} on {Environment.OSVersion}, {IntPtr.Size * 8}-bit"); - if (!(listener.Source.IsEnabled())) Assert.Skip("Event source not enabled"); + if (!listener.Source.IsEnabled()) + { + Assert.Skip("Event source not enabled"); + } } private async Task AssertCountersAsync() @@ -240,6 +243,9 @@ private async Task AssertCountersAsync() // fundamentally working. We're not meant to be testing that // the counters system *itself* works! - if (count == 0) Assert.Skip("No counters received"); + if (count == 0) + { + Assert.Skip("No counters received"); + } } } diff --git a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionAttribute.cs b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionAttribute.cs index 2316c1694d8..12f78c0d5c7 100644 --- a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionAttribute.cs +++ b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionAttribute.cs @@ -16,7 +16,7 @@ public class MarkItDownConditionAttribute : Attribute { internal static readonly Lazy IsInstalled = new(CanInvokeMarkItDown); - public string SkipReason => "MarkItDown is not installed or not accessible."; + public static string SkipReason => "MarkItDown is not installed or not accessible."; private static bool CanInvokeMarkItDown() { diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs index 554491fb1e3..1a643f021d2 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs @@ -148,7 +148,10 @@ public async Task TestCpuAndMemoryChecks_WithMetrics( ResourceUsageThresholds cpuThresholds, ResourceUsageThresholds memoryThresholds, string expectedDescription) { - if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux-specific test."); + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Linux-specific test."); + } var fakeClock = new FakeTimeProvider(); var dataTracker = new Mock(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs index 120d32fa92e..a996963e07b 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs @@ -23,7 +23,10 @@ public class ResourceHealthCheckExtensionsTests { public ResourceHealthCheckExtensionsTests() { - if (OperatingSystem.IsMacOS()) Assert.Skip("Skipped on macOS"); + if (OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on macOS"); + } } [Fact] @@ -474,7 +477,10 @@ public async Task TestCpuAndMemoryChecks_WithMetrics( ResourceUsageThresholds cpuThresholds, ResourceUsageThresholds memoryThresholds, string expectedDescription) { - if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())) Assert.Skip("Windows-specific test."); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Windows-specific test."); + } var logger = new FakeLogger(); var fakeClock = new FakeTimeProvider(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs index a70d354362a..1f1f36df06a 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs @@ -19,7 +19,10 @@ public class AcceptanceTest { public AcceptanceTest() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Windows/macOS"); + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Windows/macOS"); + } } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs index 567f359ddc5..af714b411cd 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs @@ -28,7 +28,10 @@ public sealed class AcceptanceTest [Fact] public void Adding_Linux_Resource_Utilization_Allows_To_Query_Snapshot_Provider() { - if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux specific tests"); + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Linux specific tests"); + } using var services = new ServiceCollection() .AddResourceMonitoring() @@ -44,7 +47,10 @@ public void Adding_Linux_Resource_Utilization_Allows_To_Query_Snapshot_Provider( [SuppressMessage("Minor Code Smell", "S3257:Declarations and initializations should be as concise as possible", Justification = "Broken analyzer.")] public void Adding_Linux_Resource_Utilization_Can_Be_Configured_With_Section() { - if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux specific tests"); + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Linux specific tests"); + } var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -74,7 +80,10 @@ public void Adding_Linux_Resource_Utilization_Can_Be_Configured_With_Section() [Fact] public void Adding_Linux_Resource_Utilization_Can_Be_Configured_With_Action() { - if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux specific tests"); + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Linux specific tests"); + } var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -98,7 +107,10 @@ public void Adding_Linux_Resource_Utilization_Can_Be_Configured_With_Action() [SuppressMessage("Minor Code Smell", "S3257:Declarations and initializations should be as concise as possible", Justification = "Broken analyzer.")] public void Adding_Linux_Resource_Utilization_With_Section_Registers_SnapshotProvider_Cgroupv1() { - if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux specific tests"); + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Linux specific tests"); + } var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -148,7 +160,10 @@ public void Adding_Linux_Resource_Utilization_With_Section_Registers_SnapshotPro [SuppressMessage("Minor Code Smell", "S3257:Declarations and initializations should be as concise as possible", Justification = "Broken analyzer.")] public void Adding_Linux_Resource_Utilization_With_Section_Registers_SnapshotProvider_Cgroupv2() { - if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux specific tests"); + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Linux specific tests"); + } var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -194,11 +209,13 @@ public void Adding_Linux_Resource_Utilization_With_Section_Registers_SnapshotPro Assert.Equal(100_000UL, provider.Resources.MaximumMemoryInBytes); } - [Theory] - [CombinatorialData] + [Fact] public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgroupsv1() { - if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux specific tests"); + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Linux specific tests"); + } var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -294,11 +311,13 @@ public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgrou return Task.CompletedTask; } - [Theory] - [CombinatorialData] + [Fact] public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgroupsv2() { - if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux specific tests"); + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Linux specific tests"); + } var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -404,11 +423,13 @@ public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgrou return Task.CompletedTask; } - [Theory] - [CombinatorialData] + [Fact] public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgroupsv2_Using_LinuxCalculationV2() { - if ((OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())) Assert.Skip("Linux specific tests"); + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Linux specific tests"); + } var fileSystem = new HardcodedValueFileSystem(new Dictionary { diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs index dc4e6646de8..347b8733194 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs @@ -14,7 +14,10 @@ public class DiskStatsReaderTests { public DiskStatsReaderTests() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Windows/macOS"); + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Windows/macOS"); + } } private static readonly string[] _skipDevicePrefixes = new[] { "ram", "loop", "dm-" }; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs index a6f0c2321ee..d4e07a33939 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs @@ -20,7 +20,10 @@ public class LinuxSystemDiskMetricsTests { public LinuxSystemDiskMetricsTests() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Windows/macOS"); + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Windows/macOS"); + } } private static readonly string[] _skipDevicePrefixes = new[] { "ram", "loop", "dm-" }; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs index d3dc1f3e95f..9287869616e 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs @@ -17,7 +17,10 @@ public sealed class LinuxUtilizationParserCgroupV1Tests { public LinuxUtilizationParserCgroupV1Tests() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Windows/macOS"); + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Windows/macOS"); + } } [Theory] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs index 3a759b69fda..10c2f85c78d 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs @@ -17,7 +17,10 @@ public sealed class LinuxUtilizationParserCgroupV2Tests { public LinuxUtilizationParserCgroupV2Tests() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Windows/macOS"); + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Windows/macOS"); + } } private const string VerifiedDataDirectory = "Verified"; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs index aa4c5099a51..f9bfdf4b000 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs @@ -21,13 +21,15 @@ public sealed class LinuxUtilizationProviderTests { public LinuxUtilizationProviderTests() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Windows/macOS"); + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Windows/macOS"); + } } private const string VerifiedDataDirectory = "Verified"; - [Theory] - [CombinatorialData] + [Fact] public void Provider_Registers_Instruments() { var meterName = Guid.NewGuid().ToString(); @@ -111,8 +113,7 @@ public void Provider_Registers_Instruments() Assert.Equal(0.5, samples.Single(i => i.instrument.Name == ResourceUtilizationInstruments.ProcessMemoryUtilization).value); } - [Theory] - [CombinatorialData] + [Fact] public void Provider_Registers_Instruments_CgroupV2() { var meterName = Guid.NewGuid().ToString(); @@ -232,8 +233,7 @@ public void Provider_Creates_Meter_With_Correct_Name() Assert.Equal(ResourceUtilizationInstruments.MeterName, meter.Name); } - [Theory] - [CombinatorialData] + [Fact] public void Provider_Registers_Instruments_CgroupV2_WithoutHostCpu() { var meterName = Guid.NewGuid().ToString(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs index 248278f1772..fa503ca0092 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs @@ -14,7 +14,10 @@ public sealed class OSFileSystemTests { public OSFileSystemTests() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Windows/macOS"); + if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Windows/macOS"); + } } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs index 11b1ccf8cc5..cef82f5089d 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs @@ -13,7 +13,10 @@ public sealed class ResourceMonitoringBuilderTests { public ResourceMonitoringBuilderTests() { - if (OperatingSystem.IsMacOS()) Assert.Skip("Skipped on macOS"); + if (OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on macOS"); + } } [Fact(Skip = "Not supported on MacOs.")] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs index 0f1227a3df7..2a39209c4b2 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs @@ -20,7 +20,10 @@ public sealed class ResourceMonitoringExtensionsTests [Fact] public void Throw_Null_When_Registration_Ingredients_Null() { - if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + if (OperatingSystem.IsMacOS()) + { + Assert.Skip("Not supported on MacOs."); + } var services = new ServiceCollection(); @@ -33,7 +36,10 @@ public void Throw_Null_When_Registration_Ingredients_Null() [Fact] public void AddsResourceMonitoringService_ToServicesCollection() { - if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + if (OperatingSystem.IsMacOS()) + { + Assert.Skip("Not supported on MacOs."); + } using var provider = new ServiceCollection() .AddLogging() @@ -55,7 +61,10 @@ public void AddsResourceMonitoringService_ToServicesCollection() [Fact] public void AddsResourceMonitoringService_ToServicesCollection_NoArgs() { - if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + if (OperatingSystem.IsMacOS()) + { + Assert.Skip("Not supported on MacOs."); + } using var provider = new ServiceCollection() .AddLogging() @@ -73,7 +82,10 @@ public void AddsResourceMonitoringService_ToServicesCollection_NoArgs() [Fact] public void AddsResourceMonitoringService_AsHostedService() { - if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + if (OperatingSystem.IsMacOS()) + { + Assert.Skip("Not supported on MacOs."); + } using var provider = new ServiceCollection() .AddLogging() @@ -96,7 +108,10 @@ public void AddsResourceMonitoringService_AsHostedService() [Fact] public void ConfigureResourceUtilization_InitializeTrackerProperly() { - if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + if (OperatingSystem.IsMacOS()) + { + Assert.Skip("Not supported on MacOs."); + } using var host = FakeHost.CreateBuilder() .ConfigureServices(services => @@ -124,7 +139,10 @@ public void ConfigureResourceUtilization_InitializeTrackerProperly() [Fact] public void ConfigureMonitor_GivenOptionsDelegate_InitializeTrackerWithOptionsProperly() { - if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + if (OperatingSystem.IsMacOS()) + { + Assert.Skip("Not supported on MacOs."); + } const int SamplingWindowValue = 3; const int CalculationPeriodValue = 2; @@ -154,7 +172,10 @@ public void ConfigureMonitor_GivenOptionsDelegate_InitializeTrackerWithOptionsPr [Fact] public void ConfigureMonitor_GivenIConfigurationSection_InitializeTrackerWithOptionsProperly() { - if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + if (OperatingSystem.IsMacOS()) + { + Assert.Skip("Not supported on MacOs."); + } const int SamplingWindowValue = 3; const int CalculationPeriod = 2; @@ -197,7 +218,10 @@ public void ConfigureMonitor_GivenIConfigurationSection_InitializeTrackerWithOpt [Fact] public void Registering_Resource_Utilization_Adds_Only_One_Object_Of_Type_ResourceUtilizationService_To_DI_Container() { - if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + if (OperatingSystem.IsMacOS()) + { + Assert.Skip("Not supported on MacOs."); + } using var host = FakeHost.CreateBuilder() .ConfigureServices(services => @@ -222,7 +246,10 @@ public void Registering_Resource_Utilization_Adds_Only_One_Object_Of_Type_Resour [Fact] public void AddResourceMonitoringInternal_WhenMacOs_ReturnsSameServiceCollection() { - if ((OperatingSystem.IsWindows() || OperatingSystem.IsLinux())) Assert.Skip("For MacOs only."); + if (OperatingSystem.IsWindows() || OperatingSystem.IsLinux()) + { + Assert.Skip("For MacOs only."); + } var services = new ServiceCollection(); @@ -237,7 +264,10 @@ public void AddResourceMonitoringInternal_WhenMacOs_ReturnsSameServiceCollection [Fact] public void AddResourceMonitoring_AddsISnapshotProvider() { - if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + if (OperatingSystem.IsMacOS()) + { + Assert.Skip("Not supported on MacOs."); + } var services = new ServiceCollection(); @@ -252,7 +282,10 @@ public void AddResourceMonitoring_AddsISnapshotProvider() [Fact] public void AddResourceMonitoringInternal_CallsConfigureDelegate() { - if (OperatingSystem.IsMacOS()) Assert.Skip("Not supported on MacOs."); + if (OperatingSystem.IsMacOS()) + { + Assert.Skip("Not supported on MacOs."); + } var services = new ServiceCollection(); bool delegateCalled = false; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs index f2e937c2908..f5d1542c750 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs @@ -15,7 +15,10 @@ public class WindowsDiskIoRatePerfCounterTests { public WindowsDiskIoRatePerfCounterTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } } private const string CategoryName = "LogicalDisk"; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs index c909581b9ac..6fe860c1c38 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs @@ -15,7 +15,10 @@ public class WindowsDiskIoTimePerfCounterTests { public WindowsDiskIoTimePerfCounterTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } } private const string CategoryName = "LogicalDisk"; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs index 945ca7e43dc..2754fb16127 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs @@ -22,7 +22,10 @@ public class WindowsDiskMetricsTests { public WindowsDiskMetricsTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } } private const string CategoryName = "LogicalDisk"; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs index 219411ec4e3..3e201aef69d 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs @@ -16,7 +16,10 @@ public sealed class MemoryInfoTests { public MemoryInfoTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs index 544ed532bc9..03f4cfb10f0 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs @@ -12,7 +12,10 @@ public class PerformanceCounterFactoryTests { public PerformanceCounterFactoryTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs index 5224c60bbce..8f1dde1e845 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs @@ -12,7 +12,10 @@ public class PerformanceCounterWrapperTests { public PerformanceCounterWrapperTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs index 54c814ccccc..ac8f7384b1a 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs @@ -16,7 +16,10 @@ public sealed class SystemInfoTests { public SystemInfoTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } } /// diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Tcp6TableInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Tcp6TableInfoTests.cs index e070885c4e6..13b75016828 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Tcp6TableInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Tcp6TableInfoTests.cs @@ -18,7 +18,10 @@ public sealed class Tcp6TableInfoTests { public Tcp6TableInfoTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } } public static readonly TimeSpan DefaultTimeSpan = TimeSpan.FromSeconds(5); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/TcpTableInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/TcpTableInfoTests.cs index f46cc8b6c73..a357ed84314 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/TcpTableInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/TcpTableInfoTests.cs @@ -15,7 +15,10 @@ public sealed class TcpTableInfoTests { public TcpTableInfoTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } } public static readonly TimeSpan DefaultTimeSpan = TimeSpan.FromSeconds(5); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs index c70a1511450..6e3503ec983 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs @@ -16,7 +16,10 @@ public class WindowsNetworkMetricsTests { public WindowsNetworkMetricsTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) + { + Assert.Skip("Skipped on Linux/macOS"); + } } [Fact] From 314c56557afe7b50a602ae4112dba0c67206fe37 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Jul 2026 16:19:24 +0000 Subject: [PATCH 06/19] Fix IDE0032 and CA1816 warnings in ProjectTemplates Infrastructure --- .../Infrastructure/MessageSinkTestOutputHelper.cs | 11 +++++------ .../TemplateExecutionTestClassFixtureBase.cs | 2 ++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/test/ProjectTemplates/Infrastructure/MessageSinkTestOutputHelper.cs b/test/ProjectTemplates/Infrastructure/MessageSinkTestOutputHelper.cs index b01ec6432ad..942d260db07 100644 --- a/test/ProjectTemplates/Infrastructure/MessageSinkTestOutputHelper.cs +++ b/test/ProjectTemplates/Infrastructure/MessageSinkTestOutputHelper.cs @@ -9,36 +9,35 @@ namespace Microsoft.Shared.ProjectTemplates.Tests; public sealed class MessageSinkTestOutputHelper : ITestOutputHelper { private readonly IMessageSink _messageSink; - private string _output = string.Empty; public MessageSinkTestOutputHelper(IMessageSink messageSink) { _messageSink = messageSink; } - public string Output => _output; + public string Output { get; private set; } = string.Empty; public void Write(string message) { - _output += message; + Output += message; _messageSink.OnMessage(new Xunit.v3.DiagnosticMessage(message)); } public void Write(string format, params object[] args) { _messageSink.OnMessage(new Xunit.v3.DiagnosticMessage(format, args)); - _output += string.Format(System.Globalization.CultureInfo.InvariantCulture, format, args); + Output += string.Format(System.Globalization.CultureInfo.InvariantCulture, format, args); } public void WriteLine(string message) { - _output += message + System.Environment.NewLine; + Output += message + System.Environment.NewLine; _messageSink.OnMessage(new Xunit.v3.DiagnosticMessage(message)); } public void WriteLine(string format, params object[] args) { - _output += string.Format(System.Globalization.CultureInfo.InvariantCulture, format, args) + System.Environment.NewLine; + Output += string.Format(System.Globalization.CultureInfo.InvariantCulture, format, args) + System.Environment.NewLine; _messageSink.OnMessage(new Xunit.v3.DiagnosticMessage(format, args)); } } diff --git a/test/ProjectTemplates/Infrastructure/TemplateExecutionTestClassFixtureBase.cs b/test/ProjectTemplates/Infrastructure/TemplateExecutionTestClassFixtureBase.cs index ed35526a3f8..3ec18cf45be 100644 --- a/test/ProjectTemplates/Infrastructure/TemplateExecutionTestClassFixtureBase.cs +++ b/test/ProjectTemplates/Infrastructure/TemplateExecutionTestClassFixtureBase.cs @@ -159,6 +159,8 @@ public void SetCurrentTestOutputHelper(ITestOutputHelper? outputHelper) public ValueTask DisposeAsync() { + GC.SuppressFinalize(this); + // Only here to implement IAsyncLifetime. Not currently used. return ValueTask.CompletedTask; } From 3b44bb121557dba393122450e6aabc3487451199 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Jul 2026 17:14:19 +0000 Subject: [PATCH 07/19] Fix CS8602 nullable dereference warnings on Record.Exception() results In xUnit v3, Record.Exception() returns Exception? (nullable). Add Assert.NotNull() calls before dereferencing the result to satisfy the compiler's nullable analysis. Also fix corrupted multi-line Record.Exception calls in ThrowTest.cs. --- .../Latency/ChecpointAcceptanceTests.cs | 1 + .../FakesExtensionsTests.cs | 2 ++ .../LinuxUtilizationParserCgroupV1Tests.cs | 9 +++++++ .../LinuxUtilizationParserCgroupV2Tests.cs | 13 ++++++++++ test/Shared/Throw/DoubleTests.cs | 12 ++++++++++ test/Shared/Throw/IntegerTests.cs | 24 +++++++++++++++++++ test/Shared/Throw/LongTests.cs | 24 +++++++++++++++++++ test/Shared/Throw/ThrowTest.cs | 15 ++++++++++++ 8 files changed, 100 insertions(+) diff --git a/test/Libraries/Microsoft.AspNetCore.Diagnostics.Middleware.Tests/Latency/ChecpointAcceptanceTests.cs b/test/Libraries/Microsoft.AspNetCore.Diagnostics.Middleware.Tests/Latency/ChecpointAcceptanceTests.cs index dc96ee74b4c..f0c778ccc95 100644 --- a/test/Libraries/Microsoft.AspNetCore.Diagnostics.Middleware.Tests/Latency/ChecpointAcceptanceTests.cs +++ b/test/Libraries/Microsoft.AspNetCore.Diagnostics.Middleware.Tests/Latency/ChecpointAcceptanceTests.cs @@ -104,6 +104,7 @@ public async Task RequestCheckpointMiddleware_Does_Not_Throw_When_ServerTiming_H var e = await Record.ExceptionAsync(async () => response = await host.GetTestClient().GetAsync("/").ConfigureAwait(false)); + Assert.NotNull(e); Assert.Null(e); Assert.NotNull(response); diff --git a/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakesExtensionsTests.cs b/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakesExtensionsTests.cs index 668b0730c1a..7f8e689ed48 100644 --- a/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakesExtensionsTests.cs +++ b/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakesExtensionsTests.cs @@ -108,6 +108,7 @@ public void CreateClient_NoAddress_Throws() var exception = Record.Exception(() => hostMock.Object.CreateClient(null, _ => false)); + Assert.NotNull(exception); Assert.IsType(exception); Assert.Equal("No suitable address found to call the server.", exception.Message); } @@ -119,6 +120,7 @@ public void CreateClient_NoSuitableAddress_Throws() var exception = Record.Exception(() => hostMock.Object.CreateClient(null, _ => false)); + Assert.NotNull(exception); Assert.IsType(exception); Assert.Equal("No suitable address found to call the server.", exception.Message); } diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs index 9287869616e..fb84e814011 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs @@ -94,6 +94,7 @@ public void When_Calling_GetMemoryUsageInBytes_Parser_Throws_When_MemoryStat_Doe var p = new LinuxUtilizationParserCgroupV1(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetMemoryUsageInBytes()); + Assert.NotNull(r); Assert.IsAssignableFrom(r); Assert.Contains("/sys/fs/cgroup/memory/memory.stat", r.Message); Assert.Contains("total_inactive_file", r.Message); @@ -121,6 +122,7 @@ public void When_Calling_GetMemoryUsageInBytes_Parser_Throws_When_UsageInBytes_D var p = new LinuxUtilizationParserCgroupV1(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetMemoryUsageInBytes()); + Assert.NotNull(r); Assert.IsAssignableFrom(r); Assert.Contains("/sys/fs/cgroup/memory/memory.usage_in_bytes", r.Message); } @@ -140,6 +142,7 @@ public void When_Calling_GetMemoryUsageInBytes_Parser_Throws_When_Inactive_Memor var p = new LinuxUtilizationParserCgroupV1(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetMemoryUsageInBytes()); + Assert.NotNull(r); Assert.IsAssignableFrom(r); Assert.Contains("lesser than", r.Message); } @@ -166,6 +169,7 @@ public void When_Calling_GetHostAvailableMemory_Parser_Throws_When_MemInfo_Does_ var p = new LinuxUtilizationParserCgroupV1(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetHostAvailableMemory()); + Assert.NotNull(r); Assert.IsAssignableFrom(r); Assert.Contains("/proc/meminfo", r.Message); } @@ -240,6 +244,7 @@ public void Parser_Throws_When_CpuSet_Has_Invalid_Content(string content) var p = new LinuxUtilizationParserCgroupV1(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetCgroupLimitedCpus()); + Assert.NotNull(r); Assert.IsAssignableFrom(r); Assert.Contains("/sys/fs/cgroup/cpuset/cpuset.cpus", r.Message); } @@ -261,6 +266,7 @@ public void When_Quota_And_Period_Are_Minus_One_It_Fallbacks_To_Cpuset(string qu var p = new LinuxUtilizationParserCgroupV1(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetCgroupLimitedCpus()); + Assert.NotNull(r); Assert.IsAssignableFrom(r); Assert.Contains("/sys/fs/cgroup/cpuset/cpuset.cpus", r.Message); } @@ -289,6 +295,7 @@ public void Parser_Throws_When_Cgroup_Cpu_Files_Contain_Invalid_Data(string quot var p = new LinuxUtilizationParserCgroupV1(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetCgroupLimitedCpus()); + Assert.NotNull(r); Assert.IsAssignableFrom(r); Assert.Contains("/sys/fs/cgroup/cpu/cpu.cfs_", r.Message); } @@ -339,6 +346,7 @@ public void ReadingCpuUsage_Does_Throws_For_Valid_Input(string content) var p = new LinuxUtilizationParserCgroupV1(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetHostCpuUsageInNanoseconds()); + Assert.NotNull(r); Assert.IsAssignableFrom(r); Assert.Contains("proc/stat", r.Message); } @@ -356,6 +364,7 @@ public void Parser_Throws_When_Cgroup_Cpu_Shares_Files_Contain_Invalid_Data(stri var p = new LinuxUtilizationParserCgroupV1(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetCgroupRequestCpu()); + Assert.NotNull(r); Assert.IsAssignableFrom(r); Assert.Contains("/sys/fs/cgroup/cpu/cpu.shares", r.Message); } diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs index 10c2f85c78d..f74718f7f0a 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs @@ -98,6 +98,7 @@ public Task Throws_When_TotalInactiveFile_Is_Invalid(string content) var p = new LinuxUtilizationParserCgroupV2(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetMemoryUsageInBytes()); + Assert.NotNull(r); return Verifier.Verify(r).UseParameters(content).UseDirectory(VerifiedDataDirectory); } @@ -123,6 +124,7 @@ public Task Throws_When_UsageInBytes_Is_Invalid(string content) var p = new LinuxUtilizationParserCgroupV2(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetMemoryUsageInBytes()); + Assert.NotNull(r); return Verifier.Verify(r).UseParameters(content).UseDirectory(VerifiedDataDirectory); } @@ -157,6 +159,7 @@ public Task Throws_When_AvailableMemoryInBytes_Doesnt_Contain_Just_A_Number(stri var p = new LinuxUtilizationParserCgroupV2(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetAvailableMemoryInBytes()); + Assert.NotNull(r); return Verifier.Verify(r).UseParameters(content).UseDirectory(VerifiedDataDirectory); } @@ -172,6 +175,7 @@ public Task Throws_When_UsageInBytes_Doesnt_Contain_A_Number() var p = new LinuxUtilizationParserCgroupV2(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetMemoryUsageInBytesFromSlices(regexPatternforSlices)); + Assert.NotNull(r); return Verifier.Verify(r).UseDirectory(VerifiedDataDirectory); } @@ -216,6 +220,7 @@ public Task Throws_When_Inactive_Memory_Is_Bigger_Than_Total_Memory(int inactive var p = new LinuxUtilizationParserCgroupV2(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetMemoryUsageInBytes()); + Assert.NotNull(r); return Verifier.Verify(r).UseParameters(inactive, total).UseDirectory(VerifiedDataDirectory); } @@ -241,6 +246,7 @@ public Task Throws_When_MemInfo_Does_Not_Contain_TotalMemory(string totalMemory) var p = new LinuxUtilizationParserCgroupV2(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetHostAvailableMemory()); + Assert.NotNull(r); return Verifier.Verify(r).UseParameters(totalMemory).UseDirectory(VerifiedDataDirectory); } @@ -382,6 +388,7 @@ public Task Throws_When_CpuSet_Has_Invalid_Content(string content) var p = new LinuxUtilizationParserCgroupV2(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetHostCpuCount()); + Assert.NotNull(r); return Verifier.Verify(r).UseParameters(content).UseDirectory(VerifiedDataDirectory); } @@ -397,6 +404,7 @@ public Task Fallsback_To_Cpuset_When_Quota_And_Period_Are_Minus_One_() var p = new LinuxUtilizationParserCgroupV2(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetCgroupLimitedCpus()); + Assert.NotNull(r); return Verifier.Verify(r).UseDirectory(VerifiedDataDirectory); } @@ -422,6 +430,7 @@ public Task Throws_When_Cgroup_Cpu_Files_Contain_Invalid_Data(string quota, stri var p = new LinuxUtilizationParserCgroupV2(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetCgroupLimitedCpus()); + Assert.NotNull(r); return Verifier.Verify(r).UseParameters(quota, period).UseDirectory(VerifiedDataDirectory); } @@ -492,6 +501,7 @@ public Task Throws_When_CpuUsage_Invalid(string content) var p = new LinuxUtilizationParserCgroupV2(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetHostCpuUsageInNanoseconds()); + Assert.NotNull(r); return Verifier.Verify(r).UseParameters(content).UseDirectory(VerifiedDataDirectory); } @@ -509,6 +519,7 @@ public Task Throws_When_CpuAcctUsage_Has_Invalid_Content_Both_Parts(string conte var p = new LinuxUtilizationParserCgroupV2(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetCgroupCpuUsageInNanoseconds()); + Assert.NotNull(r); return Verifier.Verify(r).UseParameters(content, value).UseDirectory(VerifiedDataDirectory); } @@ -526,6 +537,7 @@ public Task Throws_When_Usage_Usec_Has_Negative_Value(int value) var p = new LinuxUtilizationParserCgroupV2(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetCgroupCpuUsageInNanoseconds()); + Assert.NotNull(r); return Verifier.Verify(r).UseParameters(value).UseDirectory(VerifiedDataDirectory); } @@ -544,6 +556,7 @@ public Task Throws_When_Cgroup_Cpu_Weight_Files_Contain_Invalid_Data(string cont var p = new LinuxUtilizationParserCgroupV2(f, new FakeUserHz(100)); var r = Record.Exception(() => p.GetCgroupRequestCpu()); + Assert.NotNull(r); return Verifier.Verify(r).UseParameters(content).UseDirectory(VerifiedDataDirectory); } diff --git a/test/Shared/Throw/DoubleTests.cs b/test/Shared/Throw/DoubleTests.cs index 72e33cfaf78..1de7b84bc56 100644 --- a/test/Shared/Throw/DoubleTests.cs +++ b/test/Shared/Throw/DoubleTests.cs @@ -136,8 +136,10 @@ public void Shorter_Version_Of_GreaterThan_For_Double_Get_Correct_Argument_Name( const double Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfGreaterThan(Zero, -1)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfGreaterThan(Zero, -1, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -147,8 +149,10 @@ public void Shorter_Version_Of_GreaterThanOrEqual_For_Double_Get_Correct_Argumen const double Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfGreaterThanOrEqual(Zero, -1)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfGreaterThanOrEqual(Zero, -1, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -158,8 +162,10 @@ public void Shorter_Version_Of_LessThan_For_Double_Get_Correct_Argument_Name() const double Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfLessThan(Zero, 1)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfLessThan(Zero, 1, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -169,8 +175,10 @@ public void Shorter_Version_Of_LessThanOrEqual_For_Double_Get_Correct_Argument_N const double Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfLessThanOrEqual(Zero, 1)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfLessThanOrEqual(Zero, 1, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -180,8 +188,10 @@ public void Shorter_Version_Of_Zero_For_Double_Get_Correct_Argument_Name() const double Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfZero(Zero)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfZero(Zero, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -191,8 +201,10 @@ public void Shorter_Version_Of_OutOfRange_For_Double_Get_Correct_Argument_Name() const double Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfOutOfRange(Zero, 1, 2)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfOutOfRange(Zero, 1, 2, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } diff --git a/test/Shared/Throw/IntegerTests.cs b/test/Shared/Throw/IntegerTests.cs index 206d5b39e66..bdec9fd5517 100644 --- a/test/Shared/Throw/IntegerTests.cs +++ b/test/Shared/Throw/IntegerTests.cs @@ -108,8 +108,10 @@ public void Shorter_Version_Of_GreaterThan_For_Int_Get_Correct_Argument_Name() const int Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfGreaterThan(Zero, -1)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfGreaterThan(Zero, -1, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -119,8 +121,10 @@ public void Shorter_Version_Of_GreaterThanOrEqual_For_Int_Get_Correct_Argument_N const int Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfGreaterThanOrEqual(Zero, -1)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfGreaterThanOrEqual(Zero, -1, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -130,8 +134,10 @@ public void Shorter_Version_Of_LessThan_For_Int_Get_Correct_Argument_Name() const int Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfLessThan(Zero, 1)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfLessThan(Zero, 1, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -141,8 +147,10 @@ public void Shorter_Version_Of_LessThanOrEqual_For_Int_Get_Correct_Argument_Name const int Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfLessThanOrEqual(Zero, 1)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfLessThanOrEqual(Zero, 1, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -152,8 +160,10 @@ public void Shorter_Version_Of_Zero_For_Int_Get_Correct_Argument_Name() const int Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfZero(Zero)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfZero(Zero, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -163,8 +173,10 @@ public void Shorter_Version_Of_OutOfRange_For_Int_Get_Correct_Argument_Name() const int Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfOutOfRange(Zero, 1, 2)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfOutOfRange(Zero, 1, 2, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -268,8 +280,10 @@ public void Shorter_Version_Of_GreaterThan_For_UInt_Get_Correct_Argument_Name() const uint One = 1; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfGreaterThan(One, 0U)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfGreaterThan(One, 0U, nameof(One))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -279,8 +293,10 @@ public void Shorter_Version_Of_GreaterThanOrEqual_For_UInt_Get_Correct_Argument_ const uint One = 1; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfGreaterThanOrEqual(One, 0U)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfGreaterThanOrEqual(One, 0U, nameof(One))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -290,8 +306,10 @@ public void Shorter_Version_Of_LessThan_For_UInt_Get_Correct_Argument_Name() const uint Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfLessThan(Zero, 1U)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfLessThan(Zero, 1U, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -301,8 +319,10 @@ public void Shorter_Version_Of_LessThanOrEqual_For_UInt_Get_Correct_Argument_Nam const uint Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfLessThanOrEqual(Zero, 1U)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfLessThanOrEqual(Zero, 1U, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -312,8 +332,10 @@ public void Shorter_Version_Of_Zero_For_UInt_Get_Correct_Argument_Name() const uint Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfZero(Zero)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfZero(Zero, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -323,8 +345,10 @@ public void Shorter_Version_Of_OutOfRange_For_UInt_Get_Correct_Argument_Name() const uint Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfOutOfRange(Zero, 1U, 2U)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfOutOfRange(Zero, 1U, 2U, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } diff --git a/test/Shared/Throw/LongTests.cs b/test/Shared/Throw/LongTests.cs index 553dc0ba43f..ecf51131754 100644 --- a/test/Shared/Throw/LongTests.cs +++ b/test/Shared/Throw/LongTests.cs @@ -108,8 +108,10 @@ public void Shorter_Version_Of_GreaterThan_For_Long_Get_Correct_Argument_Name() const long Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfGreaterThan(Zero, -1)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfGreaterThan(Zero, -1, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -119,8 +121,10 @@ public void Shorter_Version_Of_GreaterThanOrEqual_For_Long_Get_Correct_Argument_ const long Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfGreaterThanOrEqual(Zero, -1)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfGreaterThanOrEqual(Zero, -1, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -130,8 +134,10 @@ public void Shorter_Version_Of_LessThan_For_Long_Get_Correct_Argument_Name() const long Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfLessThan(Zero, 1)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfLessThan(Zero, 1, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -141,8 +147,10 @@ public void Shorter_Version_Of_LessThanOrEqual_For_Long_Get_Correct_Argument_Nam const long Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfLessThanOrEqual(Zero, 1)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfLessThanOrEqual(Zero, 1, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -152,8 +160,10 @@ public void Shorter_Version_Of_Zero_For_Long_Get_Correct_Argument_Name() const long Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfZero(Zero)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfZero(Zero, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -163,8 +173,10 @@ public void Shorter_Version_Of_OutOfRange_For_Long_Get_Correct_Argument_Name() const long Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfOutOfRange(Zero, 1, 2)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfOutOfRange(Zero, 1, 2, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -268,8 +280,10 @@ public void Shorter_Version_Of_GreaterThan_For_ULong_Get_Correct_Argument_Name() const ulong One = 1; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfGreaterThan(One, 0UL)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfGreaterThan(One, 0UL, nameof(One))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -279,8 +293,10 @@ public void Shorter_Version_Of_GreaterThanOrEqual_For_ULong_Get_Correct_Argument const ulong One = 1; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfGreaterThanOrEqual(One, 0UL)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfGreaterThanOrEqual(One, 0UL, nameof(One))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -290,8 +306,10 @@ public void Shorter_Version_Of_LessThan_For_ULong_Get_Correct_Argument_Name() const ulong Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfLessThan(Zero, 1UL)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfLessThan(Zero, 1UL, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -301,8 +319,10 @@ public void Shorter_Version_Of_LessThanOrEqual_For_ULong_Get_Correct_Argument_Na const ulong Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfLessThanOrEqual(Zero, 1UL)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfLessThanOrEqual(Zero, 1UL, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -312,8 +332,10 @@ public void Shorter_Version_Of_Zero_For_ULong_Get_Correct_Argument_Name() const ulong Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfZero(Zero)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfZero(Zero, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -323,8 +345,10 @@ public void Shorter_Version_Of_OutOfRange_For_ULong_Get_Correct_Argument_Name() const ulong Zero = 0; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfOutOfRange(Zero, 1UL, 2UL)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfOutOfRange(Zero, 1UL, 2UL, nameof(Zero))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } diff --git a/test/Shared/Throw/ThrowTest.cs b/test/Shared/Throw/ThrowTest.cs index 691217d86ce..15c5da0c379 100644 --- a/test/Shared/Throw/ThrowTest.cs +++ b/test/Shared/Throw/ThrowTest.cs @@ -144,8 +144,10 @@ public void Shorter_Version_Of_Throws_Get_Correct_Argument_Name() Random? somethingThatIsNull = null; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfNull(somethingThatIsNull)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfNull(somethingThatIsNull, nameof(somethingThatIsNull))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -157,9 +159,11 @@ public void Shorter_Version_Of_Throws_Get_Correct_Argument_Name_For_Object_Check object somethingThatIsNotNull = new(); var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfNullOrMemberNull(somethingThatIsNull, somethingNestedThatIsNull)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception( () => Throw.IfNullOrMemberNull(somethingThatIsNull, somethingNestedThatIsNull, nameof(somethingThatIsNull), nameof(somethingNestedThatIsNull))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -171,9 +175,11 @@ public void Shorter_Version_Of_Throws_Get_Correct_Argument_Name_For_Member_Check object somethingThatIsNotNull = new(); var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfNullOrMemberNull(red, somethingNestedThatIsNull)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception( () => Throw.IfNullOrMemberNull(red, somethingNestedThatIsNull, nameof(red), nameof(somethingNestedThatIsNull))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); var expectedMessage = $"Member {nameof(somethingNestedThatIsNull)} of {nameof(red)} is null"; @@ -185,9 +191,11 @@ public void Shorter_Version_Of_Throws_Get_Correct_Argument_Name_For_Member_Check Assert.Equal(expectedMessage, exceptionImplicitArgumentName.Message); exceptionImplicitArgumentName = Record.Exception(() => Throw.IfMemberNull(somethingThatIsNotNull, somethingNestedThatIsNull)); + Assert.NotNull(exceptionImplicitArgumentName); exceptionExplicitArgumentName = Record.Exception( () => Throw.IfMemberNull(somethingThatIsNotNull, somethingNestedThatIsNull, nameof(somethingThatIsNotNull), nameof(somethingNestedThatIsNull))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); expectedMessage = $"Member {nameof(somethingNestedThatIsNull)} of {nameof(somethingThatIsNotNull)} is null"; @@ -268,8 +276,10 @@ public void Shorter_Version_Of_ThrowIfNullOrWhitespace_Get_Correct_Argument_Name string? somethingThatIsNull = null; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfNullOrWhitespace(somethingThatIsNull)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfNullOrWhitespace(somethingThatIsNull, nameof(somethingThatIsNull))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -279,8 +289,10 @@ public void Shorter_Version_Of_ThrowIfNullOrEmpty_Get_Correct_Argument_Name() string? somethingThatIsNull = null; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfNullOrEmpty(somethingThatIsNull)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfNullOrEmpty(somethingThatIsNull, nameof(somethingThatIsNull))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } @@ -379,6 +391,7 @@ public void Shorter_Version_Of_NullOrEmpty_Get_Correct_Argument_Name() var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfNullOrEmpty(listButActuallyNull!)); + Assert.NotNull(exceptionImplicitArgumentName); Assert.Contains(nameof(listButActuallyNull), exceptionImplicitArgumentName.Message); } @@ -415,8 +428,10 @@ public void Shorter_Version_Of_OutOfRange_Get_Correct_Argument_Name() Color? colorButNull = null; var exceptionImplicitArgumentName = Record.Exception(() => Throw.IfOutOfRange((Color)colorButNull!)); + Assert.NotNull(exceptionImplicitArgumentName); var exceptionExplicitArgumentName = Record.Exception(() => Throw.IfOutOfRange((Color)colorButNull!, nameof(colorButNull))); + Assert.NotNull(exceptionExplicitArgumentName); Assert.Equal(exceptionExplicitArgumentName.Message, exceptionImplicitArgumentName.Message); } From e5f259ee14489a8b742eedcafe149d744a608b6b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Jul 2026 17:23:00 +0000 Subject: [PATCH 08/19] Fix NU1010 Windows build errors by adding empty-TF fallback for AspNetCore PackageVersion items --- eng/packages/Tests.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/packages/Tests.props b/eng/packages/Tests.props index 5f80b404aa6..94355370426 100644 --- a/eng/packages/Tests.props +++ b/eng/packages/Tests.props @@ -61,7 +61,7 @@ - + From fff9efafa6e933aa705f8d63133be85f35b4fccb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Jul 2026 18:05:46 +0000 Subject: [PATCH 09/19] Address review feedback: ConditionalNet472 pattern, Assert.SkipUnless, MarkItDownConditionHelper, ctor skip logic, FakeLogCollector StringBuilder, CA1816 fixes --- Directory.Build.props | 1 + ...n.ContextualOptions.Generated.Tests.csproj | 3 +- ...crosoft.Gen.Logging.Generated.Tests.csproj | 3 +- ...Microsoft.Gen.Logging.HelperLibrary.csproj | 4 +- ...crosoft.Gen.Metrics.Generated.Tests.csproj | 3 +- .../FakeCertificateFactoryTests.cs | 10 +--- .../AgentQualityEvaluatorTests.cs | 5 +- .../NLPEvaluatorTests.cs | 5 +- .../QualityEvaluatorTests.cs | 5 +- .../SafetyEvaluatorTests.cs | 5 +- .../AzureStorage/AzureResponseCacheTests.cs | 1 + .../AzureStorage/AzureResultStoreTests.cs | 1 + .../DiskBased/DiskBasedResponseCacheTests.cs | 1 + .../DiskBased/DiskBasedResultStoreTests.cs | 2 + .../DiskBased/PathValidationTests.cs | 55 ++++--------------- .../EmbeddingTests.cs | 5 +- .../ResponseCacheTester.cs | 5 +- .../ResultStoreTester.cs | 5 +- .../ChatClientIntegrationTests.cs | 10 +--- .../EmbeddingGeneratorIntegrationTests.cs | 5 +- ...ageGeneratingChatClientIntegrationTests.cs | 5 +- .../ImageGeneratorIntegrationTests.cs | 5 +- .../SpeechToTextClientIntegrationTests.cs | 5 +- .../TextToSpeechClientIntegrationTests.cs | 5 +- .../OpenAIHostedFileClientIntegrationTests.cs | 5 +- .../OpenAIResponseClientIntegrationTests.cs | 40 +++----------- ...penAITextToSpeechClientIntegrationTests.cs | 5 +- .../HybridCacheEventSourceTests.cs | 5 +- ...ribute.cs => MarkItDownConditionHelper.cs} | 3 +- .../Readers/MarkItDownReaderTests.cs | 6 +- .../Linux/LinuxResourceHealthCheckTests.cs | 5 +- .../ResourceHealthCheckExtensionsTests.cs | 10 +--- .../Linux/AcceptanceTest.cs | 5 +- .../Linux/AcceptanceTest.cs | 40 +++----------- .../Linux/Disk/DiskStatsReaderTests.cs | 5 +- .../Linux/Disk/LinuxSystemDiskMetricsTests.cs | 5 +- .../Linux/LinuxNetworkMetricsTests.cs | 5 +- .../LinuxUtilizationParserCgroupV1Tests.cs | 5 +- .../LinuxUtilizationParserCgroupV2Tests.cs | 5 +- .../Linux/LinuxUtilizationProviderTests.cs | 5 +- .../Linux/OSFileSystemTests.cs | 5 +- .../ResourceMonitoringBuilderTests.cs | 7 +-- .../ResourceMonitoringExtensionsTests.cs | 55 ++++--------------- .../Disk/WindowsDiskIoRatePerfCounterTests.cs | 5 +- .../Disk/WindowsDiskIoTimePerfCounterTests.cs | 5 +- .../Windows/Disk/WindowsDiskMetricsTests.cs | 5 +- .../Windows/MemoryInfoTests.cs | 5 +- .../Windows/PerformanceCounterFactoryTests.cs | 5 +- .../Windows/PerformanceCounterWrapperTests.cs | 5 +- .../Windows/SystemInfoTests.cs | 5 +- .../Windows/Tcp6TableInfoTests.cs | 5 +- .../Windows/TcpTableInfoTests.cs | 5 +- .../Windows/WindowsNetworkMetricsTests.cs | 5 +- .../Windows/WindowsSnapshotProviderTests.cs | 5 +- .../Logging/FakeLogCollectorTests.cs | 7 ++- 55 files changed, 100 insertions(+), 337 deletions(-) rename test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/{MarkItDownConditionAttribute.cs => MarkItDownConditionHelper.cs} (88%) diff --git a/Directory.Build.props b/Directory.Build.props index 38fbb2c0850..4ddba237ced 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -29,6 +29,7 @@ $(SupportedNetCoreTargetFrameworks) $(NetCoreTargetFrameworks);net8.0 ;net462 + ;net472 $(NetCoreTargetFrameworks) diff --git a/test/Generators/Microsoft.Gen.ContextualOptions/Generated/Microsoft.Gen.ContextualOptions.Generated.Tests.csproj b/test/Generators/Microsoft.Gen.ContextualOptions/Generated/Microsoft.Gen.ContextualOptions.Generated.Tests.csproj index ce8265414c4..8fb859be613 100644 --- a/test/Generators/Microsoft.Gen.ContextualOptions/Generated/Microsoft.Gen.ContextualOptions.Generated.Tests.csproj +++ b/test/Generators/Microsoft.Gen.ContextualOptions/Generated/Microsoft.Gen.ContextualOptions.Generated.Tests.csproj @@ -5,8 +5,7 @@ - $(TestNetCoreTargetFrameworks) - $(TestNetCoreTargetFrameworks);net472 + $(TestNetCoreTargetFrameworks)$(ConditionalNet472) true true true diff --git a/test/Generators/Microsoft.Gen.Logging/Generated/Microsoft.Gen.Logging.Generated.Tests.csproj b/test/Generators/Microsoft.Gen.Logging/Generated/Microsoft.Gen.Logging.Generated.Tests.csproj index d0b98af9cb4..78615f29b9b 100644 --- a/test/Generators/Microsoft.Gen.Logging/Generated/Microsoft.Gen.Logging.Generated.Tests.csproj +++ b/test/Generators/Microsoft.Gen.Logging/Generated/Microsoft.Gen.Logging.Generated.Tests.csproj @@ -5,8 +5,7 @@ - $(TestNetCoreTargetFrameworks) - $(TestNetCoreTargetFrameworks);net472 + $(TestNetCoreTargetFrameworks)$(ConditionalNet472) true true true diff --git a/test/Generators/Microsoft.Gen.Logging/HelperLibrary/Microsoft.Gen.Logging.HelperLibrary.csproj b/test/Generators/Microsoft.Gen.Logging/HelperLibrary/Microsoft.Gen.Logging.HelperLibrary.csproj index e9e877bf1d7..19ccc382efb 100644 --- a/test/Generators/Microsoft.Gen.Logging/HelperLibrary/Microsoft.Gen.Logging.HelperLibrary.csproj +++ b/test/Generators/Microsoft.Gen.Logging/HelperLibrary/Microsoft.Gen.Logging.HelperLibrary.csproj @@ -2,14 +2,12 @@ Microsoft.Gen.Logging.Test Test classes for Microsoft.Gen.Logging.Generated.Tests. - Library false - $(TestNetCoreTargetFrameworks) - $(TestNetCoreTargetFrameworks);net472 + $(TestNetCoreTargetFrameworks)$(ConditionalNet472) diff --git a/test/Generators/Microsoft.Gen.Metrics/Generated/Microsoft.Gen.Metrics.Generated.Tests.csproj b/test/Generators/Microsoft.Gen.Metrics/Generated/Microsoft.Gen.Metrics.Generated.Tests.csproj index 198869c8205..c7a2e0fa99b 100644 --- a/test/Generators/Microsoft.Gen.Metrics/Generated/Microsoft.Gen.Metrics.Generated.Tests.csproj +++ b/test/Generators/Microsoft.Gen.Metrics/Generated/Microsoft.Gen.Metrics.Generated.Tests.csproj @@ -5,8 +5,7 @@ - $(TestNetCoreTargetFrameworks) - $(TestNetCoreTargetFrameworks);net472 + $(TestNetCoreTargetFrameworks)$(ConditionalNet472) true true $(NoWarn);IDE0161;S1144 diff --git a/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs b/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs index b8a1d5a4597..47dfc06a4c2 100644 --- a/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs +++ b/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs @@ -27,10 +27,7 @@ public void Create_CreatesCertificate() [InlineData(true)] public void GenerateRsa_RunsOnWindows_GeneratesRsa(bool runsOnWindows) { - if (OperatingSystem.IsLinux()) - { - Assert.Skip("Skipped on Linux"); - } + Assert.SkipUnless(!OperatingSystem.IsLinux(), "Skipped on Linux"); Assert.NotNull(FakeSslCertificateFactory.GenerateRsa(runsOnWindows)); } @@ -38,10 +35,7 @@ public void GenerateRsa_RunsOnWindows_GeneratesRsa(bool runsOnWindows) [Fact] public void GenerateRsa_DoesNotRunOnWindows_GeneratesRsa() { - if (OperatingSystem.IsWindows()) - { - Assert.Skip("Skipped on Windows"); - } + Assert.SkipUnless(!OperatingSystem.IsWindows(), "Skipped on Windows"); Assert.NotNull(FakeSslCertificateFactory.GenerateRsa(runsOnWindows: false)); } diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/AgentQualityEvaluatorTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/AgentQualityEvaluatorTests.cs index 6c730cf577c..f8b908dbf55 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/AgentQualityEvaluatorTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/AgentQualityEvaluatorTests.cs @@ -267,10 +267,7 @@ private record OrderStatus(int OrderId, string Status, DateTime ExpectedDelivery [MemberNotNull(nameof(_needsContextReportingConfiguration))] private static void SkipIfNotConfigured() { - if (!Settings.Current.Configured) - { - Assert.Skip("Test is not configured"); - } + Assert.SkipUnless(Settings.Current.Configured, "Test is not configured"); Assert.NotNull(_chatOptionsWithTools); Assert.NotNull(_agentQualityReportingConfiguration); diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/NLPEvaluatorTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/NLPEvaluatorTests.cs index fd92ece1a76..857af1e21fd 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/NLPEvaluatorTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/NLPEvaluatorTests.cs @@ -148,10 +148,7 @@ await _nlpReportingConfiguration.CreateScenarioRunAsync( [MemberNotNull(nameof(_nlpReportingConfiguration))] private static void SkipIfNotConfigured() { - if (!Settings.Current.Configured) - { - Assert.Skip("Test is not configured"); - } + Assert.SkipUnless(Settings.Current.Configured, "Test is not configured"); Assert.NotNull(_nlpReportingConfiguration); } diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/QualityEvaluatorTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/QualityEvaluatorTests.cs index 9017e4c874c..7dbb56c0e2f 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/QualityEvaluatorTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/QualityEvaluatorTests.cs @@ -281,10 +281,7 @@ await scenarioRun.EvaluateAsync( [MemberNotNull(nameof(_needsContextReportingConfiguration))] private static void SkipIfNotConfigured() { - if (!Settings.Current.Configured) - { - Assert.Skip("Test is not configured"); - } + Assert.SkipUnless(Settings.Current.Configured, "Test is not configured"); Assert.NotNull(_chatOptions); Assert.NotNull(_qualityReportingConfiguration); diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/SafetyEvaluatorTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/SafetyEvaluatorTests.cs index 1a47a82c3f9..8d13756aaa8 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/SafetyEvaluatorTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Integration.Tests/SafetyEvaluatorTests.cs @@ -621,10 +621,7 @@ await _mixedQualityAndSafetyReportingConfiguration.CreateScenarioRunAsync( [MemberNotNull(nameof(_hubBasedContentSafetyReportingConfiguration))] private static void SkipIfNotConfigured() { - if (!Settings.Current.Configured) - { - Assert.Skip("Test is not configured"); - } + Assert.SkipUnless(Settings.Current.Configured, "Test is not configured"); Assert.NotNull(_chatOptions); Assert.NotNull(_contentSafetyReportingConfiguration); diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResponseCacheTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResponseCacheTests.cs index 025980febc0..4c7ddfe76a9 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResponseCacheTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResponseCacheTests.cs @@ -39,6 +39,7 @@ public AzureResponseCacheTests() public async ValueTask DisposeAsync() { + GC.SuppressFinalize(this); if (Settings.Current.Configured) { await CreateResponseCacheProvider().ResetAsync(); diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResultStoreTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResultStoreTests.cs index b2cb06c822c..b6583675bbb 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResultStoreTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResultStoreTests.cs @@ -39,6 +39,7 @@ public AzureResultStoreTests() public async ValueTask DisposeAsync() { + GC.SuppressFinalize(this); if (_dirClient is not null) { await _dirClient.DeleteAsync(); diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResponseCacheTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResponseCacheTests.cs index 7697f0aeece..9917f2f9b80 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResponseCacheTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResponseCacheTests.cs @@ -26,6 +26,7 @@ private string UseTempStoragePath() public ValueTask DisposeAsync() { + GC.SuppressFinalize(this); foreach (string path in _tempStorage) { try diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResultStoreTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResultStoreTests.cs index e199ffe3c7a..d85f807bfd3 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResultStoreTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResultStoreTests.cs @@ -1,6 +1,7 @@ // 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.Generic; using System.IO; using System.Threading.Tasks; @@ -25,6 +26,7 @@ private string UseTempStoragePath() public ValueTask DisposeAsync() { + GC.SuppressFinalize(this); foreach (string path in _tempStorage) { try diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/PathValidationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/PathValidationTests.cs index fbb67c80a50..ad8bf5216ae 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/PathValidationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/PathValidationTests.cs @@ -259,10 +259,7 @@ await Assert.ThrowsAsync(() => [Fact] public void EnsureWithinRoot_UncPath_ChildPath_ReturnsResolved() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); string root = @"\\server\share\data"; string child = @"\\server\share\data\sub\file.txt"; @@ -275,10 +272,7 @@ public void EnsureWithinRoot_UncPath_ChildPath_ReturnsResolved() [Fact] public void EnsureWithinRoot_UncPath_DifferentShare_Throws() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); string root = @"\\server\share\data"; string other = @"\\server\share\other\file.txt"; @@ -290,10 +284,7 @@ public void EnsureWithinRoot_UncPath_DifferentShare_Throws() [Fact] public void EnsureWithinRoot_UncPath_DotDotEscapes_Throws() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); string root = @"\\server\share\data"; string escaped = @"\\server\share\data\..\other"; @@ -305,10 +296,7 @@ public void EnsureWithinRoot_UncPath_DotDotEscapes_Throws() [Fact] public void EnsureWithinRoot_UncPath_SiblingWithPrefix_Throws() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); string root = @"\\server\share\data"; string sibling = @"\\server\share\data-sibling\file.txt"; @@ -320,10 +308,7 @@ public void EnsureWithinRoot_UncPath_SiblingWithPrefix_Throws() [Fact] public void EnsureWithinRoot_UncPath_PathEqualsRoot_DoesNotThrow() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); string root = @"\\server\share\data"; @@ -339,10 +324,7 @@ public void EnsureWithinRoot_UncPath_PathEqualsRoot_DoesNotThrow() [Fact] public void EnsureWithinRoot_ShortPathRoot_LongPathChild_DocumentedBehavior() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); // Short (8.3) paths are NOT consistently normalized by Path.GetFullPath // across .NET versions. This test documents that if the root uses a short @@ -391,10 +373,7 @@ public void EnsureWithinRoot_ShortPathRoot_LongPathChild_DocumentedBehavior() [Fact] public void EnsureWithinRoot_ConsistentShortPaths_Works() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); // When both root and child are constructed from the same short-path // string via Path.Combine, EnsureWithinRoot succeeds because @@ -433,10 +412,7 @@ public void EnsureWithinRoot_ConsistentShortPaths_Works() [Fact] public void EnsureWithinRoot_AltSeparatorInRoot_Works() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); // Forward slash is an alternate directory separator on Windows. string root = Path.GetTempPath().Replace('\\', '/') + "testroot"; @@ -470,10 +446,7 @@ public void EnsureWithinRoot_CaseMismatch_BehavesPerPlatform() [Fact] public void EnsureWithinRoot_DriveRoot_ChildPath_Works() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); string root = @"C:\"; string child = @"C:\some\nested\file.txt"; @@ -486,10 +459,7 @@ public void EnsureWithinRoot_DriveRoot_ChildPath_Works() [Fact] public void EnsureWithinRoot_DriveRoot_DifferentDrive_Throws() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); string root = @"C:\data"; string other = @"D:\data\file.txt"; @@ -501,10 +471,7 @@ public void EnsureWithinRoot_DriveRoot_DifferentDrive_Throws() [Fact] public void EnsureWithinRoot_UnixAbsoluteRoot_ChildPath_Works() { - if (OperatingSystem.IsWindows()) - { - Assert.Skip("Skipped on Windows"); - } + Assert.SkipUnless(!OperatingSystem.IsWindows(), "Skipped on Windows"); string root = "/tmp/testroot"; string child = "/tmp/testroot/sub/file.txt"; diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/EmbeddingTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/EmbeddingTests.cs index 71a171e51f2..fddd07ba7df 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/EmbeddingTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/EmbeddingTests.cs @@ -13,10 +13,7 @@ public class EmbeddingTests public void CIBuildsMustIncludeEmbeddedHTML() { // TF_BUILD should be set in our CI pipeline - if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TF_BUILD"))) - { - Assert.Skip("Skipping test because it is not running in CI"); - } + Assert.SkipUnless(!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TF_BUILD")), "Skipping test because it is not running in CI"); Assert.NotEmpty(HtmlReportWriter.HtmlTemplateBefore); Assert.NotEmpty(HtmlReportWriter.HtmlTemplateAfter); diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ResponseCacheTester.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ResponseCacheTester.cs index 586fb828d57..328379094eb 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ResponseCacheTester.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ResponseCacheTester.cs @@ -22,10 +22,7 @@ public abstract class ResponseCacheTester private void SkipIfNotConfigured() { - if (!IsConfigured) - { - Assert.Skip("Test not configured"); - } + Assert.SkipUnless(IsConfigured, "Test not configured"); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ResultStoreTester.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ResultStoreTester.cs index e8957a6e0c5..12504cd2a47 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ResultStoreTester.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/ResultStoreTester.cs @@ -58,10 +58,7 @@ private static ScenarioRunResult CreateTestResult(string scenarioName, string it private void SkipIfNotConfigured() { - if (!IsConfigured) - { - Assert.Skip("Test not configured"); - } + Assert.SkipUnless(IsConfigured, "Test not configured"); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs index 0e83fb8da4a..75bed1ef82e 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ChatClientIntegrationTests.cs @@ -565,10 +565,7 @@ private class ComplexObject public virtual async Task FunctionInvocation_SupportsMultipleParallelRequests() { SkipIfNotEnabled(); - if (!SupportsParallelFunctionCalling) - { - Assert.Skip("Parallel function calling is not supported by this chat client"); - } + Assert.SkipUnless(SupportsParallelFunctionCalling, "Parallel function calling is not supported by this chat client"); using var chatClient = new FunctionInvokingChatClient(ChatClient); @@ -1404,10 +1401,7 @@ protected void SkipIfNotEnabled() { string? skipIntegration = TestRunnerConfiguration.Instance["SkipIntegrationTests"]; - if (skipIntegration is not null || ChatClient is null) - { - Assert.Skip("Client is not enabled."); - } + Assert.SkipUnless(skipIntegration is null && ChatClient is not null, "Client is not enabled."); } } diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/EmbeddingGeneratorIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/EmbeddingGeneratorIntegrationTests.cs index 817dfa1212c..72f0ef894ed 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/EmbeddingGeneratorIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/EmbeddingGeneratorIntegrationTests.cs @@ -218,9 +218,6 @@ public async Task Quantization_Half_EmbeddingsCompareSuccessfully() [MemberNotNull(nameof(_embeddingGenerator))] protected void SkipIfNotEnabled() { - if (_embeddingGenerator is null) - { - Assert.Skip("Generator is not enabled."); - } + Assert.SkipUnless(_embeddingGenerator is not null, "Generator is not enabled."); } } diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratingChatClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratingChatClientIntegrationTests.cs index 9b01b489a34..80c66c5a5f0 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratingChatClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratingChatClientIntegrationTests.cs @@ -439,9 +439,6 @@ protected void SkipIfNotEnabled() { string? skipIntegration = TestRunnerConfiguration.Instance["SkipIntegrationTests"]; - if (skipIntegration is not null || ChatClient is null) - { - Assert.Skip("Client is not enabled."); - } + Assert.SkipUnless(skipIntegration is null && ChatClient is not null, "Client is not enabled."); } } diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratorIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratorIntegrationTests.cs index b07b7ece1db..d7fb16aa2d5 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratorIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratorIntegrationTests.cs @@ -126,9 +126,6 @@ protected void SkipIfNotEnabled() { string? skipIntegration = TestRunnerConfiguration.Instance["SkipIntegrationTests"]; - if (skipIntegration is not null || _generator is null) - { - Assert.Skip("Generator is not enabled."); - } + Assert.SkipUnless(skipIntegration is null && _generator is not null, "Generator is not enabled."); } } diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/SpeechToTextClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/SpeechToTextClientIntegrationTests.cs index ef5eaa9c9e8..d6f6f38e8e7 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/SpeechToTextClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/SpeechToTextClientIntegrationTests.cs @@ -91,9 +91,6 @@ protected void SkipIfNotEnabled() { string? skipIntegration = TestRunnerConfiguration.Instance["SkipIntegrationTests"]; - if (skipIntegration is not null || _client is null) - { - Assert.Skip("Client is not enabled."); - } + Assert.SkipUnless(skipIntegration is null && _client is not null, "Client is not enabled."); } } diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/TextToSpeechClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/TextToSpeechClientIntegrationTests.cs index 4fb2b5e50d7..c7ff72ab8ac 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/TextToSpeechClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/TextToSpeechClientIntegrationTests.cs @@ -129,9 +129,6 @@ protected void SkipIfNotEnabled() { string? skipIntegration = TestRunnerConfiguration.Instance["SkipIntegrationTests"]; - if (skipIntegration is not null || _client is null) - { - Assert.Skip("Client is not enabled."); - } + Assert.SkipUnless(skipIntegration is null && _client is not null, "Client is not enabled."); } } diff --git a/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIHostedFileClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIHostedFileClientIntegrationTests.cs index 49e5266f594..ec0736550f6 100644 --- a/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIHostedFileClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIHostedFileClientIntegrationTests.cs @@ -457,9 +457,6 @@ private void SkipIfNotEnabled() { string? skipIntegration = TestRunnerConfiguration.Instance["SkipIntegrationTests"]; - if (skipIntegration is not null || _client is null) - { - Assert.Skip("Client is not enabled."); - } + Assert.SkipUnless(skipIntegration is null && _client is not null, "Client is not enabled."); } } diff --git a/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientIntegrationTests.cs index ae9d6f38169..24e4f580dfd 100644 --- a/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientIntegrationTests.cs @@ -140,10 +140,7 @@ public async Task UseImageGeneration_ProducesImageContent(bool streaming, string { SkipIfNotEnabled(); - if (TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is not true) - { - Assert.Skip("Image generation tool requires gpt-5.4 or later."); - } + Assert.SkipUnless(TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is true, "Image generation tool requires gpt-5.4 or later."); var chatOptions = new ChatOptions { @@ -315,10 +312,7 @@ public async Task RemoteMCP_DeferLoadingTools() { SkipIfNotEnabled(); - if (TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is not true) - { - Assert.Skip("Tool search requires gpt-5.4 or later."); - } + Assert.SkipUnless(TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is true, "Tool search requires gpt-5.4 or later."); var mcpTool = new HostedMcpServerTool("deepwiki", new Uri("https://mcp.deepwiki.com/mcp")) { @@ -859,10 +853,7 @@ public async Task UseToolSearch_WithDeferredFunctions() { SkipIfNotEnabled(); - if (TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is not true) - { - Assert.Skip("Tool search requires gpt-5.4 or later."); - } + Assert.SkipUnless(TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is true, "Tool search requires gpt-5.4 or later."); AIFunction getWeather = AIFunctionFactory.Create(() => "Sunny, 72°F", "GetWeather", "Gets the current weather."); AIFunction getTime = AIFunctionFactory.Create(() => "3:00 PM", "GetTime", "Gets the current time."); @@ -898,10 +889,7 @@ public async Task UseToolSearch_OnlyToolSearchNoFunctions_Throws() { SkipIfNotEnabled(); - if (TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is not true) - { - Assert.Skip("Tool search requires gpt-5.4 or later."); - } + Assert.SkipUnless(TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is true, "Tool search requires gpt-5.4 or later."); // HostedToolSearchTool with no deferred tools — the API rejects this with 400 // because tool_search requires at least one tool with defer_loading. @@ -919,10 +907,7 @@ public async Task UseToolSearch_WithNonDeferredFunctionsOnly_Throws() { SkipIfNotEnabled(); - if (TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is not true) - { - Assert.Skip("Tool search requires gpt-5.4 or later."); - } + Assert.SkipUnless(TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is true, "Tool search requires gpt-5.4 or later."); // HostedToolSearchTool with DeferredTools explicitly set to empty — no tools are deferred. // The API rejects this with 400 because tool_search requires at least one deferred tool. @@ -946,10 +931,7 @@ public async Task UseToolSearch_DeferLoadingOnNonDeferrableTool_Throws() { SkipIfNotEnabled(); - if (TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is not true) - { - Assert.Skip("Tool search requires gpt-5.4 or later."); - } + Assert.SkipUnless(TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is true, "Tool search requires gpt-5.4 or later."); // Force defer_loading on a code_interpreter tool via Patch — the API should reject this. var codeTool = new HostedCodeInterpreterTool(); @@ -975,10 +957,7 @@ public async Task UseToolSearch_NamespaceWithDescription_RoundTrips() { SkipIfNotEnabled(); - if (TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is not true) - { - Assert.Skip("Tool search requires gpt-5.4 or later."); - } + Assert.SkipUnless(TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is true, "Tool search requires gpt-5.4 or later."); AIFunction getWeather = AIFunctionFactory.Create(() => "Sunny, 72°F", "GetWeather", "Gets the current weather."); AIFunction getTime = AIFunctionFactory.Create(() => "3:00 PM", "GetTime", "Gets the current time."); @@ -1020,10 +999,7 @@ public async Task UseToolSearch_TwoNamespacesWithDescriptions_RoundTrips() { SkipIfNotEnabled(); - if (TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is not true) - { - Assert.Skip("Tool search requires gpt-5.4 or later."); - } + Assert.SkipUnless(TestRunnerConfiguration.Instance["OpenAI:ChatModel"]?.StartsWith("gpt-5.4", StringComparison.OrdinalIgnoreCase) is true, "Tool search requires gpt-5.4 or later."); AIFunction getWeather = AIFunctionFactory.Create(() => "Sunny, 72°F", "GetWeather", "Gets the current weather."); AIFunction getTime = AIFunctionFactory.Create(() => "3:00 PM", "GetTime", "Gets the current time."); diff --git a/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAITextToSpeechClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAITextToSpeechClientIntegrationTests.cs index f52b640a646..11e927d5066 100644 --- a/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAITextToSpeechClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAITextToSpeechClientIntegrationTests.cs @@ -20,10 +20,7 @@ public class OpenAITextToSpeechClientIntegrationTests : TextToSpeechClientIntegr public async Task GetStreamingAudioAsync_StreamingModel_ReturnsMultipleUpdatesWithUsage() { var openAIClient = IntegrationTestHelpers.GetOpenAIClient(); - if (openAIClient is null) - { - Assert.Skip("Client is not enabled."); - } + Assert.SkipUnless(openAIClient is not null, "Client is not enabled."); using ITextToSpeechClient client = openAIClient .GetAudioClient(TestRunnerConfiguration.Instance["OpenAI:TextToSpeechStreamingModel"] ?? "gpt-4o-mini-tts") diff --git a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/HybridCacheEventSourceTests.cs b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/HybridCacheEventSourceTests.cs index de59bd6023f..ad27a0054e0 100644 --- a/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/HybridCacheEventSourceTests.cs +++ b/test/Libraries/Microsoft.Extensions.Caching.Hybrid.Tests/HybridCacheEventSourceTests.cs @@ -225,10 +225,7 @@ private void AssertEnabled() // including this data for visibility when tests fail - ETW subsystem can be ... weird log.WriteLine($".NET {Environment.Version} on {Environment.OSVersion}, {IntPtr.Size * 8}-bit"); - if (!listener.Source.IsEnabled()) - { - Assert.Skip("Event source not enabled"); - } + Assert.SkipUnless(listener.Source.IsEnabled(), "Event source not enabled"); } private async Task AssertCountersAsync() diff --git a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionAttribute.cs b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionHelper.cs similarity index 88% rename from test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionAttribute.cs rename to test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionHelper.cs index 12f78c0d5c7..ed37a17d830 100644 --- a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionAttribute.cs +++ b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionHelper.cs @@ -11,8 +11,7 @@ namespace Microsoft.Extensions.DataIngestion.Readers.Tests; /// /// Checks whether MarkItDown is installed and accessible. Used to conditionally skip tests. /// -[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)] -public class MarkItDownConditionAttribute : Attribute +internal static class MarkItDownConditionHelper { internal static readonly Lazy IsInstalled = new(CanInvokeMarkItDown); diff --git a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownReaderTests.cs b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownReaderTests.cs index fc22029aaeb..a9a99a4b947 100644 --- a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownReaderTests.cs +++ b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownReaderTests.cs @@ -8,15 +8,11 @@ namespace Microsoft.Extensions.DataIngestion.Readers.Tests; -[MarkItDownCondition] public class MarkItDownReaderTests : DocumentReaderConformanceTests { protected override IngestionDocumentReader CreateDocumentReader(bool extractImages = false) { - if (!MarkItDownConditionAttribute.IsInstalled.Value) - { - Assert.Skip("MarkItDown is not installed"); - } + Assert.SkipUnless(MarkItDownConditionHelper.IsInstalled.Value, "MarkItDown is not installed"); return new MarkItDownReader(extractImages: extractImages); } diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs index 1a643f021d2..2521dcc8a5e 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs @@ -148,10 +148,7 @@ public async Task TestCpuAndMemoryChecks_WithMetrics( ResourceUsageThresholds cpuThresholds, ResourceUsageThresholds memoryThresholds, string expectedDescription) { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Linux-specific test."); - } + Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux-specific test."); var fakeClock = new FakeTimeProvider(); var dataTracker = new Mock(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs index a996963e07b..5c42a2c02aa 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs @@ -23,10 +23,7 @@ public class ResourceHealthCheckExtensionsTests { public ResourceHealthCheckExtensionsTests() { - if (OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on macOS"); - } + Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Skipped on macOS"); } [Fact] @@ -477,10 +474,7 @@ public async Task TestCpuAndMemoryChecks_WithMetrics( ResourceUsageThresholds cpuThresholds, ResourceUsageThresholds memoryThresholds, string expectedDescription) { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Windows-specific test."); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Windows-specific test."); var logger = new FakeLogger(); var fakeClock = new FakeTimeProvider(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs index 1f1f36df06a..a4c9e3006a7 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs @@ -19,10 +19,7 @@ public class AcceptanceTest { public AcceptanceTest() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Windows/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsLinux(), "Skipped on Windows/macOS"); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs index af714b411cd..edbb0f29f8e 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs @@ -28,10 +28,7 @@ public sealed class AcceptanceTest [Fact] public void Adding_Linux_Resource_Utilization_Allows_To_Query_Snapshot_Provider() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Linux specific tests"); - } + Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux specific tests"); using var services = new ServiceCollection() .AddResourceMonitoring() @@ -47,10 +44,7 @@ public void Adding_Linux_Resource_Utilization_Allows_To_Query_Snapshot_Provider( [SuppressMessage("Minor Code Smell", "S3257:Declarations and initializations should be as concise as possible", Justification = "Broken analyzer.")] public void Adding_Linux_Resource_Utilization_Can_Be_Configured_With_Section() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Linux specific tests"); - } + Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux specific tests"); var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -80,10 +74,7 @@ public void Adding_Linux_Resource_Utilization_Can_Be_Configured_With_Section() [Fact] public void Adding_Linux_Resource_Utilization_Can_Be_Configured_With_Action() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Linux specific tests"); - } + Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux specific tests"); var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -107,10 +98,7 @@ public void Adding_Linux_Resource_Utilization_Can_Be_Configured_With_Action() [SuppressMessage("Minor Code Smell", "S3257:Declarations and initializations should be as concise as possible", Justification = "Broken analyzer.")] public void Adding_Linux_Resource_Utilization_With_Section_Registers_SnapshotProvider_Cgroupv1() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Linux specific tests"); - } + Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux specific tests"); var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -160,10 +148,7 @@ public void Adding_Linux_Resource_Utilization_With_Section_Registers_SnapshotPro [SuppressMessage("Minor Code Smell", "S3257:Declarations and initializations should be as concise as possible", Justification = "Broken analyzer.")] public void Adding_Linux_Resource_Utilization_With_Section_Registers_SnapshotProvider_Cgroupv2() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Linux specific tests"); - } + Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux specific tests"); var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -212,10 +197,7 @@ public void Adding_Linux_Resource_Utilization_With_Section_Registers_SnapshotPro [Fact] public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgroupsv1() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Linux specific tests"); - } + Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux specific tests"); var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -314,10 +296,7 @@ public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgrou [Fact] public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgroupsv2() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Linux specific tests"); - } + Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux specific tests"); var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -426,10 +405,7 @@ public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgrou [Fact] public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgroupsv2_Using_LinuxCalculationV2() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Linux specific tests"); - } + Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux specific tests"); var fileSystem = new HardcodedValueFileSystem(new Dictionary { diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs index 347b8733194..9e3d06cedeb 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs @@ -14,10 +14,7 @@ public class DiskStatsReaderTests { public DiskStatsReaderTests() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Windows/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsLinux(), "Skipped on Windows/macOS"); } private static readonly string[] _skipDevicePrefixes = new[] { "ram", "loop", "dm-" }; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs index d4e07a33939..54720f24868 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs @@ -20,10 +20,7 @@ public class LinuxSystemDiskMetricsTests { public LinuxSystemDiskMetricsTests() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Windows/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsLinux(), "Skipped on Windows/macOS"); } private static readonly string[] _skipDevicePrefixes = new[] { "ram", "loop", "dm-" }; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxNetworkMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxNetworkMetricsTests.cs index 5cc5c1924cd..158bd181cab 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxNetworkMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxNetworkMetricsTests.cs @@ -17,15 +17,14 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; public class LinuxNetworkMetricsTests { - // Class-level skip condition - // Skip: if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Windows/macOS"); - private readonly Mock _tcpStateInfoProvider = new(); private readonly DateTimeOffset _startTime = DateTimeOffset.UtcNow; private FakeTimeProvider _timeProvider; public LinuxNetworkMetricsTests() { + Assert.SkipUnless(OperatingSystem.IsLinux(), "Skipped on Windows/macOS"); + _timeProvider = new FakeTimeProvider(_startTime); _tcpStateInfoProvider.Setup(p => p.GetIpV4TcpStateInfo()).Returns(new TcpStateInfo()); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs index fb84e814011..ea9b2ee085a 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs @@ -17,10 +17,7 @@ public sealed class LinuxUtilizationParserCgroupV1Tests { public LinuxUtilizationParserCgroupV1Tests() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Windows/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsLinux(), "Skipped on Windows/macOS"); } [Theory] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs index f74718f7f0a..ec7b0b91a35 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs @@ -17,10 +17,7 @@ public sealed class LinuxUtilizationParserCgroupV2Tests { public LinuxUtilizationParserCgroupV2Tests() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Windows/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsLinux(), "Skipped on Windows/macOS"); } private const string VerifiedDataDirectory = "Verified"; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs index f9bfdf4b000..87b7629576c 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs @@ -21,10 +21,7 @@ public sealed class LinuxUtilizationProviderTests { public LinuxUtilizationProviderTests() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Windows/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsLinux(), "Skipped on Windows/macOS"); } private const string VerifiedDataDirectory = "Verified"; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs index fa503ca0092..43cbac0725e 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs @@ -14,10 +14,7 @@ public sealed class OSFileSystemTests { public OSFileSystemTests() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Windows/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsLinux(), "Skipped on Windows/macOS"); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs index cef82f5089d..2bc9d1c315b 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs @@ -13,13 +13,10 @@ public sealed class ResourceMonitoringBuilderTests { public ResourceMonitoringBuilderTests() { - if (OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on macOS"); - } + Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Skipped on macOS"); } - [Fact(Skip = "Not supported on MacOs.")] + [Fact] public void AddPublisher_CalledOnce_AddsSinglePublisherToServiceCollection() { using var provider = new ServiceCollection() diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs index 2a39209c4b2..a61c48ccef9 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs @@ -20,10 +20,7 @@ public sealed class ResourceMonitoringExtensionsTests [Fact] public void Throw_Null_When_Registration_Ingredients_Null() { - if (OperatingSystem.IsMacOS()) - { - Assert.Skip("Not supported on MacOs."); - } + Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); var services = new ServiceCollection(); @@ -36,10 +33,7 @@ public void Throw_Null_When_Registration_Ingredients_Null() [Fact] public void AddsResourceMonitoringService_ToServicesCollection() { - if (OperatingSystem.IsMacOS()) - { - Assert.Skip("Not supported on MacOs."); - } + Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); using var provider = new ServiceCollection() .AddLogging() @@ -61,10 +55,7 @@ public void AddsResourceMonitoringService_ToServicesCollection() [Fact] public void AddsResourceMonitoringService_ToServicesCollection_NoArgs() { - if (OperatingSystem.IsMacOS()) - { - Assert.Skip("Not supported on MacOs."); - } + Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); using var provider = new ServiceCollection() .AddLogging() @@ -82,10 +73,7 @@ public void AddsResourceMonitoringService_ToServicesCollection_NoArgs() [Fact] public void AddsResourceMonitoringService_AsHostedService() { - if (OperatingSystem.IsMacOS()) - { - Assert.Skip("Not supported on MacOs."); - } + Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); using var provider = new ServiceCollection() .AddLogging() @@ -108,10 +96,7 @@ public void AddsResourceMonitoringService_AsHostedService() [Fact] public void ConfigureResourceUtilization_InitializeTrackerProperly() { - if (OperatingSystem.IsMacOS()) - { - Assert.Skip("Not supported on MacOs."); - } + Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); using var host = FakeHost.CreateBuilder() .ConfigureServices(services => @@ -139,10 +124,7 @@ public void ConfigureResourceUtilization_InitializeTrackerProperly() [Fact] public void ConfigureMonitor_GivenOptionsDelegate_InitializeTrackerWithOptionsProperly() { - if (OperatingSystem.IsMacOS()) - { - Assert.Skip("Not supported on MacOs."); - } + Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); const int SamplingWindowValue = 3; const int CalculationPeriodValue = 2; @@ -172,10 +154,7 @@ public void ConfigureMonitor_GivenOptionsDelegate_InitializeTrackerWithOptionsPr [Fact] public void ConfigureMonitor_GivenIConfigurationSection_InitializeTrackerWithOptionsProperly() { - if (OperatingSystem.IsMacOS()) - { - Assert.Skip("Not supported on MacOs."); - } + Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); const int SamplingWindowValue = 3; const int CalculationPeriod = 2; @@ -218,10 +197,7 @@ public void ConfigureMonitor_GivenIConfigurationSection_InitializeTrackerWithOpt [Fact] public void Registering_Resource_Utilization_Adds_Only_One_Object_Of_Type_ResourceUtilizationService_To_DI_Container() { - if (OperatingSystem.IsMacOS()) - { - Assert.Skip("Not supported on MacOs."); - } + Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); using var host = FakeHost.CreateBuilder() .ConfigureServices(services => @@ -246,10 +222,7 @@ public void Registering_Resource_Utilization_Adds_Only_One_Object_Of_Type_Resour [Fact] public void AddResourceMonitoringInternal_WhenMacOs_ReturnsSameServiceCollection() { - if (OperatingSystem.IsWindows() || OperatingSystem.IsLinux()) - { - Assert.Skip("For MacOs only."); - } + Assert.SkipUnless(OperatingSystem.IsMacOS(), "For MacOs only."); var services = new ServiceCollection(); @@ -264,10 +237,7 @@ public void AddResourceMonitoringInternal_WhenMacOs_ReturnsSameServiceCollection [Fact] public void AddResourceMonitoring_AddsISnapshotProvider() { - if (OperatingSystem.IsMacOS()) - { - Assert.Skip("Not supported on MacOs."); - } + Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); var services = new ServiceCollection(); @@ -282,10 +252,7 @@ public void AddResourceMonitoring_AddsISnapshotProvider() [Fact] public void AddResourceMonitoringInternal_CallsConfigureDelegate() { - if (OperatingSystem.IsMacOS()) - { - Assert.Skip("Not supported on MacOs."); - } + Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); var services = new ServiceCollection(); bool delegateCalled = false; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs index f5d1542c750..b33ef54e806 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs @@ -15,10 +15,7 @@ public class WindowsDiskIoRatePerfCounterTests { public WindowsDiskIoRatePerfCounterTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); } private const string CategoryName = "LogicalDisk"; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs index 6fe860c1c38..3180be4c239 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs @@ -15,10 +15,7 @@ public class WindowsDiskIoTimePerfCounterTests { public WindowsDiskIoTimePerfCounterTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); } private const string CategoryName = "LogicalDisk"; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs index 2754fb16127..76eced19d90 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs @@ -22,10 +22,7 @@ public class WindowsDiskMetricsTests { public WindowsDiskMetricsTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); } private const string CategoryName = "LogicalDisk"; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs index 3e201aef69d..68a2bbc4f8a 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs @@ -16,10 +16,7 @@ public sealed class MemoryInfoTests { public MemoryInfoTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs index 03f4cfb10f0..9d3a7754d5d 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs @@ -12,10 +12,7 @@ public class PerformanceCounterFactoryTests { public PerformanceCounterFactoryTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs index 8f1dde1e845..ce33e537c71 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs @@ -12,10 +12,7 @@ public class PerformanceCounterWrapperTests { public PerformanceCounterWrapperTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs index ac8f7384b1a..a10da3756a5 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs @@ -16,10 +16,7 @@ public sealed class SystemInfoTests { public SystemInfoTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); } /// diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Tcp6TableInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Tcp6TableInfoTests.cs index 13b75016828..b77162f3482 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Tcp6TableInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Tcp6TableInfoTests.cs @@ -18,10 +18,7 @@ public sealed class Tcp6TableInfoTests { public Tcp6TableInfoTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); } public static readonly TimeSpan DefaultTimeSpan = TimeSpan.FromSeconds(5); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/TcpTableInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/TcpTableInfoTests.cs index a357ed84314..f67f66bc07d 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/TcpTableInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/TcpTableInfoTests.cs @@ -15,10 +15,7 @@ public sealed class TcpTableInfoTests { public TcpTableInfoTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); } public static readonly TimeSpan DefaultTimeSpan = TimeSpan.FromSeconds(5); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs index 6e3503ec983..3327df6fb77 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs @@ -16,10 +16,7 @@ public class WindowsNetworkMetricsTests { public WindowsNetworkMetricsTests() { - if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) - { - Assert.Skip("Skipped on Linux/macOS"); - } + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsSnapshotProviderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsSnapshotProviderTests.cs index d92a87fa361..558defd43aa 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsSnapshotProviderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsSnapshotProviderTests.cs @@ -20,9 +20,6 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; public sealed class WindowsSnapshotProviderTests { - // Class-level skip condition - // Skip: if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) Assert.Skip("Skipped on Linux/macOS"); - private const string VerifiedDataDirectory = "Verified"; private readonly Mock _meterFactoryMock; @@ -31,6 +28,8 @@ public sealed class WindowsSnapshotProviderTests public WindowsSnapshotProviderTests() { + Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + _options = Options.Options.Create(new()); using var meter = new Meter(nameof(BasicConstructor)); _meterFactoryMock = new Mock(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.Testing.Tests/Logging/FakeLogCollectorTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.Testing.Tests/Logging/FakeLogCollectorTests.cs index 8a5b8aad268..4d772bf60af 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.Testing.Tests/Logging/FakeLogCollectorTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.Testing.Tests/Logging/FakeLogCollectorTests.cs @@ -12,12 +12,14 @@ public partial class FakeLogCollectorTests { private class Output : ITestOutputHelper { + private readonly System.Text.StringBuilder _sb = new(); + public string Last { get; private set; } = string.Empty; - public string Output1 => Last; - string ITestOutputHelper.Output => Output1; + string ITestOutputHelper.Output => _sb.ToString(); public void Write(string message) { + _sb.Append(message); Last += message; } @@ -25,6 +27,7 @@ public void Write(string message) public void WriteLine(string message) { + _sb.AppendLine(message); Last = message; } From 17f28af095fe5701ba4a35836f71e71434865485 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Jul 2026 08:19:32 +0000 Subject: [PATCH 10/19] Fix S4144: deduplicate FunctionInvocation_RequireSpecific by delegating to FunctionInvocation_RequireAny --- .../OllamaSharpChatClientIntegrationTests.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/Libraries/Microsoft.Extensions.AI.OllamaSharp.Integration.Tests/OllamaSharpChatClientIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.OllamaSharp.Integration.Tests/OllamaSharpChatClientIntegrationTests.cs index 475c9dfa1cf..8ed29b756a7 100644 --- a/test/Libraries/Microsoft.Extensions.AI.OllamaSharp.Integration.Tests/OllamaSharpChatClientIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.OllamaSharp.Integration.Tests/OllamaSharpChatClientIntegrationTests.cs @@ -24,11 +24,7 @@ public override Task FunctionInvocation_RequireAny() return Task.CompletedTask; // Unreachable } - public override Task FunctionInvocation_RequireSpecific() - { - Assert.Skip("Ollama does not currently support requiring function invocation."); - return Task.CompletedTask; // Unreachable - } + public override Task FunctionInvocation_RequireSpecific() => FunctionInvocation_RequireAny(); protected override string? GetModel_MultiModal_DescribeImage() => "llava"; From df4b7c59f1f666482919e2c6b83c215fc0ffba9b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Jul 2026 08:52:18 +0000 Subject: [PATCH 11/19] Address review feedback: fix UseVSTestRunner conflict, move ConditionalNet472, use Assert.SkipUnless, remove SkipReason, use StringBuilder, remove xUnit1051 suppression --- Directory.Build.props | 3 +-- test/Directory.Build.props | 3 ++- .../Utilities/AIJsonUtilitiesTests.cs | 10 ++-------- .../Readers/MarkItDownConditionHelper.cs | 2 -- .../Infrastructure/MessageSinkTestOutputHelper.cs | 13 ++++++++----- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 4ddba237ced..fed133116e3 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -29,7 +29,6 @@ $(SupportedNetCoreTargetFrameworks) $(NetCoreTargetFrameworks);net8.0 ;net462 - ;net472 $(NetCoreTargetFrameworks) @@ -100,7 +99,7 @@ Run tests with the VS Test Runner (dotnet test) instead of the XUnit Test runner (dotnet exec). This is needed to produce Cobertura code coverage. See the targets file to more information. --> - true + true diff --git a/test/Directory.Build.props b/test/Directory.Build.props index 7749c5ddf79..03e7099823e 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -2,7 +2,7 @@ false - $(NoWarn);RT0000;xUnit1051 + $(NoWarn);RT0000 XUnitV3 @@ -13,5 +13,6 @@ $(LatestTargetFramework) + ;net472 diff --git a/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs b/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs index acaaee01077..edab335bcd6 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Utilities/AIJsonUtilitiesTests.cs @@ -650,10 +650,7 @@ public static void CreateJsonSchema_NullableEnum_IncludesTypeKeyword() [Fact] public static void CreateJsonSchema_IncorporatesTypesAndAnnotations_Net() { - if (RuntimeInformation.FrameworkDescription.Contains(".NET Framework")) - { - return; - } + Assert.SkipUnless(!RuntimeInformation.FrameworkDescription.Contains(".NET Framework"), "Only runs on .NET Core"); AssertDeepEquals(JsonSerializer.Deserialize( """ @@ -886,10 +883,7 @@ public static void CreateJsonSchema_IncorporatesTypesAndAnnotations_Net() [Fact] public static void CreateJsonSchema_IncorporatesTypesAndAnnotations_NetFx() { - if (!RuntimeInformation.FrameworkDescription.Contains(".NET Framework")) - { - return; - } + Assert.SkipUnless(RuntimeInformation.FrameworkDescription.Contains(".NET Framework"), "Only runs on .NET Framework"); AssertDeepEquals(JsonSerializer.Deserialize( """ diff --git a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionHelper.cs b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionHelper.cs index ed37a17d830..a2f4a432832 100644 --- a/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionHelper.cs +++ b/test/Libraries/Microsoft.Extensions.DataIngestion.Tests/Readers/MarkItDownConditionHelper.cs @@ -15,8 +15,6 @@ internal static class MarkItDownConditionHelper { internal static readonly Lazy IsInstalled = new(CanInvokeMarkItDown); - public static string SkipReason => "MarkItDown is not installed or not accessible."; - private static bool CanInvokeMarkItDown() { ProcessStartInfo startInfo = new() diff --git a/test/ProjectTemplates/Infrastructure/MessageSinkTestOutputHelper.cs b/test/ProjectTemplates/Infrastructure/MessageSinkTestOutputHelper.cs index 942d260db07..17c25cf99f2 100644 --- a/test/ProjectTemplates/Infrastructure/MessageSinkTestOutputHelper.cs +++ b/test/ProjectTemplates/Infrastructure/MessageSinkTestOutputHelper.cs @@ -1,6 +1,7 @@ // 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; using Xunit; using Xunit.Sdk; @@ -9,35 +10,37 @@ namespace Microsoft.Shared.ProjectTemplates.Tests; public sealed class MessageSinkTestOutputHelper : ITestOutputHelper { private readonly IMessageSink _messageSink; + private readonly StringBuilder _sb = new(); public MessageSinkTestOutputHelper(IMessageSink messageSink) { _messageSink = messageSink; } - public string Output { get; private set; } = string.Empty; + public string Output => _sb.ToString(); public void Write(string message) { - Output += message; + _sb.Append(message); _messageSink.OnMessage(new Xunit.v3.DiagnosticMessage(message)); } public void Write(string format, params object[] args) { + _sb.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, format, args); _messageSink.OnMessage(new Xunit.v3.DiagnosticMessage(format, args)); - Output += string.Format(System.Globalization.CultureInfo.InvariantCulture, format, args); } public void WriteLine(string message) { - Output += message + System.Environment.NewLine; + _sb.AppendLine(message); _messageSink.OnMessage(new Xunit.v3.DiagnosticMessage(message)); } public void WriteLine(string format, params object[] args) { - Output += string.Format(System.Globalization.CultureInfo.InvariantCulture, format, args) + System.Environment.NewLine; + _sb.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, format, args); + _sb.AppendLine(); _messageSink.OnMessage(new Xunit.v3.DiagnosticMessage(format, args)); } } From 77d93e4160a047002d656866168c21b628983ec1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Jul 2026 09:18:43 +0000 Subject: [PATCH 12/19] Restore xUnit1051 suppression with explanatory comment --- test/Directory.Build.props | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/Directory.Build.props b/test/Directory.Build.props index 03e7099823e..58b120d457f 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -2,7 +2,9 @@ false - $(NoWarn);RT0000 + + $(NoWarn);RT0000;xUnit1051 XUnitV3 From bf1d599e7b0421a402dd5788fa71628ce0a8e17c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Jul 2026 10:00:29 +0000 Subject: [PATCH 13/19] Fix NU1010 by using literal net10.0 instead of $(LatestTargetFramework), fix xUnit1051 comment --- eng/packages/Tests.props | 2 +- test/Directory.Build.props | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/eng/packages/Tests.props b/eng/packages/Tests.props index 94355370426..1ff68b4863b 100644 --- a/eng/packages/Tests.props +++ b/eng/packages/Tests.props @@ -61,7 +61,7 @@ - + diff --git a/test/Directory.Build.props b/test/Directory.Build.props index 58b120d457f..af9331f6b09 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -2,8 +2,8 @@ false - + $(NoWarn);RT0000;xUnit1051 XUnitV3 From 2b96c96482b1ffc2aefc28db22a4e2e5665e1539 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Fri, 3 Jul 2026 12:51:04 +0200 Subject: [PATCH 14/19] fix the Windows build --- eng/packages/General.props | 2 +- eng/packages/Tests.props | 4 ++-- ...Diagnostics.HealthChecks.ResourceUtilization.Tests.csproj | 2 +- .../Microsoft.Extensions.Diagnostics.Probes.Tests.csproj | 2 +- ...ns.Diagnostics.ResourceMonitoring.Kubernetes.Tests.csproj | 2 +- ...ft.Extensions.Diagnostics.ResourceMonitoring.Tests.csproj | 2 +- .../Microsoft.Extensions.Http.Diagnostics.Tests.csproj | 2 +- .../Microsoft.Extensions.Http.Resilience.Tests.csproj | 3 +-- .../Microsoft.Extensions.Options.Contextual.Tests.csproj | 2 +- .../Microsoft.Extensions.Resilience.Tests.csproj | 5 ----- .../Microsoft.Extensions.ServiceDiscovery.Tests.csproj | 2 +- .../Microsoft.Extensions.Telemetry.Abstractions.Tests.csproj | 2 +- .../Microsoft.Extensions.Telemetry.Tests.csproj | 2 +- 13 files changed, 13 insertions(+), 19 deletions(-) diff --git a/eng/packages/General.props b/eng/packages/General.props index 59290680f74..80325ca0efd 100644 --- a/eng/packages/General.props +++ b/eng/packages/General.props @@ -41,7 +41,7 @@ - + diff --git a/eng/packages/Tests.props b/eng/packages/Tests.props index 1ff68b4863b..18beee83aa4 100644 --- a/eng/packages/Tests.props +++ b/eng/packages/Tests.props @@ -46,7 +46,7 @@ - + @@ -61,7 +61,7 @@ - + diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests.csproj b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests.csproj index 3d0296419ac..74198ce98e7 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests.csproj @@ -13,7 +13,7 @@ - + diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/Microsoft.Extensions.Diagnostics.Probes.Tests.csproj b/test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/Microsoft.Extensions.Diagnostics.Probes.Tests.csproj index 6e1c0cdf3fb..5f363b88ed2 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/Microsoft.Extensions.Diagnostics.Probes.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.Probes.Tests/Microsoft.Extensions.Diagnostics.Probes.Tests.csproj @@ -15,7 +15,7 @@ - + diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests.csproj b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests.csproj index a8a58ef0559..7bdaf6f27e0 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests.csproj @@ -11,7 +11,7 @@ - + diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests.csproj b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests.csproj index b88534f1408..b45e7b29084 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests.csproj @@ -5,7 +5,7 @@ true - + diff --git a/test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Microsoft.Extensions.Http.Diagnostics.Tests.csproj b/test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Microsoft.Extensions.Http.Diagnostics.Tests.csproj index 4bc20735577..118937eb1ed 100644 --- a/test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Microsoft.Extensions.Http.Diagnostics.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.Http.Diagnostics.Tests/Microsoft.Extensions.Http.Diagnostics.Tests.csproj @@ -27,7 +27,7 @@ - + diff --git a/test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Microsoft.Extensions.Http.Resilience.Tests.csproj b/test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Microsoft.Extensions.Http.Resilience.Tests.csproj index 95e047fabb3..cee9a69a16c 100644 --- a/test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Microsoft.Extensions.Http.Resilience.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Microsoft.Extensions.Http.Resilience.Tests.csproj @@ -24,11 +24,10 @@ - - + diff --git a/test/Libraries/Microsoft.Extensions.Options.ContextualOptions.Tests/Microsoft.Extensions.Options.Contextual.Tests.csproj b/test/Libraries/Microsoft.Extensions.Options.ContextualOptions.Tests/Microsoft.Extensions.Options.Contextual.Tests.csproj index d440b8820db..6709628b4d1 100644 --- a/test/Libraries/Microsoft.Extensions.Options.ContextualOptions.Tests/Microsoft.Extensions.Options.Contextual.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.Options.ContextualOptions.Tests/Microsoft.Extensions.Options.Contextual.Tests.csproj @@ -14,7 +14,7 @@ - + diff --git a/test/Libraries/Microsoft.Extensions.Resilience.Tests/Microsoft.Extensions.Resilience.Tests.csproj b/test/Libraries/Microsoft.Extensions.Resilience.Tests/Microsoft.Extensions.Resilience.Tests.csproj index 163b01082d1..c7b2043dcc3 100644 --- a/test/Libraries/Microsoft.Extensions.Resilience.Tests/Microsoft.Extensions.Resilience.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.Resilience.Tests/Microsoft.Extensions.Resilience.Tests.csproj @@ -8,11 +8,6 @@ true - - - true - - diff --git a/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Tests/Microsoft.Extensions.ServiceDiscovery.Tests.csproj b/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Tests/Microsoft.Extensions.ServiceDiscovery.Tests.csproj index a589eccc256..4dc289c3caa 100644 --- a/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Tests/Microsoft.Extensions.ServiceDiscovery.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.ServiceDiscovery.Tests/Microsoft.Extensions.ServiceDiscovery.Tests.csproj @@ -8,7 +8,7 @@ $(NoWarn);IDE0004;IDE0040;IDE0055;IDE1006;CA2000;S1121;S1128;SA1316;SA1500;SA1513 - + diff --git a/test/Libraries/Microsoft.Extensions.Telemetry.Abstractions.Tests/Microsoft.Extensions.Telemetry.Abstractions.Tests.csproj b/test/Libraries/Microsoft.Extensions.Telemetry.Abstractions.Tests/Microsoft.Extensions.Telemetry.Abstractions.Tests.csproj index 387cec3c5c0..267e1de7143 100644 --- a/test/Libraries/Microsoft.Extensions.Telemetry.Abstractions.Tests/Microsoft.Extensions.Telemetry.Abstractions.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.Telemetry.Abstractions.Tests/Microsoft.Extensions.Telemetry.Abstractions.Tests.csproj @@ -13,7 +13,7 @@ - + diff --git a/test/Libraries/Microsoft.Extensions.Telemetry.Tests/Microsoft.Extensions.Telemetry.Tests.csproj b/test/Libraries/Microsoft.Extensions.Telemetry.Tests/Microsoft.Extensions.Telemetry.Tests.csproj index b52f7b92d76..73f6aa0f1de 100644 --- a/test/Libraries/Microsoft.Extensions.Telemetry.Tests/Microsoft.Extensions.Telemetry.Tests.csproj +++ b/test/Libraries/Microsoft.Extensions.Telemetry.Tests/Microsoft.Extensions.Telemetry.Tests.csproj @@ -2,7 +2,7 @@ Microsoft.Extensions.Telemetry Unit tests for Microsoft.Extensions.Telemetry. - $(NoWarn);CS0436 + $(NoWarn);CS0436 From fe3a01705340483fd1a53b9ac3cd16fe608ce245 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Jul 2026 12:08:57 +0000 Subject: [PATCH 15/19] Replace OperatingSystem.Is* with RuntimeInformation.IsOSPlatform for Full Framework compatibility --- .../FakeCertificateFactoryTests.cs | 5 ++-- .../DiskBased/PathValidationTests.cs | 22 +++++++++--------- .../Linux/LinuxResourceHealthCheckTests.cs | 3 ++- .../ResourceHealthCheckExtensionsTests.cs | 5 ++-- .../Linux/AcceptanceTest.cs | 3 ++- .../Linux/AcceptanceTest.cs | 17 +++++++------- .../Linux/Disk/DiskStatsReaderTests.cs | 3 ++- .../Linux/Disk/LinuxSystemDiskMetricsTests.cs | 3 ++- .../Linux/LinuxNetworkMetricsTests.cs | 3 ++- .../LinuxUtilizationParserCgroupV1Tests.cs | 3 ++- .../LinuxUtilizationParserCgroupV2Tests.cs | 3 ++- .../Linux/LinuxUtilizationProviderTests.cs | 3 ++- .../Linux/OSFileSystemTests.cs | 3 ++- .../ResourceMonitoringBuilderTests.cs | 3 ++- .../ResourceMonitoringExtensionsTests.cs | 23 ++++++++++--------- .../Disk/WindowsDiskIoRatePerfCounterTests.cs | 3 ++- .../Disk/WindowsDiskIoTimePerfCounterTests.cs | 3 ++- .../Windows/Disk/WindowsDiskMetricsTests.cs | 3 ++- .../Windows/MemoryInfoTests.cs | 3 ++- .../Windows/PerformanceCounterFactoryTests.cs | 3 ++- .../Windows/PerformanceCounterWrapperTests.cs | 3 ++- .../Windows/SystemInfoTests.cs | 3 ++- .../Windows/Tcp6TableInfoTests.cs | 2 +- .../Windows/TcpTableInfoTests.cs | 2 +- .../Windows/WindowsNetworkMetricsTests.cs | 3 ++- .../Windows/WindowsSnapshotProviderTests.cs | 3 ++- 26 files changed, 78 insertions(+), 55 deletions(-) diff --git a/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs b/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs index 47dfc06a4c2..bf9c02aa6bc 100644 --- a/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs +++ b/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Security.Cryptography.X509Certificates; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Testing.Test; @@ -27,7 +28,7 @@ public void Create_CreatesCertificate() [InlineData(true)] public void GenerateRsa_RunsOnWindows_GeneratesRsa(bool runsOnWindows) { - Assert.SkipUnless(!OperatingSystem.IsLinux(), "Skipped on Linux"); + Assert.SkipUnless(!RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Skipped on Linux"); Assert.NotNull(FakeSslCertificateFactory.GenerateRsa(runsOnWindows)); } @@ -35,7 +36,7 @@ public void GenerateRsa_RunsOnWindows_GeneratesRsa(bool runsOnWindows) [Fact] public void GenerateRsa_DoesNotRunOnWindows_GeneratesRsa() { - Assert.SkipUnless(!OperatingSystem.IsWindows(), "Skipped on Windows"); + Assert.SkipUnless(!RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Windows"); Assert.NotNull(FakeSslCertificateFactory.GenerateRsa(runsOnWindows: false)); } diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/PathValidationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/PathValidationTests.cs index ad8bf5216ae..9b47d0404cb 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/PathValidationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/PathValidationTests.cs @@ -259,7 +259,7 @@ await Assert.ThrowsAsync(() => [Fact] public void EnsureWithinRoot_UncPath_ChildPath_ReturnsResolved() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); string root = @"\\server\share\data"; string child = @"\\server\share\data\sub\file.txt"; @@ -272,7 +272,7 @@ public void EnsureWithinRoot_UncPath_ChildPath_ReturnsResolved() [Fact] public void EnsureWithinRoot_UncPath_DifferentShare_Throws() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); string root = @"\\server\share\data"; string other = @"\\server\share\other\file.txt"; @@ -284,7 +284,7 @@ public void EnsureWithinRoot_UncPath_DifferentShare_Throws() [Fact] public void EnsureWithinRoot_UncPath_DotDotEscapes_Throws() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); string root = @"\\server\share\data"; string escaped = @"\\server\share\data\..\other"; @@ -296,7 +296,7 @@ public void EnsureWithinRoot_UncPath_DotDotEscapes_Throws() [Fact] public void EnsureWithinRoot_UncPath_SiblingWithPrefix_Throws() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); string root = @"\\server\share\data"; string sibling = @"\\server\share\data-sibling\file.txt"; @@ -308,7 +308,7 @@ public void EnsureWithinRoot_UncPath_SiblingWithPrefix_Throws() [Fact] public void EnsureWithinRoot_UncPath_PathEqualsRoot_DoesNotThrow() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); string root = @"\\server\share\data"; @@ -324,7 +324,7 @@ public void EnsureWithinRoot_UncPath_PathEqualsRoot_DoesNotThrow() [Fact] public void EnsureWithinRoot_ShortPathRoot_LongPathChild_DocumentedBehavior() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); // Short (8.3) paths are NOT consistently normalized by Path.GetFullPath // across .NET versions. This test documents that if the root uses a short @@ -373,7 +373,7 @@ public void EnsureWithinRoot_ShortPathRoot_LongPathChild_DocumentedBehavior() [Fact] public void EnsureWithinRoot_ConsistentShortPaths_Works() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); // When both root and child are constructed from the same short-path // string via Path.Combine, EnsureWithinRoot succeeds because @@ -412,7 +412,7 @@ public void EnsureWithinRoot_ConsistentShortPaths_Works() [Fact] public void EnsureWithinRoot_AltSeparatorInRoot_Works() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); // Forward slash is an alternate directory separator on Windows. string root = Path.GetTempPath().Replace('\\', '/') + "testroot"; @@ -446,7 +446,7 @@ public void EnsureWithinRoot_CaseMismatch_BehavesPerPlatform() [Fact] public void EnsureWithinRoot_DriveRoot_ChildPath_Works() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); string root = @"C:\"; string child = @"C:\some\nested\file.txt"; @@ -459,7 +459,7 @@ public void EnsureWithinRoot_DriveRoot_ChildPath_Works() [Fact] public void EnsureWithinRoot_DriveRoot_DifferentDrive_Throws() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); string root = @"C:\data"; string other = @"D:\data\file.txt"; @@ -471,7 +471,7 @@ public void EnsureWithinRoot_DriveRoot_DifferentDrive_Throws() [Fact] public void EnsureWithinRoot_UnixAbsoluteRoot_ChildPath_Works() { - Assert.SkipUnless(!OperatingSystem.IsWindows(), "Skipped on Windows"); + Assert.SkipUnless(!RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Windows"); string root = "/tmp/testroot"; string child = "/tmp/testroot/sub/file.txt"; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs index 2521dcc8a5e..a92b051ae5d 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs @@ -11,6 +11,7 @@ using Microsoft.Extensions.Time.Testing; using Moq; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.HealthChecks.Test; @@ -148,7 +149,7 @@ public async Task TestCpuAndMemoryChecks_WithMetrics( ResourceUsageThresholds cpuThresholds, ResourceUsageThresholds memoryThresholds, string expectedDescription) { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux-specific test."); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Linux-specific test."); var fakeClock = new FakeTimeProvider(); var dataTracker = new Mock(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs index 5c42a2c02aa..3778b9c41bd 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs @@ -16,6 +16,7 @@ using Moq; using Xunit; using static Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Interop.JobObjectInfo; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.HealthChecks.Test; @@ -23,7 +24,7 @@ public class ResourceHealthCheckExtensionsTests { public ResourceHealthCheckExtensionsTests() { - Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Skipped on macOS"); + Assert.SkipUnless(!RuntimeInformation.IsOSPlatform(OSPlatform.OSX), "Skipped on macOS"); } [Fact] @@ -474,7 +475,7 @@ public async Task TestCpuAndMemoryChecks_WithMetrics( ResourceUsageThresholds cpuThresholds, ResourceUsageThresholds memoryThresholds, string expectedDescription) { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Windows-specific test."); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Windows-specific test."); var logger = new FakeLogger(); var fakeClock = new FakeTimeProvider(); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs index a4c9e3006a7..3c4c6fd95d8 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs @@ -12,6 +12,7 @@ using Microsoft.Shared.Instruments; using Moq; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Linux; @@ -19,7 +20,7 @@ public class AcceptanceTest { public AcceptanceTest() { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Skipped on Windows/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Skipped on Windows/macOS"); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs index edbb0f29f8e..56414e997fa 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs @@ -20,6 +20,7 @@ using Microsoft.Extensions.Time.Testing; using Microsoft.Shared.Instruments; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; @@ -28,7 +29,7 @@ public sealed class AcceptanceTest [Fact] public void Adding_Linux_Resource_Utilization_Allows_To_Query_Snapshot_Provider() { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux specific tests"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Linux specific tests"); using var services = new ServiceCollection() .AddResourceMonitoring() @@ -44,7 +45,7 @@ public void Adding_Linux_Resource_Utilization_Allows_To_Query_Snapshot_Provider( [SuppressMessage("Minor Code Smell", "S3257:Declarations and initializations should be as concise as possible", Justification = "Broken analyzer.")] public void Adding_Linux_Resource_Utilization_Can_Be_Configured_With_Section() { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux specific tests"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Linux specific tests"); var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -74,7 +75,7 @@ public void Adding_Linux_Resource_Utilization_Can_Be_Configured_With_Section() [Fact] public void Adding_Linux_Resource_Utilization_Can_Be_Configured_With_Action() { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux specific tests"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Linux specific tests"); var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -98,7 +99,7 @@ public void Adding_Linux_Resource_Utilization_Can_Be_Configured_With_Action() [SuppressMessage("Minor Code Smell", "S3257:Declarations and initializations should be as concise as possible", Justification = "Broken analyzer.")] public void Adding_Linux_Resource_Utilization_With_Section_Registers_SnapshotProvider_Cgroupv1() { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux specific tests"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Linux specific tests"); var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -148,7 +149,7 @@ public void Adding_Linux_Resource_Utilization_With_Section_Registers_SnapshotPro [SuppressMessage("Minor Code Smell", "S3257:Declarations and initializations should be as concise as possible", Justification = "Broken analyzer.")] public void Adding_Linux_Resource_Utilization_With_Section_Registers_SnapshotProvider_Cgroupv2() { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux specific tests"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Linux specific tests"); var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -197,7 +198,7 @@ public void Adding_Linux_Resource_Utilization_With_Section_Registers_SnapshotPro [Fact] public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgroupsv1() { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux specific tests"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Linux specific tests"); var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -296,7 +297,7 @@ public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgrou [Fact] public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgroupsv2() { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux specific tests"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Linux specific tests"); var cpuRefresh = TimeSpan.FromMinutes(13); var memoryRefresh = TimeSpan.FromMinutes(14); @@ -405,7 +406,7 @@ public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgrou [Fact] public Task ResourceUtilizationTracker_And_Metrics_Report_Same_Values_With_Cgroupsv2_Using_LinuxCalculationV2() { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Linux specific tests"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Linux specific tests"); var fileSystem = new HardcodedValueFileSystem(new Dictionary { diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs index 9e3d06cedeb..39cd6f800f0 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs @@ -7,6 +7,7 @@ using System.Linq; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Disk.Test; @@ -14,7 +15,7 @@ public class DiskStatsReaderTests { public DiskStatsReaderTests() { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Skipped on Windows/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Skipped on Windows/macOS"); } private static readonly string[] _skipDevicePrefixes = new[] { "ram", "loop", "dm-" }; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs index 54720f24868..7e22b8be45d 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs @@ -13,6 +13,7 @@ using Microsoft.Shared.Instruments; using Moq; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Disk.Test; @@ -20,7 +21,7 @@ public class LinuxSystemDiskMetricsTests { public LinuxSystemDiskMetricsTests() { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Skipped on Windows/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Skipped on Windows/macOS"); } private static readonly string[] _skipDevicePrefixes = new[] { "ram", "loop", "dm-" }; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxNetworkMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxNetworkMetricsTests.cs index 158bd181cab..0ca488663f4 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxNetworkMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxNetworkMetricsTests.cs @@ -12,6 +12,7 @@ using Microsoft.Shared.Instruments; using Moq; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; @@ -23,7 +24,7 @@ public class LinuxNetworkMetricsTests public LinuxNetworkMetricsTests() { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Skipped on Windows/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Skipped on Windows/macOS"); _timeProvider = new FakeTimeProvider(_startTime); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs index ea9b2ee085a..c985a769e6b 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs @@ -10,6 +10,7 @@ using Microsoft.Shared.Pools; using Moq; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; @@ -17,7 +18,7 @@ public sealed class LinuxUtilizationParserCgroupV1Tests { public LinuxUtilizationParserCgroupV1Tests() { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Skipped on Windows/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Skipped on Windows/macOS"); } [Theory] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs index ec7b0b91a35..3dbbc533a14 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs @@ -10,6 +10,7 @@ using Moq; using VerifyXunit; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; @@ -17,7 +18,7 @@ public sealed class LinuxUtilizationParserCgroupV2Tests { public LinuxUtilizationParserCgroupV2Tests() { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Skipped on Windows/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Skipped on Windows/macOS"); } private const string VerifiedDataDirectory = "Verified"; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs index 87b7629576c..7f5f5433f70 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs @@ -14,6 +14,7 @@ using Moq; using VerifyXunit; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; @@ -21,7 +22,7 @@ public sealed class LinuxUtilizationProviderTests { public LinuxUtilizationProviderTests() { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Skipped on Windows/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Skipped on Windows/macOS"); } private const string VerifiedDataDirectory = "Verified"; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs index 43cbac0725e..af2550ebfc5 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs @@ -7,6 +7,7 @@ using System.Text; using Microsoft.Shared.Pools; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; @@ -14,7 +15,7 @@ public sealed class OSFileSystemTests { public OSFileSystemTests() { - Assert.SkipUnless(OperatingSystem.IsLinux(), "Skipped on Windows/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Linux), "Skipped on Windows/macOS"); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs index 2bc9d1c315b..fcb354ff52f 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Publishers; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test; @@ -13,7 +14,7 @@ public sealed class ResourceMonitoringBuilderTests { public ResourceMonitoringBuilderTests() { - Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Skipped on macOS"); + Assert.SkipUnless(!RuntimeInformation.IsOSPlatform(OSPlatform.OSX), "Skipped on macOS"); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs index a61c48ccef9..3b42983869f 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs @@ -12,6 +12,7 @@ using Microsoft.Extensions.Hosting.Testing; using Microsoft.Extensions.Options; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test; @@ -20,7 +21,7 @@ public sealed class ResourceMonitoringExtensionsTests [Fact] public void Throw_Null_When_Registration_Ingredients_Null() { - Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); + Assert.SkipUnless(!RuntimeInformation.IsOSPlatform(OSPlatform.OSX), "Not supported on MacOs."); var services = new ServiceCollection(); @@ -33,7 +34,7 @@ public void Throw_Null_When_Registration_Ingredients_Null() [Fact] public void AddsResourceMonitoringService_ToServicesCollection() { - Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); + Assert.SkipUnless(!RuntimeInformation.IsOSPlatform(OSPlatform.OSX), "Not supported on MacOs."); using var provider = new ServiceCollection() .AddLogging() @@ -55,7 +56,7 @@ public void AddsResourceMonitoringService_ToServicesCollection() [Fact] public void AddsResourceMonitoringService_ToServicesCollection_NoArgs() { - Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); + Assert.SkipUnless(!RuntimeInformation.IsOSPlatform(OSPlatform.OSX), "Not supported on MacOs."); using var provider = new ServiceCollection() .AddLogging() @@ -73,7 +74,7 @@ public void AddsResourceMonitoringService_ToServicesCollection_NoArgs() [Fact] public void AddsResourceMonitoringService_AsHostedService() { - Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); + Assert.SkipUnless(!RuntimeInformation.IsOSPlatform(OSPlatform.OSX), "Not supported on MacOs."); using var provider = new ServiceCollection() .AddLogging() @@ -96,7 +97,7 @@ public void AddsResourceMonitoringService_AsHostedService() [Fact] public void ConfigureResourceUtilization_InitializeTrackerProperly() { - Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); + Assert.SkipUnless(!RuntimeInformation.IsOSPlatform(OSPlatform.OSX), "Not supported on MacOs."); using var host = FakeHost.CreateBuilder() .ConfigureServices(services => @@ -124,7 +125,7 @@ public void ConfigureResourceUtilization_InitializeTrackerProperly() [Fact] public void ConfigureMonitor_GivenOptionsDelegate_InitializeTrackerWithOptionsProperly() { - Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); + Assert.SkipUnless(!RuntimeInformation.IsOSPlatform(OSPlatform.OSX), "Not supported on MacOs."); const int SamplingWindowValue = 3; const int CalculationPeriodValue = 2; @@ -154,7 +155,7 @@ public void ConfigureMonitor_GivenOptionsDelegate_InitializeTrackerWithOptionsPr [Fact] public void ConfigureMonitor_GivenIConfigurationSection_InitializeTrackerWithOptionsProperly() { - Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); + Assert.SkipUnless(!RuntimeInformation.IsOSPlatform(OSPlatform.OSX), "Not supported on MacOs."); const int SamplingWindowValue = 3; const int CalculationPeriod = 2; @@ -197,7 +198,7 @@ public void ConfigureMonitor_GivenIConfigurationSection_InitializeTrackerWithOpt [Fact] public void Registering_Resource_Utilization_Adds_Only_One_Object_Of_Type_ResourceUtilizationService_To_DI_Container() { - Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); + Assert.SkipUnless(!RuntimeInformation.IsOSPlatform(OSPlatform.OSX), "Not supported on MacOs."); using var host = FakeHost.CreateBuilder() .ConfigureServices(services => @@ -222,7 +223,7 @@ public void Registering_Resource_Utilization_Adds_Only_One_Object_Of_Type_Resour [Fact] public void AddResourceMonitoringInternal_WhenMacOs_ReturnsSameServiceCollection() { - Assert.SkipUnless(OperatingSystem.IsMacOS(), "For MacOs only."); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.OSX), "For MacOs only."); var services = new ServiceCollection(); @@ -237,7 +238,7 @@ public void AddResourceMonitoringInternal_WhenMacOs_ReturnsSameServiceCollection [Fact] public void AddResourceMonitoring_AddsISnapshotProvider() { - Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); + Assert.SkipUnless(!RuntimeInformation.IsOSPlatform(OSPlatform.OSX), "Not supported on MacOs."); var services = new ServiceCollection(); @@ -252,7 +253,7 @@ public void AddResourceMonitoring_AddsISnapshotProvider() [Fact] public void AddResourceMonitoringInternal_CallsConfigureDelegate() { - Assert.SkipUnless(!OperatingSystem.IsMacOS(), "Not supported on MacOs."); + Assert.SkipUnless(!RuntimeInformation.IsOSPlatform(OSPlatform.OSX), "Not supported on MacOs."); var services = new ServiceCollection(); bool delegateCalled = false; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs index b33ef54e806..0e1b246b312 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Time.Testing; using Moq; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Disk.Test; @@ -15,7 +16,7 @@ public class WindowsDiskIoRatePerfCounterTests { public WindowsDiskIoRatePerfCounterTests() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); } private const string CategoryName = "LogicalDisk"; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs index 3180be4c239..b1d90c47e14 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.Time.Testing; using Moq; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Disk.Test; @@ -15,7 +16,7 @@ public class WindowsDiskIoTimePerfCounterTests { public WindowsDiskIoTimePerfCounterTests() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); } private const string CategoryName = "LogicalDisk"; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs index 76eced19d90..c04ddf32b76 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs @@ -14,6 +14,7 @@ using Microsoft.Shared.Instruments; using Moq; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Disk.Test; @@ -22,7 +23,7 @@ public class WindowsDiskMetricsTests { public WindowsDiskMetricsTests() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); } private const string CategoryName = "LogicalDisk"; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs index 68a2bbc4f8a..d7f5f5e97a9 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs @@ -4,6 +4,7 @@ using System; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Interop; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; @@ -16,7 +17,7 @@ public sealed class MemoryInfoTests { public MemoryInfoTests() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs index 9d3a7754d5d..ec652800283 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs @@ -4,6 +4,7 @@ using System; using System.Runtime.Versioning; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; @@ -12,7 +13,7 @@ public class PerformanceCounterFactoryTests { public PerformanceCounterFactoryTests() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs index ce33e537c71..8388cde4aa7 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs @@ -4,6 +4,7 @@ using System; using System.Runtime.Versioning; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; @@ -12,7 +13,7 @@ public class PerformanceCounterWrapperTests { public PerformanceCounterWrapperTests() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs index a10da3756a5..a89b4d23945 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs @@ -4,6 +4,7 @@ using System; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Interop; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; @@ -16,7 +17,7 @@ public sealed class SystemInfoTests { public SystemInfoTests() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); } /// diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Tcp6TableInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Tcp6TableInfoTests.cs index b77162f3482..a1cc1b29a87 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Tcp6TableInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Tcp6TableInfoTests.cs @@ -18,7 +18,7 @@ public sealed class Tcp6TableInfoTests { public Tcp6TableInfoTests() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); } public static readonly TimeSpan DefaultTimeSpan = TimeSpan.FromSeconds(5); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/TcpTableInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/TcpTableInfoTests.cs index f67f66bc07d..36171cab650 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/TcpTableInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/TcpTableInfoTests.cs @@ -15,7 +15,7 @@ public sealed class TcpTableInfoTests { public TcpTableInfoTests() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); } public static readonly TimeSpan DefaultTimeSpan = TimeSpan.FromSeconds(5); diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs index 3327df6fb77..9edbce0be8f 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs @@ -9,6 +9,7 @@ using Microsoft.Shared.Instruments; using Moq; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; @@ -16,7 +17,7 @@ public class WindowsNetworkMetricsTests { public WindowsNetworkMetricsTests() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsSnapshotProviderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsSnapshotProviderTests.cs index 558defd43aa..35f6bd61874 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsSnapshotProviderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsSnapshotProviderTests.cs @@ -15,6 +15,7 @@ using Moq; using VerifyXunit; using Xunit; +using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; @@ -28,7 +29,7 @@ public sealed class WindowsSnapshotProviderTests public WindowsSnapshotProviderTests() { - Assert.SkipUnless(OperatingSystem.IsWindows(), "Skipped on Linux/macOS"); + Assert.SkipUnless(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipped on Linux/macOS"); _options = Options.Options.Create(new()); using var meter = new Meter(nameof(BasicConstructor)); From 775f64674e2b96792fd13e27a78805c25728032e Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Fri, 3 Jul 2026 16:07:16 +0200 Subject: [PATCH 16/19] fix the Windows build --- eng/MSBuild/LegacySupport.props | 44 +++++++++---------- .../AzureStorage/AzureResponseCacheTests.cs | 9 +++- .../AzureStorage/AzureResultStoreTests.cs | 9 +++- .../DiskBased/DiskBasedResponseCacheTests.cs | 13 +++++- .../DiskBased/DiskBasedResultStoreTests.cs | 13 +++++- 5 files changed, 62 insertions(+), 26 deletions(-) diff --git a/eng/MSBuild/LegacySupport.props b/eng/MSBuild/LegacySupport.props index 20fe1187732..82756c73912 100644 --- a/eng/MSBuild/LegacySupport.props +++ b/eng/MSBuild/LegacySupport.props @@ -1,89 +1,89 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResponseCacheTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResponseCacheTests.cs index 4c7ddfe76a9..ad7b460f0dc 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResponseCacheTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResponseCacheTests.cs @@ -35,7 +35,14 @@ public AzureResponseCacheTests() _dirClient = _fsClient?.GetDirectoryClient(Path.GetRandomFileName()); } - public ValueTask InitializeAsync() => ValueTask.CompletedTask; + public ValueTask InitializeAsync() + { +#if NET + return ValueTask.CompletedTask; +#else + return new ValueTask(Task.CompletedTask); +#endif + } public async ValueTask DisposeAsync() { diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResultStoreTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResultStoreTests.cs index b6583675bbb..375a58bb8ac 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResultStoreTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/AzureStorage/AzureResultStoreTests.cs @@ -35,7 +35,14 @@ public AzureResultStoreTests() _dirClient = _fsClient?.GetDirectoryClient(Path.GetRandomFileName()); } - public ValueTask InitializeAsync() => ValueTask.CompletedTask; + public ValueTask InitializeAsync() + { +#if NET + return ValueTask.CompletedTask; +#else + return new ValueTask(Task.CompletedTask); +#endif + } public async ValueTask DisposeAsync() { diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResponseCacheTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResponseCacheTests.cs index 9917f2f9b80..4e188343099 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResponseCacheTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResponseCacheTests.cs @@ -22,7 +22,14 @@ private string UseTempStoragePath() return path; } - public ValueTask InitializeAsync() => ValueTask.CompletedTask; + public ValueTask InitializeAsync() + { +#if NET + return ValueTask.CompletedTask; +#else + return new ValueTask(Task.CompletedTask); +#endif + } public ValueTask DisposeAsync() { @@ -41,7 +48,11 @@ public ValueTask DisposeAsync() } } +#if NET return ValueTask.CompletedTask; +#else + return new ValueTask(Task.CompletedTask); +#endif } internal override bool IsConfigured => true; diff --git a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResultStoreTests.cs b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResultStoreTests.cs index d85f807bfd3..184ed9d922a 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResultStoreTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Evaluation.Reporting.Tests/DiskBased/DiskBasedResultStoreTests.cs @@ -22,7 +22,14 @@ private string UseTempStoragePath() return path; } - public ValueTask InitializeAsync() => ValueTask.CompletedTask; + public ValueTask InitializeAsync() + { +#if NET + return ValueTask.CompletedTask; +#else + return new ValueTask(Task.CompletedTask); +#endif + } public ValueTask DisposeAsync() { @@ -41,7 +48,11 @@ public ValueTask DisposeAsync() } } +#if NET return ValueTask.CompletedTask; +#else + return new ValueTask(Task.CompletedTask); +#endif } public override bool IsConfigured => true; From 03c1650ed55e60a88c5ce7181c4689e9e55d9b28 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Jul 2026 14:35:54 +0000 Subject: [PATCH 17/19] Fix SA1208/SA1210: sort using directives alphabetically with System.* first --- .../FakeCertificateFactoryTests.cs | 2 +- .../Linux/LinuxResourceHealthCheckTests.cs | 2 +- .../ResourceHealthCheckExtensionsTests.cs | 2 +- .../Linux/AcceptanceTest.cs | 2 +- .../Linux/AcceptanceTest.cs | 4 +--- .../Linux/Disk/DiskStatsReaderTests.cs | 2 +- .../Linux/Disk/LinuxSystemDiskMetricsTests.cs | 2 +- .../Linux/LinuxNetworkMetricsTests.cs | 2 +- .../Linux/LinuxUtilizationParserCgroupV1Tests.cs | 2 +- .../Linux/LinuxUtilizationParserCgroupV2Tests.cs | 2 +- .../Linux/LinuxUtilizationProviderTests.cs | 2 +- .../Linux/OSFileSystemTests.cs | 2 +- .../ResourceMonitoringBuilderTests.cs | 2 +- .../ResourceMonitoringExtensionsTests.cs | 2 +- .../Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs | 2 +- .../Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs | 2 +- .../Windows/Disk/WindowsDiskMetricsTests.cs | 2 +- .../Windows/MemoryInfoTests.cs | 2 +- .../Windows/PerformanceCounterFactoryTests.cs | 2 +- .../Windows/PerformanceCounterWrapperTests.cs | 2 +- .../Windows/SystemInfoTests.cs | 2 +- .../Windows/WindowsNetworkMetricsTests.cs | 2 +- .../Windows/WindowsSnapshotProviderTests.cs | 2 +- 23 files changed, 23 insertions(+), 25 deletions(-) diff --git a/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs b/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs index bf9c02aa6bc..b7236129359 100644 --- a/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs +++ b/test/Libraries/Microsoft.AspNetCore.Testing.Tests/FakeCertificateFactoryTests.cs @@ -3,9 +3,9 @@ using System; using System.Linq; +using System.Runtime.InteropServices; using System.Security.Cryptography.X509Certificates; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.AspNetCore.Testing.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs index a92b051ae5d..233ad42fd6e 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/Linux/LinuxResourceHealthCheckTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.Metrics; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.Extensions.Diagnostics.ResourceMonitoring; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux; @@ -11,7 +12,6 @@ using Microsoft.Extensions.Time.Testing; using Moq; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.HealthChecks.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs index 3778b9c41bd..114e3690026 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization.Tests/ResourceHealthCheckExtensionsTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.Metrics; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -16,7 +17,6 @@ using Moq; using Xunit; using static Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Interop.JobObjectInfo; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.HealthChecks.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs index 3c4c6fd95d8..9bf3db7de4f 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes.Tests/Linux/AcceptanceTest.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics.Metrics; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.Extensions.Diagnostics.Metrics.Testing; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes; @@ -12,7 +13,6 @@ using Microsoft.Shared.Instruments; using Moq; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Linux; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs index 56414e997fa..d36f35d04af 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs @@ -6,9 +6,8 @@ using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Metrics; using System.IO; -#if !NET10_0 using System.Linq; -#endif +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; @@ -20,7 +19,6 @@ using Microsoft.Extensions.Time.Testing; using Microsoft.Shared.Instruments; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs index 39cd6f800f0..7ccf2477646 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/DiskStatsReaderTests.cs @@ -5,9 +5,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Disk.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs index 7e22b8be45d..1276a86181a 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/Disk/LinuxSystemDiskMetricsTests.cs @@ -6,6 +6,7 @@ using System.Diagnostics.Metrics; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using Microsoft.Extensions.Diagnostics.Metrics.Testing; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Helpers; using Microsoft.Extensions.Logging.Testing; @@ -13,7 +14,6 @@ using Microsoft.Shared.Instruments; using Moq; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Disk.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxNetworkMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxNetworkMetricsTests.cs index 0ca488663f4..e6c001d5f78 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxNetworkMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxNetworkMetricsTests.cs @@ -6,13 +6,13 @@ using System.Diagnostics.Metrics; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Network; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Helpers; using Microsoft.Extensions.Time.Testing; using Microsoft.Shared.Instruments; using Moq; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs index c985a769e6b..52511de8157 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV1Tests.cs @@ -6,11 +6,11 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.Shared.Pools; using Moq; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs index 3dbbc533a14..2e62afa8f21 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationParserCgroupV2Tests.cs @@ -5,12 +5,12 @@ using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.Shared.Pools; using Moq; using VerifyXunit; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs index 7f5f5433f70..a820988e36c 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxUtilizationProviderTests.cs @@ -6,6 +6,7 @@ using System.Diagnostics.Metrics; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Helpers; using Microsoft.Extensions.Logging.Testing; @@ -14,7 +15,6 @@ using Moq; using VerifyXunit; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs index af2550ebfc5..9c81e144a53 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/OSFileSystemTests.cs @@ -4,10 +4,10 @@ using System; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using Microsoft.Shared.Pools; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs index fcb354ff52f..3ad80704f05 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs @@ -3,10 +3,10 @@ using System; using System.Linq; +using System.Runtime.InteropServices; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Publishers; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs index 3b42983869f..ed6d57f9e09 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringExtensionsTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Providers; @@ -12,7 +13,6 @@ using Microsoft.Extensions.Hosting.Testing; using Microsoft.Extensions.Options; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs index 0e1b246b312..3c1d1ee50d7 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoRatePerfCounterTests.cs @@ -2,12 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Runtime.InteropServices; using System.Runtime.Versioning; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; using Microsoft.Extensions.Time.Testing; using Moq; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Disk.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs index b1d90c47e14..d39b8a6515a 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskIoTimePerfCounterTests.cs @@ -2,12 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Runtime.InteropServices; using System.Runtime.Versioning; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; using Microsoft.Extensions.Time.Testing; using Moq; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Disk.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs index c04ddf32b76..aea99cf7610 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/Disk/WindowsDiskMetricsTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Diagnostics.Metrics; using System.Linq; +using System.Runtime.InteropServices; using System.Runtime.Versioning; using Microsoft.Extensions.Diagnostics.Metrics.Testing; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Helpers; @@ -14,7 +15,6 @@ using Microsoft.Shared.Instruments; using Moq; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Disk.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs index d7f5f5e97a9..64e9d87a5ac 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs @@ -2,9 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Runtime.InteropServices; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Interop; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs index ec652800283..17382e7eb22 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs @@ -2,9 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Runtime.InteropServices; using System.Runtime.Versioning; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs index 8388cde4aa7..fd7d6526dc1 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs @@ -2,9 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Runtime.InteropServices; using System.Runtime.Versioning; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs index a89b4d23945..f2f6e0e5e4f 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs @@ -2,9 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Runtime.InteropServices; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Interop; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs index 9edbce0be8f..e98b1311b0e 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs @@ -4,12 +4,12 @@ using System; using System.Diagnostics.Metrics; using System.Linq; +using System.Runtime.InteropServices; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Helpers; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Network; using Microsoft.Shared.Instruments; using Moq; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsSnapshotProviderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsSnapshotProviderTests.cs index 35f6bd61874..a93d515e7bb 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsSnapshotProviderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsSnapshotProviderTests.cs @@ -4,6 +4,7 @@ using System; using System.Diagnostics.Metrics; using System.Linq; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.Extensions.Diagnostics.Metrics.Testing; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test.Helpers; @@ -15,7 +16,6 @@ using Moq; using VerifyXunit; using Xunit; -using System.Runtime.InteropServices; namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Test; From 8a1169e25f487fbb490136844b48d1dc86ff503f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 3 Jul 2026 15:14:01 +0000 Subject: [PATCH 18/19] Fix S1128 (unnecessary using System) and FS0052 (struct copy in F# auto-generated entry point) --- .../Microsoft.Extensions.AI.Abstractions.FSharp.Tests.fsproj | 3 ++- .../ResourceMonitoringBuilderTests.cs | 1 - .../Windows/MemoryInfoTests.cs | 1 - .../Windows/PerformanceCounterFactoryTests.cs | 1 - .../Windows/PerformanceCounterWrapperTests.cs | 1 - .../Windows/SystemInfoTests.cs | 1 - .../Windows/WindowsNetworkMetricsTests.cs | 1 - 7 files changed, 2 insertions(+), 7 deletions(-) diff --git a/test/Libraries/Microsoft.Extensions.AI.Abstractions.FSharp.Tests/Microsoft.Extensions.AI.Abstractions.FSharp.Tests.fsproj b/test/Libraries/Microsoft.Extensions.AI.Abstractions.FSharp.Tests/Microsoft.Extensions.AI.Abstractions.FSharp.Tests.fsproj index dfaf0f0c5d9..408fbab4b2f 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Abstractions.FSharp.Tests/Microsoft.Extensions.AI.Abstractions.FSharp.Tests.fsproj +++ b/test/Libraries/Microsoft.Extensions.AI.Abstractions.FSharp.Tests/Microsoft.Extensions.AI.Abstractions.FSharp.Tests.fsproj @@ -7,7 +7,8 @@ true - $(NoWarn);FS3261 + + $(NoWarn);FS3261;FS0052 diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs index 3ad80704f05..5960bd74f8a 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceMonitoringBuilderTests.cs @@ -1,7 +1,6 @@ // 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.Linq; using System.Runtime.InteropServices; using Microsoft.Extensions.DependencyInjection; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs index 64e9d87a5ac..f8bca7bd500 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/MemoryInfoTests.cs @@ -1,7 +1,6 @@ // 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.Runtime.InteropServices; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Interop; using Xunit; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs index 17382e7eb22..3827563d16d 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterFactoryTests.cs @@ -1,7 +1,6 @@ // 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.Runtime.InteropServices; using System.Runtime.Versioning; using Xunit; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs index fd7d6526dc1..1ab159bc6bd 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/PerformanceCounterWrapperTests.cs @@ -1,7 +1,6 @@ // 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.Runtime.InteropServices; using System.Runtime.Versioning; using Xunit; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs index f2f6e0e5e4f..d006a7c4ea5 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/SystemInfoTests.cs @@ -1,7 +1,6 @@ // 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.Runtime.InteropServices; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Interop; using Xunit; diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs index e98b1311b0e..c2146cbecb4 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsNetworkMetricsTests.cs @@ -1,7 +1,6 @@ // 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.Diagnostics.Metrics; using System.Linq; using System.Runtime.InteropServices; From 99b16b80e268110c6867638159a32ebb8c2206e0 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Fri, 3 Jul 2026 18:31:02 +0200 Subject: [PATCH 19/19] Apply suggestions from code review Co-authored-by: Adam Sitnik --- .../Linux/AcceptanceTest.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs index d36f35d04af..1a3aaf4420b 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs @@ -6,7 +6,6 @@ using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Metrics; using System.IO; -using System.Linq; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks;