ConditionalIgnoreAttribute.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections.Generic;
  2. using NUnit.Framework;
  3. using NUnit.Framework.Interfaces;
  4. using NUnit.Framework.Internal;
  5. namespace UnityEngine.TestTools
  6. {
  7. public class ConditionalIgnoreAttribute : NUnitAttribute, IApplyToTest
  8. {
  9. string m_ConditionKey;
  10. string m_IgnoreReason;
  11. public ConditionalIgnoreAttribute(string conditionKey, string ignoreReason)
  12. {
  13. m_ConditionKey = conditionKey;
  14. m_IgnoreReason = ignoreReason;
  15. }
  16. public void ApplyToTest(Test test)
  17. {
  18. var key = m_ConditionKey.ToLowerInvariant();
  19. if (m_ConditionMap.ContainsKey(key) && m_ConditionMap[key])
  20. {
  21. test.RunState = RunState.Ignored;
  22. string skipReason = string.Format(m_IgnoreReason);
  23. test.Properties.Add(PropertyNames.SkipReason, skipReason);
  24. }
  25. }
  26. static Dictionary<string, bool> m_ConditionMap = new Dictionary<string, bool>();
  27. public static void AddConditionalIgnoreMapping(string key, bool value)
  28. {
  29. m_ConditionMap.Add(key.ToLowerInvariant(), value);
  30. }
  31. }
  32. }