in src/Adapter/MSTest.CoreAdapter/ObjectModel/UnitTestElement.cs [125:253]
internal TestCase ToTestCase()
{
// This causes compatibility problems with older runners.
// string fullName = this.TestMethod.HasManagedMethodAndTypeProperties
// ? string.Format(CultureInfo.InvariantCulture, "{0}.{1}", this.TestMethod.ManagedTypeName, this.TestMethod.ManagedMethodName)
// : string.Format(CultureInfo.InvariantCulture, "{0}.{1}", this.TestMethod.FullClassName, this.TestMethod.Name);
var fullName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", this.TestMethod.FullClassName, this.TestMethod.Name);
TestCase testCase = new TestCase(fullName, TestAdapter.Constants.ExecutorUri, this.TestMethod.AssemblyName);
testCase.DisplayName = this.GetDisplayName();
if (this.TestMethod.HasManagedMethodAndTypeProperties)
{
testCase.SetPropertyValue(TestCaseExtensions.ManagedTypeProperty, this.TestMethod.ManagedTypeName);
testCase.SetPropertyValue(TestCaseExtensions.ManagedMethodProperty, this.TestMethod.ManagedMethodName);
testCase.SetPropertyValue(TestAdapter.Constants.TestClassNameProperty, this.TestMethod.ManagedTypeName);
}
else
{
testCase.SetPropertyValue(TestAdapter.Constants.TestClassNameProperty, this.TestMethod.FullClassName);
}
var hierarchy = this.TestMethod.Hierarchy;
if (hierarchy != null && hierarchy.Count > 0)
{
testCase.SetHierarchy(hierarchy.ToArray());
}
// Set declaring type if present so the correct method info can be retrieved
if (this.TestMethod.DeclaringClassFullName != null)
{
testCase.SetPropertyValue(TestAdapter.Constants.DeclaringClassNameProperty, this.TestMethod.DeclaringClassFullName);
}
// Many of the tests will not be async, so there is no point in sending extra data
if (this.IsAsync)
{
testCase.SetPropertyValue(TestAdapter.Constants.AsyncTestProperty, this.IsAsync);
}
// Set only if some test category is present
if (this.TestCategory != null && this.TestCategory.Length > 0)
{
testCase.SetPropertyValue(TestAdapter.Constants.TestCategoryProperty, this.TestCategory);
}
// Set priority if present
if (this.Priority != null)
{
testCase.SetPropertyValue(TestAdapter.Constants.PriorityProperty, this.Priority.Value);
}
if (this.Traits != null)
{
testCase.Traits.AddRange(this.Traits);
}
if (!string.IsNullOrEmpty(this.CssIteration))
{
testCase.SetPropertyValue(TestAdapter.Constants.CssIterationProperty, this.CssIteration);
}
if (!string.IsNullOrEmpty(this.CssProjectStructure))
{
testCase.SetPropertyValue(TestAdapter.Constants.CssProjectStructureProperty, this.CssProjectStructure);
}
if (!string.IsNullOrEmpty(this.Description))
{
testCase.SetPropertyValue(TestAdapter.Constants.DescriptionProperty, this.Description);
}
if (this.WorkItemIds != null)
{
testCase.SetPropertyValue(TestAdapter.Constants.WorkItemIdsProperty, this.WorkItemIds);
}
// The list of items to deploy before running this test.
if (this.DeploymentItems != null && this.DeploymentItems.Length > 0)
{
testCase.SetPropertyValue(TestAdapter.Constants.DeploymentItemsProperty, this.DeploymentItems);
}
// Set the Do not parallelize state if present
if (this.DoNotParallelize)
{
testCase.SetPropertyValue(TestAdapter.Constants.DoNotParallelizeProperty, this.DoNotParallelize);
}
// Store resolved data if any
if (this.TestMethod.DataType != DynamicDataType.None)
{
var data = this.TestMethod.SerializedData;
testCase.SetPropertyValue(TestAdapter.Constants.TestDynamicDataTypeProperty, (int)this.TestMethod.DataType);
testCase.SetPropertyValue(TestAdapter.Constants.TestDynamicDataProperty, data);
}
string fileName = testCase.Source;
try
{
fileName = Path.GetFileName(fileName);
}
catch
{
}
var idProvider = new TestIdProvider();
idProvider.AppendString(testCase.ExecutorUri?.ToString());
idProvider.AppendString(fileName);
if (this.TestMethod.HasManagedMethodAndTypeProperties)
{
idProvider.AppendString(this.TestMethod.ManagedTypeName);
idProvider.AppendString(this.TestMethod.ManagedMethodName);
}
else
{
idProvider.AppendString(testCase.FullyQualifiedName);
}
if (this.TestMethod.DataType != DynamicDataType.None)
{
idProvider.AppendString(testCase.DisplayName);
}
testCase.Id = idProvider.GetId();
return testCase;
}