From bcc0324da68fbd26766bf8e285d62595e759d4ff Mon Sep 17 00:00:00 2001 From: Ivan Duplenskikh <115665590+ivanduplenskikh@users.noreply.github.com> Date: Tue, 20 Feb 2024 19:36:03 +0100 Subject: [PATCH] Fix unit test file names in the TestLogs directory (#4649) --- src/Test/L0/TestHostContext.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Test/L0/TestHostContext.cs b/src/Test/L0/TestHostContext.cs index dbea7f40a0..8408dfa762 100644 --- a/src/Test/L0/TestHostContext.cs +++ b/src/Test/L0/TestHostContext.cs @@ -50,14 +50,21 @@ public TestHostContext(object testClass, [CallerMemberName] string testName = "" _testName = testName; // Trim the test assembly's root namespace from the test class's full name. - _suiteName = testClass.GetType().FullName.Substring( - startIndex: typeof(Tests.TestHostContext).FullName.LastIndexOf(nameof(TestHostContext))); - _suiteName = _suiteName.Replace(".", "_"); + _suiteName = testClass.GetType().FullName.Replace( + typeof(TestHostContext).Namespace, + string.Empty, + StringComparison.OrdinalIgnoreCase); + + if (_suiteName.StartsWith(".")) + { + _suiteName = _suiteName[1..]; + } + + _suiteName = _suiteName.Replace(".", "_", StringComparison.OrdinalIgnoreCase); // Setup the trace manager. - TraceFileName = Path.Combine( - Path.Combine(TestUtil.GetSrcPath(), "Test", "TestLogs"), - $"trace_{_suiteName}_{_testName}.log"); + TraceFileName = Path.Combine(TestUtil.GetSrcPath(), "Test", "TestLogs", $"trace_{_suiteName}_{_testName}.log"); + if (File.Exists(TraceFileName)) { File.Delete(TraceFileName);