Skip to content

Commit

Permalink
BugFix: WorkItemAttribute not extracted (#749)
Browse files Browse the repository at this point in the history
* Fixed WorkItem Id not being read bug

* Added comment to trigger CI build

* Removed comment to trigger CI build

* Removed second newline

* Removed Array Suffix from Variable Name

* Fixed bug and added test

Co-authored-by: Flepp Jann <JFlepp@Hamilton.ch>
  • Loading branch information
jflepp and Flepp Jann committed Dec 8, 2020
1 parent ce694f3 commit ad822aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
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

0 comments on commit ad822aa

Please sign in to comment.