< Summary

Class:Azure.Core.TestFramework.PlaybackOnlyAttribute
Assembly:Azure.Core.TestFramework
File(s):C:\Git\azure-sdk-for-net\sdk\core\Azure.Core.TestFramework\src\PlaybackOnlyAttribute.cs
Covered lines:8
Uncovered lines:2
Coverable lines:10
Total lines:46
Line coverage:80% (8 of 10)
Covered branches:3
Total branches:4
Branch coverage:75% (3 of 4)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
ApplyToTest(...)-71.43%75%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using NUnit.Framework;
 6using NUnit.Framework.Interfaces;
 7using NUnit.Framework.Internal;
 8
 9namespace Azure.Core.TestFramework
 10{
 11    /// <summary>
 12    /// Attribute on test assemblies, classes, or methods that run only against playback resources.
 13    /// </summary>
 14    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true, 
 15    public class PlaybackOnlyAttribute : NUnitAttribute, IApplyToTest
 16    {
 17        private readonly string _reason;
 18
 19        /// <summary>
 20        /// Constructs the attribute giving a reason the associated tests is playback only.
 21        /// </summary>
 24822        public PlaybackOnlyAttribute(string reason)
 23        {
 24824            _reason = reason;
 24825        }
 26
 27        /// <summary>
 28        /// Modifies the <paramref name="test"/> by adding categories to it and changing the run state as needed.
 29        /// </summary>
 30        /// <param name="test">The <see cref="Test"/> to modify.</param>
 31        public void ApplyToTest(Test test)
 32        {
 24833            test.Properties.Add("Category", "Playback");
 34
 24835            if (test.RunState != RunState.NotRunnable)
 36            {
 24837                RecordedTestMode mode = RecordedTestUtilities.GetModeFromEnvironment();
 24838                if (mode != RecordedTestMode.Playback)
 39                {
 040                    test.RunState = RunState.Ignored;
 041                    test.Properties.Set("_SKIPREASON", $"Playback tests will not run when AZURE_TEST_MODE is {mode}.  Th
 42                }
 43            }
 24844        }
 45    }
 46}

Methods/Properties

.ctor(...)
ApplyToTest(...)