Skip to content

Commit

Permalink
Merge pull request #50 from AArnott/documentClassUseCase
Browse files Browse the repository at this point in the history
Document support for class-level OS targeting
  • Loading branch information
AArnott authored Dec 2, 2024
2 parents 47a3a8b + 84af6cf commit 4131590
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docfx/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ your library is not expected to be implemented in some of them. For example:

### Supported platforms

Apply the @System.Runtime.Versioning.SupportedOSPlatformAttribute and/or @System.Runtime.Versioning.UnsupportedOSPlatformAttribute to a test method to skip it based on the platform the test is running on.
Apply the @System.Runtime.Versioning.SupportedOSPlatformAttribute and/or @System.Runtime.Versioning.UnsupportedOSPlatformAttribute to a test method or test class to skip it based on the platform the test is running on.

[!code-csharp[](../../samples/GettingStarted.cs#OSCheck)]

Expand Down
23 changes: 18 additions & 5 deletions samples/GettingStarted.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Andrew Arnott. All rights reserved.
// Licensed under the Microsoft Public License (Ms-PL). See LICENSE.txt file in the project root for full license information.

using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using Xunit;
Expand All @@ -26,11 +25,25 @@ public void TestFunctionalityWhichIsNotSupportedOnSomePlatforms()
#endregion

#region OSCheck
[SkippableFact, SupportedOSPlatform("Windows")]
public void TestCngKey()
public class AnyTestClass
{
var key = CngKey.Create(CngAlgorithm.Rsa);
Assert.NotNull(key);
[SkippableFact]
[SupportedOSPlatform("Windows")]
public void TestCngKey()
{
var key = CngKey.Create(CngAlgorithm.Rsa);
Assert.NotNull(key);
}
}

[SupportedOSPlatform("Windows")]
public class WindowsOnlyTestClass
{
[SkippableFact]
public void SomeTest()
{
// This test will only run on Windows.
}
}
#endregion
}

0 comments on commit 4131590

Please sign in to comment.