| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Linq; |
| | 6 | | using System.Runtime.InteropServices; |
| | 7 | | using NUnit.Framework; |
| | 8 | | using NUnit.Framework.Interfaces; |
| | 9 | | using NUnit.Framework.Internal; |
| | 10 | | using OSPlatform = System.Runtime.InteropServices.OSPlatform; |
| | 11 | |
|
| | 12 | | namespace Azure.Core.TestFramework |
| | 13 | | { |
| | 14 | | [AttributeUsage(AttributeTargets.Method|AttributeTargets.Class|AttributeTargets.Assembly, AllowMultiple = false, Inh |
| | 15 | | public class RunOnlyOnPlatformsAttribute : NUnitAttribute, IApplyToTest |
| | 16 | | { |
| 0 | 17 | | public bool Linux { get; set; } |
| 40 | 18 | | public bool OSX { get; set; } |
| 48 | 19 | | public bool Windows { get; set; } |
| | 20 | |
|
| | 21 | | public void ApplyToTest(Test test) |
| | 22 | | { |
| 24 | 23 | | if (test.RunState != RunState.NotRunnable && !CanRunOnPlatform()) |
| | 24 | | { |
| 0 | 25 | | test.RunState = RunState.Ignored; |
| 0 | 26 | | test.Properties.Set(PropertyNames.SkipReason, $"This test can't' run on {RuntimeInformation.OSDescriptio |
| | 27 | | } |
| 24 | 28 | | } |
| | 29 | |
|
| | 30 | | private bool CanRunOnPlatform() => |
| 24 | 31 | | Linux && RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || |
| 24 | 32 | | OSX && RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || |
| 24 | 33 | | Windows && RuntimeInformation.IsOSPlatform(OSPlatform.Windows); |
| | 34 | | } |
| | 35 | | } |