Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to override GetDisplayName method from DataRowAttribute #1413

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ public void GetDisplayNameForArrayOfOneItem()
Verify(displayName == "MyMethod (a)");
}

public void GetDisplayName_AfterOverriding_GetsTheNewDisplayname()
{
// Arrange
var dataRow = new DummyDataRowAttribute(new[] { "a" });
var methodInfoMock = new Mock<MethodInfo>();
methodInfoMock.SetupGet(x => x.Name).Returns("MyMethod");

// Act
var displayName = dataRow.GetDisplayName(methodInfoMock.Object, dataRow.Data);

// Assert
Verify(displayName == "MyMethod");
}

public void GetDisplayNameForArrayOfMultipleItems()
{
// Arrange
Expand Down Expand Up @@ -164,4 +178,22 @@ public void GetDisplayNameForMultipleArraysOfMultipleItems()
// Assert
Verify(displayName == "MyMethod (System.String[],System.String[])");
}

private class DummyDataRowAttribute : DataRowAttribute
{
public DummyDataRowAttribute(object data)
: base(data)
{
}

public override string GetDisplayName(MethodInfo methodInfo, object[] data)
{
if (!string.IsNullOrWhiteSpace(DisplayName))
{
return DisplayName;
}

return methodInfo.Name;
engyebrahim marked this conversation as resolved.
Show resolved Hide resolved
}
}
}