From 7abb442add97b87e5b2a0b971041f87ab1a188c3 Mon Sep 17 00:00:00 2001 From: Sarabjot Singh Date: Fri, 10 May 2019 14:37:16 +0530 Subject: [PATCH] Fix for the trx classname being wrongly stamped when testname and fullqualifiedname are same. --- .../Utility/Converter.cs | 2 +- .../Utility/ConverterTests.cs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/Converter.cs b/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/Converter.cs index 217352bdd2..4a5f998554 100644 --- a/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/Converter.cs +++ b/src/Microsoft.TestPlatform.Extensions.TrxLogger/Utility/Converter.cs @@ -606,7 +606,7 @@ private static string GetTestClassName(string testName, string fullyQualifiedNam // In case, fullyQualifiedName ends with testName, className is checked within remaining value of fullyQualifiedName. // Example: In case, testName = TestMethod1(2, 3, 4.0d) and fullyQualifiedName = TestProject1.Class1.TestMethod1(2, 3, 4.0d), className will be checked within 'TestProject1.Class1.' only - var nameToCheck = fullyQualifiedName.EndsWith(testName) ? + var nameToCheck = !fullyQualifiedName.Equals(testName, StringComparison.OrdinalIgnoreCase) && fullyQualifiedName.EndsWith(testName) ? fullyQualifiedName.Substring(0, fullyQualifiedName.Length - testName.Length) : fullyQualifiedName; diff --git a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/ConverterTests.cs b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/ConverterTests.cs index 8d4adca18a..b4ce48f197 100644 --- a/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/ConverterTests.cs +++ b/test/Microsoft.TestPlatform.Extensions.TrxLogger.UnitTests/Utility/ConverterTests.cs @@ -99,6 +99,16 @@ public void ToTestElementShouldNotFailWhenThereIsNoTestCategoreis() CollectionAssert.AreEqual(expected, unitTestElement.TestCategories.ToArray()); } + [TestMethod] + public void ToTestElementShouldContainExpectedTestMethodPropertiesIfFqnIsSameAsTestName() + { + var expectedClassName = "TestProject1.Class1"; + var fullyQualifiedName = expectedClassName + "." + "TestMethod1"; + var testName = "TestProject1.Class1.TestMethod1"; + + ValidateTestMethodProperties(testName, fullyQualifiedName, expectedClassName); + } + [TestMethod] public void ToTestElementShouldContainExpectedTestMethodPropertiesIfFqnEndsWithTestName() {