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

Already on GitHub? Sign in to your account

Fixing data annotations unit tests #1471

Merged
merged 2 commits into from Mar 2, 2014

Conversation

Projects
None yet
2 participants
Contributor

xt0rted commented Mar 2, 2014

The first commit turns the tests back on but they don't pass because the validation refactoring removed class level attribute support. The second commit tries to add this back in.

From what I know ASP.NET MVC adds class level errors to the results with an empty member name which is what I did here. This also required modifying the custom attribute in the tests to return a member name otherwise the tests still failed.

Another option is to modify the OopsAdapter and override the Validate function like this

yield return new ModelValidationError(new[] { string.Empty }, result.ErrorMessage);

I think this is the better of the two options, I just don't like how the rest of the function is duplicated. I had to do this when implementing an adapter for the CompareAttribute so maybe this could be refactored a bit more to remove the duplication?

I still need to make the change to handle display names as per #1469 but I was looking for feedback on these changes first.

@thecodejunkie thecodejunkie merged commit 9f207dd into NancyFx:master Mar 2, 2014

1 check passed

default The Travis CI build passed
Details
Owner

thecodejunkie commented Mar 2, 2014

Thanks! Pulled it in locally and refactored the method a bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment