Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Adapter/MSTest.CoreAdapter/Discovery/TypeEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ internal UnitTestElement GetTestFromMethod(MethodInfo method, bool isDeclaredInT
testElement.Description = descriptionAttribute.Description;
}

var workItemAttributeArray = this.reflectHelper.GetCustomAttributes(method, typeof(WorkItemAttribute)) as WorkItemAttribute[];
if (workItemAttributeArray != null)
var workItemAttributes = this.reflectHelper.GetCustomAttributes(method, typeof(WorkItemAttribute)).Cast<WorkItemAttribute>().ToArray();
if (workItemAttributes.Any())
{
testElement.WorkItemIds = workItemAttributeArray.Select(x => x.Id.ToString()).ToArray();
testElement.WorkItemIds = workItemAttributes.Select(x => x.Id.ToString()).ToArray();
}

// Get Deployment items if any.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,26 @@ public void GetTestFromMethodShouldSetWorkItemIds()
this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
var methodInfo = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");
this.mockReflectHelper.Setup(rh => rh.GetCustomAttributes(methodInfo, typeof(UTF.WorkItemAttribute))).Returns(new UTF.WorkItemAttribute[] { new UTF.WorkItemAttribute(123), new UTF.WorkItemAttribute(345) });
this.mockReflectHelper.Setup(rh => rh.GetCustomAttributes(methodInfo, typeof(UTF.WorkItemAttribute))).Returns(new Attribute[] { new UTF.WorkItemAttribute(123), new UTF.WorkItemAttribute(345) });

var testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, this.warnings);

CollectionAssert.AreEqual(new string[] { "123", "345" }, testElement.WorkItemIds);
}

[TestMethod]
public void GetTestFromMethodShouldSetWorkItemIdsToNullIfNotAny()
{
this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
var methodInfo = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");
this.mockReflectHelper.Setup(rh => rh.GetCustomAttributes(methodInfo, typeof(UTF.WorkItemAttribute))).Returns(new Attribute[0]);

var testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, this.warnings);

Assert.IsNull(testElement.WorkItemIds);
}

[TestMethod]
public void GetTestFromMethodShouldSetCssIteration()
{
Expand Down