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

How to fake form fields #14

Closed
gswartz777 opened this issue Apr 4, 2019 · 5 comments
Closed

How to fake form fields #14

gswartz777 opened this issue Apr 4, 2019 · 5 comments

Comments

@gswartz777
Copy link

Is it possible to fake a form post to a controller? I saw setting up the Request for the FakeContext with FakePostData but the example didn't really make sense to me and I wasn't sure if that was specifically for form posts or something else. If for form posts, do you have a more complete example of how to provide that post data to the controller being tested? Thanks.

@vadimzozulya
Copy link
Owner

@gswartz777 , sorry for delay, but I'm on vacation, and will be able to look at the question only in two weeks.
Offhand, shouldn't controller just accept Model like this: https://stackoverflow.com/a/14124732/5160188 ?
It would be really nice if you provide or point me to a sample controller and test you're trying to implement. But again I'll be able to look at this only in two weeks.

@gswartz777
Copy link
Author

While I can do that, an issue I'm running into with passing the model to the controller is that Model.IsValid is always true because model binding has already occurred. If I pass form fields, then the controller handles the model binding and will fire the validation. To this point, any fields marked required on the model are not validated when I pass the model directly to the controller. Thanks.

@gswartz777
Copy link
Author

Any update on this?

@vadimzozulya
Copy link
Owner

@gswartz777 , if you're trying to test ModelState.IsValid you should use this approach: https://stackoverflow.com/a/3822895/5160188. If not, could you please post the controller code sample ?

Sorry for so long delay.

@vadimzozulya
Copy link
Owner

Please reopen with code sample if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants