Added one more test to cover the diverse XML.
MODIFY
src/NUnitTestAdapterTests/Fakes/FakeTestData.cs
src/NUnitTestAdapterTests/Fakes/FakeTestData.cs
@@ -34,7 +34,7 @@ namespace NUnit.VisualStudio.TestAdapter.Tests.Fakes
{
// ReSharper disable once UnusedMember.Local
private static void FakeTestCase() { } // LineNumber should be this line
-
+ #region TestXmls
public const string TestXml =
@"<test-suite
id='121'
@@ -57,6 +57,64 @@ namespace NUnit.VisualStudio.TestAdapter.Tests.Fakes
</test-case>
</test-suite>";
+ public const string TestXml2 = @"<test-run id='2' name='nUnitClassLibrary.dll' fullname='C:\Users\navb\source\repos\nUnitClassLibrary\nUnitClassLibrary\bin\Debug\nUnitClassLibrary.dll' testcasecount='5'>
+ <test-suite type='Assembly' id='0-1009' name='nUnitClassLibrary.dll' fullname='C:\Users\navb\source\repos\nUnitClassLibrary\nUnitClassLibrary\bin\Debug\nUnitClassLibrary.dll' runstate='Runnable' testcasecount='5'>
+ <properties>
+ <property name='_PID' value='6164' />
+ <property name='_APPDOMAIN' value='domain-71b2ab93-nUnitClassLibrary.dll' />
+ </properties>
+ <test-suite type='TestSuite' id='0-1010' name='nUnitClassLibrary' fullname='nUnitClassLibrary' runstate='Runnable' testcasecount='5'>
+ <test-suite type='TestFixture' id='0-1000' name='Class1' fullname='nUnitClassLibrary.Class1' classname='nUnitClassLibrary.Class1' runstate='Runnable' testcasecount='1'>
+ <properties>
+ <property name='Category' value='BaseClass' />
+ </properties>
+ <test-case id='0-1001' name='nUnitTest' fullname='nUnitClassLibrary.Class1.nUnitTest' methodname='nUnitTest' classname='nUnitClassLibrary.Class1' runstate='Runnable' seed='113395783'>
+ <properties>
+ <property name='Category' value='Base' />
+ </properties>
+ </test-case>
+ </test-suite>
+ <test-suite type='TestFixture' id='0-1002' name='ClassD' fullname='nUnitClassLibrary.ClassD' classname='nUnitClassLibrary.ClassD' runstate='Runnable' testcasecount='2'>
+ <properties>
+ <property name='Category' value='DerivedClass' />
+ <property name='Category' value='BaseClass' />
+ </properties>
+ <test-case id='0-1003' name='dNunitTest' fullname='nUnitClassLibrary.ClassD.dNunitTest' methodname='dNunitTest' classname='nUnitClassLibrary.ClassD' runstate='Runnable' seed='405714082'>
+ <properties>
+ <property name='Category' value='Derived' />
+ </properties>
+ </test-case>
+ <test-case id='0-1004' name='nUnitTest' fullname='nUnitClassLibrary.ClassD.nUnitTest' methodname='nUnitTest' classname='nUnitClassLibrary.Class1' runstate='Runnable' seed='1553985978'>
+ <properties>
+ <property name='Category' value='Base' />
+ </properties>
+ </test-case>
+ </test-suite>
+ <test-suite type='TestFixture' id='0-1005' name='NestedClasses' fullname='nUnitClassLibrary.NestedClasses' classname='nUnitClassLibrary.NestedClasses' runstate='Runnable' testcasecount='1'>
+ <properties>
+ <property name='Category' value='NS1' />
+ </properties>
+ <test-case id='0-1006' name='NC11' fullname='nUnitClassLibrary.NestedClasses.NC11' methodname='NC11' classname='nUnitClassLibrary.NestedClasses' runstate='Runnable' seed='1107340752'>
+ <properties>
+ <property name='Category' value='NS11' />
+ </properties>
+ </test-case>
+ </test-suite>
+ <test-suite type='TestFixture' id='0-1007' name='NestedClasses+NestedClass2' fullname='nUnitClassLibrary.NestedClasses+NestedClass2' classname='nUnitClassLibrary.NestedClasses+NestedClass2' runstate='Runnable' testcasecount='1'>
+ <properties>
+ <property name='Category' value='NS2' />
+ </properties>
+ <test-case id='0-1008' name='NC21' fullname='nUnitClassLibrary.NestedClasses+NestedClass2.NC21' methodname='NC21' classname='nUnitClassLibrary.NestedClasses+NestedClass2' runstate='Runnable' seed='1823789309'>
+ <properties>
+ <property name='Category' value='NS21' />
+ </properties>
+ </test-case>
+ </test-suite>
+ </test-suite>
+ </test-suite>
+</test-run>";
+ #endregion
+
public const string ResultXml =
@"<test-suite
id='121'
@@ -105,6 +163,11 @@ namespace NUnit.VisualStudio.TestAdapter.Tests.Fakes
return XmlHelper.CreateXmlNode(TestXml).SelectSingleNode("test-case");
}
+ public static XmlNodeList GetTestNodes()
+ {
+ return XmlHelper.CreateXmlNode(TestXml2).SelectNodes("//test-case");
+ }
+
public static XmlNode GetResultNode()
{
return XmlHelper.CreateXmlNode(ResultXml).SelectSingleNode("test-case");

MODIFY
src/NUnitTestAdapterTests/TestConverterTests.cs
src/NUnitTestAdapterTests/TestConverterTests.cs
// ***********************************************************************
using System;
+using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -70,6 +71,37 @@ namespace NUnit.VisualStudio.TestAdapter.Tests
Assert.That(parentTrait[0].Value, Is.EqualTo("super"));
}
+ [Test]
+ public void CanMakeTestCaseShouldBuildTraitsCache()
+ {
+ //System.Diagnostics.Debugger.Launch();
+ var xmlNodeList = FakeTestData.GetTestNodes();
+
+ foreach(XmlNode node in xmlNodeList)
+ {
+ var testCase = testConverter.ConvertTestCase(node);
+ }
+
+ var attributesCache = testConverter.AttributesCache;
+
+ // There are 12 ids in the TestXml2, but will be storing only ancestor properties.
+ // Not the leaf node test-case properties.
+ Assert.That(attributesCache.Keys.Count, Is.EqualTo(7));
+
+ // Even though ancestor doesn't have any properties. Will be storing their ids.
+ // So that we will not make call SelectNodes call again.
+ CheckNodesWithNoProperties(attributesCache);
+
+ // Will not be storing leaf nodes test-case nodes in the cache.
+ CheckNoTestCaseNodesExist(attributesCache);
+
+ CheckNodeProperties(attributesCache, "0-1000", new KeyValuePair<string,string>[] { new KeyValuePair<string, string>("Category", "BaseClass") });
+ CheckNodeProperties(attributesCache, "0-1002", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>("Category", "DerivedClass"), new KeyValuePair<string, string>("Category", "BaseClass") });
+ CheckNodeProperties(attributesCache, "0-1005", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>("Category", "NS1") });
+ CheckNodeProperties(attributesCache, "0-1007", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>("Category", "NS2") });
+
+ }
+
[Test]
public void ConvertedTestCaseIsCached()
{
@@ -121,5 +153,33 @@ namespace NUnit.VisualStudio.TestAdapter.Tests
var traitList = testCase.GetTraits().Select(trait => trait.Name + ":" + trait.Value).ToList();
Assert.That(traitList, Is.EquivalentTo(new[] { "Category:super", "Category:cat1", "Priority:medium" }));
}
+
+ private void CheckNodesWithNoProperties(IDictionary<string, List<Trait>> attributesCache)
+ {
+ Assert.That(attributesCache["2"].Count, Is.EqualTo(0));
+ Assert.That(attributesCache["0-1009"].Count, Is.EqualTo(0));
+ Assert.That(attributesCache["0-1010"].Count, Is.EqualTo(0));
+ }
+
+ private void CheckNoTestCaseNodesExist(IDictionary<string, List<Trait>> attributesCache)
+ {
+ Assert.That(!attributesCache.ContainsKey("0-1008"));
+ Assert.That(!attributesCache.ContainsKey("0-1006"));
+ Assert.That(!attributesCache.ContainsKey("0-1004"));
+ Assert.That(!attributesCache.ContainsKey("0-1003"));
+ Assert.That(!attributesCache.ContainsKey("0-1001"));
+ }
+
+ private void CheckNodeProperties(IDictionary<string, List<Trait>> attributesCache, string id, KeyValuePair<string,string>[] kps)
+ {
+ Assert.That(attributesCache.ContainsKey(id));
+ Assert.That(attributesCache[id].Count, Is.EqualTo(kps.Count()));
+ var traits = attributesCache[id];
+
+ foreach(var kp in kps)
+ {
+ Assert.That(traits.Any(t => t.Name == kp.Key && t.Value == kp.Value));
+ }
+ }
}
}

Added one more test to cover the diverse XML.