< Summary

Class:Azure.Core.TestFramework.RunOnlyOnPlatformsAttribute
Assembly:Azure.Core.TestFramework
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core.TestFramework\src\RunOnlyOnPlatformsAttribute.cs
Covered lines:7
Uncovered lines:3
Coverable lines:10
Total lines:35
Line coverage:70% (7 of 10)
Covered branches:9
Total branches:14
Branch coverage:64.2% (9 of 14)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Linux()-0%100%
get_OSX()-100%100%
get_Windows()-100%100%
ApplyToTest(...)-50%75%
CanRunOnPlatform()-100%60%

File(s)

C:\Git\azure-sdk-for-net\sdk\core\Azure.Core.TestFramework\src\RunOnlyOnPlatformsAttribute.cs

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