Skip to content

Commit

Permalink
Fixed Explicit trait caching bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jnm2 committed Mar 3, 2018
1 parent 0e777b5 commit 39744b3
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/NUnitTestAdapter/CategoryList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> categorylist = new List<string>();
private readonly TestCase testCase;

Expand Down Expand Up @@ -48,20 +54,14 @@ public IEnumerable<string> 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);
}
}

Expand All @@ -70,6 +70,13 @@ public IEnumerable<string> 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);
}
Expand Down

0 comments on commit 39744b3

Please sign in to comment.