| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using NUnit.Framework; |
| | | 6 | | using NUnit.Framework.Interfaces; |
| | | 7 | | using NUnit.Framework.Internal; |
| | | 8 | | |
| | | 9 | | namespace 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> |
| | 248 | 22 | | public PlaybackOnlyAttribute(string reason) |
| | | 23 | | { |
| | 248 | 24 | | _reason = reason; |
| | 248 | 25 | | } |
| | | 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 | | { |
| | 248 | 33 | | test.Properties.Add("Category", "Playback"); |
| | | 34 | | |
| | 248 | 35 | | if (test.RunState != RunState.NotRunnable) |
| | | 36 | | { |
| | 248 | 37 | | RecordedTestMode mode = RecordedTestUtilities.GetModeFromEnvironment(); |
| | 248 | 38 | | if (mode != RecordedTestMode.Playback) |
| | | 39 | | { |
| | 0 | 40 | | test.RunState = RunState.Ignored; |
| | 0 | 41 | | test.Properties.Set("_SKIPREASON", $"Playback tests will not run when AZURE_TEST_MODE is {mode}. Th |
| | | 42 | | } |
| | | 43 | | } |
| | 248 | 44 | | } |
| | | 45 | | } |
| | | 46 | | } |