FileExtensions and HttpPostedFileBase #36

crash-dive opened this Issue Apr 4, 2012 · 3 comments


None yet
2 participants

crash-dive commented Apr 4, 2012

When binding to a model which uses HttpPostedFileBase validation will always fail because FileExtensions expects the property it is decorating to be string.

This should be simple to correct as all you would need to do is add a typeof check in FileExtensions IsValid method.

I'd be happy to create a pull request to fix this if you are happy with the idea of FileExtensions working when model binding to HttpPostedFileBase.


srkirkland commented Apr 4, 2012

@ja-jo A pull request would be great, this sounds like a good idea.


crash-dive commented Apr 5, 2012

I have written the code just wanted a little advice on how you would prefer it organised. In order to create unit tests using HttpPostedFileBase without a Mocking framework you need to inherit from HttpPostedFileBase and create a mock object which I have called HttpPostedFileBaseMock. This follows Microsofts guidelines regarding unit testing this class which you can find here

However I am not sure where to put this class. At the moment I have it in the ValidationAttributes folder of DataAnnotationsExtensions.Tests or I could create another folder and namespace called Mocks but that seems little much for one file so thought I would ask you.

Also one other issue I wanted to raise is this change requires adding a reference to System.Web in the DataAnnotationsExtensions project, I do not see why that would be an issue but want to raise it in case you object.


srkirkland commented Apr 6, 2012

I think it would be ok to create a new folder under DataAnnotationsExtensions.Tests for the new derivative of HttpPostedFileBase, maybe in a folder called "Doubles" so it can be a generic holder for test doubles. Depending on how you use the class it sounds like more a 'fake' or 'stub' than a 'mock' (which has specific validation expectations), so something like HttpPostedFileBaseStub might be a good class/file name.

Also I don't have any problem with adding a reference to System.Web.

@crash-dive crash-dive closed this May 3, 2012

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