| | 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 live resources. |
| | 13 | | /// </summary> |
| | 14 | | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true, |
| | 15 | | public class LiveOnlyAttribute : NUnitAttribute, IApplyToTest |
| | 16 | | { |
| | 17 | | /// <summary> |
| | 18 | | /// Modifies the <paramref name="test"/> by adding categories to it and changing the run state as needed. |
| | 19 | | /// </summary> |
| | 20 | | /// <param name="test">The <see cref="Test"/> to modify.</param> |
| | 21 | | public void ApplyToTest(Test test) |
| | 22 | | { |
| 580 | 23 | | test.Properties.Add("Category", "Live"); |
| | 24 | |
|
| 580 | 25 | | if (test.RunState != RunState.NotRunnable) |
| | 26 | | { |
| 580 | 27 | | RecordedTestMode mode = RecordedTestUtilities.GetModeFromEnvironment(); |
| 580 | 28 | | if (mode != RecordedTestMode.Live) |
| | 29 | | { |
| 580 | 30 | | test.RunState = RunState.Ignored; |
| 580 | 31 | | test.Properties.Set("_SKIPREASON", $"Live tests will not run when AZURE_TEST_MODE is {mode}"); |
| | 32 | | } |
| | 33 | | } |
| 580 | 34 | | } |
| | 35 | | } |
| | 36 | | } |