forked from microsoft/testfx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestCaseExtensions.cs
47 lines (41 loc) · 2.15 KB
/
TestCaseExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Extensions
{
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Constants = Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Constants;
/// <summary>
/// Extension Methods for TestCase Class
/// </summary>
internal static class TestCaseExtensions
{
/// <summary>
/// The to unit test element.
/// </summary>
/// <param name="testCase"> The test case. </param>
/// <param name="source"> The source. If deployed this is the full path of the source in the deployment directory. </param>
/// <returns> The converted <see cref="UnitTestElement"/>. </returns>
internal static UnitTestElement ToUnitTestElement(this TestCase testCase, string source)
{
var isAsync = (testCase.GetPropertyValue(Constants.AsyncTestProperty) as bool?) ?? false;
var testClassName = testCase.GetPropertyValue(Constants.TestClassNameProperty) as string;
var declaringClassName = testCase.GetPropertyValue(Constants.DeclaringClassNameProperty) as string;
var parts = testCase.FullyQualifiedName.Split('.');
var name = parts[parts.Length - 1];
TestMethod testMethod = new TestMethod(name, testClassName, source, isAsync);
if (declaringClassName != null && declaringClassName != testClassName)
{
testMethod.DeclaringClassFullName = declaringClassName;
}
UnitTestElement testElement = new UnitTestElement(testMethod)
{
IsAsync = isAsync,
TestCategory = testCase.GetPropertyValue(Constants.TestCategoryProperty) as string[],
Priority = testCase.GetPropertyValue(Constants.PriorityProperty) as int?,
DisplayName = testCase.DisplayName
};
return testElement;
}
}
}