From 53f51342f8d7158adcc6ce0e490cf5a42cba9f72 Mon Sep 17 00:00:00 2001 From: Sean McCullough Date: Tue, 9 Jun 2020 13:45:20 -0500 Subject: [PATCH 1/2] Added PlaybackOnlyAttribute --- .../src/PlaybackOnlyAttribute.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 sdk/core/Azure.Core.TestFramework/src/PlaybackOnlyAttribute.cs diff --git a/sdk/core/Azure.Core.TestFramework/src/PlaybackOnlyAttribute.cs b/sdk/core/Azure.Core.TestFramework/src/PlaybackOnlyAttribute.cs new file mode 100644 index 000000000000..7c11b8215814 --- /dev/null +++ b/sdk/core/Azure.Core.TestFramework/src/PlaybackOnlyAttribute.cs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using NUnit.Framework; +using NUnit.Framework.Interfaces; +using NUnit.Framework.Internal; + +namespace Azure.Core.TestFramework +{ + /// + /// Attribute on test assemblies, classes, or methods that run only against playback resources. + /// + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true, Inherited = true)] + public class PlaybackOnlyAttribute : NUnitAttribute, IApplyToTest + { + /// + /// Modifies the by adding categories to it and changing the run state as needed. + /// + /// The to modify. + public void ApplyToTest(Test test) + { + test.Properties.Add("Category", "Playback"); + + if (test.RunState != RunState.NotRunnable) + { + RecordedTestMode mode = RecordedTestUtilities.GetModeFromEnvironment(); + if (mode != RecordedTestMode.Playback) + { + test.RunState = RunState.Ignored; + test.Properties.Set("_SKIPREASON", $"Live tests will not run when AZURE_TEST_MODE is {mode}"); + } + } + } + } +} From 76d887ed4ea34b74c2cef1216ef42b235529abe7 Mon Sep 17 00:00:00 2001 From: Sean McCullough Date: Thu, 18 Jun 2020 13:33:28 -0500 Subject: [PATCH 2/2] PR comments --- .../src/PlaybackOnlyAttribute.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sdk/core/Azure.Core.TestFramework/src/PlaybackOnlyAttribute.cs b/sdk/core/Azure.Core.TestFramework/src/PlaybackOnlyAttribute.cs index 7c11b8215814..706390608816 100644 --- a/sdk/core/Azure.Core.TestFramework/src/PlaybackOnlyAttribute.cs +++ b/sdk/core/Azure.Core.TestFramework/src/PlaybackOnlyAttribute.cs @@ -14,6 +14,16 @@ namespace Azure.Core.TestFramework [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true, Inherited = true)] public class PlaybackOnlyAttribute : NUnitAttribute, IApplyToTest { + private readonly string _reason; + + /// + /// Constructs the attribute giving a reason the associated tests is playback only. + /// + public PlaybackOnlyAttribute(string reason) + { + _reason = reason; + } + /// /// Modifies the by adding categories to it and changing the run state as needed. /// @@ -28,7 +38,7 @@ public void ApplyToTest(Test test) if (mode != RecordedTestMode.Playback) { test.RunState = RunState.Ignored; - test.Properties.Set("_SKIPREASON", $"Live tests will not run when AZURE_TEST_MODE is {mode}"); + test.Properties.Set("_SKIPREASON", $"Playback tests will not run when AZURE_TEST_MODE is {mode}. This test was skipped for the following reason: {_reason}"); } } }