diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Helpers/ReflectHelperTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Helpers/ReflectHelperTests.cs index 884e2d6c6b..c37d2d432a 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Helpers/ReflectHelperTests.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Helpers/ReflectHelperTests.cs @@ -69,12 +69,32 @@ public void GetTestCategoryAttributeShouldIncludeTestCategoriesAtClassLevel() [TestMethod] public void GetTestCategoryAttributeShouldIncludeTestCategoriesAtAllLevels() { - this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("AsmLevel") }, MemberTypes.All); + this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("AsmLevel1"), new UTF.TestCategoryAttribute("AsmLevel2") }, MemberTypes.All); + this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("AsmLevel3") }, MemberTypes.All); this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("ClassLevel") }, MemberTypes.TypeInfo); this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("MethodLevel") }, MemberTypes.Method); var actual = this.reflectHelper.GetCategories(this.method.Object).ToArray(); - string[] expected = new[] { "MethodLevel", "ClassLevel", "AsmLevel" }; + string[] expected = new[] { "MethodLevel", "ClassLevel", "AsmLevel1", "AsmLevel2", "AsmLevel3" }; + + CollectionAssert.AreEqual(expected, actual); + } + + /// + /// Testing test category attributes adorned at calss, assembly and method level are getting collected. + /// + [TestMethod] + public void GetTestCategoryAttributeShouldConcatCustomAttributeOfSameType() + { + this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("AsmLevel1") }, MemberTypes.All); + this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("AsmLevel2") }, MemberTypes.All); + this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("ClassLevel1") }, MemberTypes.TypeInfo); + this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("ClassLevel2") }, MemberTypes.TypeInfo); + this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("MethodLevel1") }, MemberTypes.Method); + this.reflectHelper.SetCustomAttribute(typeof(UTF.TestCategoryBaseAttribute), new[] { new UTF.TestCategoryAttribute("MethodLevel2") }, MemberTypes.Method); + + var actual = this.reflectHelper.GetCategories(this.method.Object).ToArray(); + string[] expected = new[] { "MethodLevel1", "MethodLevel2", "ClassLevel1", "ClassLevel2", "AsmLevel1", "AsmLevel2" }; CollectionAssert.AreEqual(expected, actual); } diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/TestableImplementations/TestableReflectHelper.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/TestableImplementations/TestableReflectHelper.cs index c09e9dba37..3f38b01e81 100644 --- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/TestableImplementations/TestableReflectHelper.cs +++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/TestableImplementations/TestableReflectHelper.cs @@ -33,7 +33,7 @@ public void SetCustomAttribute(Type type, Attribute[] values, MemberTypes member var hashcode = type.FullName.GetHashCode() + memberTypes.GetHashCode(); if (this.customAttributes.ContainsKey(hashcode)) { - this.customAttributes[hashcode].Concat(values); + this.customAttributes[hashcode] = this.customAttributes[hashcode].Concat(values).ToArray(); } else {