test & fix for assembly level attributes
MODIFY
src/NUnitTestAdapter/TraitsFeature.cs
src/NUnitTestAdapter/TraitsFeature.cs
@@ -97,20 +97,23 @@ namespace NUnit.VisualStudio.TestAdapter
private static void AddAttributesToCache(IDictionary<string, List<Trait>> propertiesCache, string key, string propertyName, string propertyValue)
{
- if (propertiesCache.ContainsKey(key) && !IsInternalProperty(propertyName, propertyValue))
+ if (propertiesCache.ContainsKey(key))
{
+ if(!IsInternalProperty(propertyName, propertyValue))
propertiesCache[key].Add(new Trait(propertyName, propertyValue));
+ return;
}
- else
- {
+
+
var traits = new List<Trait>();
+
+ // Will add empty list of traits, if the property is internal type. So that we will not make SelectNodes call again.
if (!IsInternalProperty(propertyName, propertyValue))
{
traits.Add(new Trait(propertyName, propertyValue));
}
propertiesCache[key] = traits;
}
- }
public static IEnumerable<NTrait> GetTraits(this TestCase testCase)
{

MODIFY
src/NUnitTestAdapterTests/Fakes/FakeTestData.cs
src/NUnitTestAdapterTests/Fakes/FakeTestData.cs
@@ -60,6 +60,7 @@ namespace NUnit.VisualStudio.TestAdapter.Tests.Fakes
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='Category' value='AsmCat' />
<property name='_PID' value='6164' />
<property name='_APPDOMAIN' value='domain-71b2ab93-nUnitClassLibrary.dll' />
</properties>

MODIFY
src/NUnitTestAdapterTests/TestConverterTests.cs
src/NUnitTestAdapterTests/TestConverterTests.cs
@@ -74,7 +74,6 @@ namespace NUnit.VisualStudio.TestAdapter.Tests
[Test]
public void CanMakeTestCaseShouldBuildTraitsCache()
{
- //System.Diagnostics.Debugger.Launch();
var xmlNodeList = FakeTestData.GetTestNodes();
foreach(XmlNode node in xmlNodeList)
@@ -95,8 +94,14 @@ namespace NUnit.VisualStudio.TestAdapter.Tests
// Will not be storing leaf nodes test-case nodes in the cache.
CheckNoTestCaseNodesExist(attributesCache);
+ // Checking assembly level attribute.
+ CheckNodeProperties(attributesCache, "0-1009", new KeyValuePair<string, string>[] { new KeyValuePair<string, string>("Category", "AsmCat") });
+
+ // Checking Class level attributes base class & dervied class
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") });
+
+ // Checking Nested class attributes.
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") });
@@ -157,7 +162,6 @@ namespace NUnit.VisualStudio.TestAdapter.Tests
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));
}

test & fix for assembly level attributes