From 39744b3e722c9845efff34f80652ecd8f73eaee9 Mon Sep 17 00:00:00 2001 From: jnm2 Date: Fri, 2 Mar 2018 19:03:30 -0500 Subject: [PATCH] Fixed Explicit trait caching bug --- src/NUnitTestAdapter/CategoryList.cs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/NUnitTestAdapter/CategoryList.cs b/src/NUnitTestAdapter/CategoryList.cs index 83b72ef7..1ceae098 100644 --- a/src/NUnitTestAdapter/CategoryList.cs +++ b/src/NUnitTestAdapter/CategoryList.cs @@ -13,6 +13,12 @@ public class CategoryList private const string VsTestCategoryLabel = "TestCategory"; internal static readonly TestProperty NUnitTestCategoryProperty = TestProperty.Register(NUnitCategoryName, VsTestCategoryLabel, typeof(string[]), TestPropertyAttributes.Hidden | TestPropertyAttributes.Trait, typeof(TestCase)); + private const string ExplicitTraitName = "Explicit"; + // The empty string causes the UI we want. + // If it's null, the explicit trait doesn't show up in Test Explorer. + // If it's not empty, it shows up as “Explicit [value]” in Test Explorer. + private const string ExplicitTraitValue = ""; + private readonly List categorylist = new List(); private readonly TestCase testCase; @@ -48,20 +54,14 @@ public IEnumerable ProcessTestCaseProperties(XmlNode testNode, bool addT } } - const string explicitTraitName = "Explicit"; - // The empty string causes the UI we want. - // If it's null, the explicit trait doesn't show up in Test Explorer. - // If it's not empty, it shows up as “Explicit [value]” in Test Explorer. - const string explicitTraitValue = ""; - if (testNode.Attributes?["runstate"]?.Value == "Explicit") { - if (!testCase.Traits.Any(trait => trait.Name == explicitTraitName)) + if (!testCase.Traits.Any(trait => trait.Name == ExplicitTraitName)) { - testCase.Traits.Add(new Trait(explicitTraitName, explicitTraitValue)); + testCase.Traits.Add(new Trait(ExplicitTraitName, ExplicitTraitValue)); if (addToCache) - AddTraitsToCache(traitsCache, key, explicitTraitName, explicitTraitValue); + AddTraitsToCache(traitsCache, key, ExplicitTraitName, ExplicitTraitValue); } } @@ -70,6 +70,13 @@ public IEnumerable ProcessTestCaseProperties(XmlNode testNode, bool addT private static bool IsInternalProperty(string propertyName, string propertyValue) { + if (propertyName == ExplicitTraitName) + { + // Otherwise the IsNullOrEmpty check does the wrong thing, + // but I'm not sure of the consequences of allowing all empty strings. + return false; + } + // Property names starting with '_' are for internal use only return String.IsNullOrEmpty(propertyName) || propertyName[0] == '_' || String.IsNullOrEmpty(propertyValue); }