-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add easier way to unit test controllers calling the extension methods #16
Comments
Hi, Thanks |
@astian92 Have you tried the above link: Otherwise, can you give me your action code and the failing test and can give a solution? |
Yes I did, I am using this code to call an Initializing method in the Test class constructor:
As you can see, the "TestServices" object is not recognized by the compiler, and I am sorry if I am missing something simple but I don't know what this service is for either, and my research at the web spawns a long list of different results that I didn't find useful. Anyway, as this line is not working, I get the following exception:
This is my test:
In the initialization of the test class I use a static tool that calls the initialization that you suggested and mocks the URL function to return the controllername\action as a value:
So, the full initialization code in my test class is:
Finally, this is the method under test:
Sorry to bother you, and thank you very much for answering. |
@astian92 Take a look at the whole example to get a better understand of what is going on. https://github.com/ivaylokenov/AspNet.Mvc.TypedRouting/tree/master/test/AspNet.Mvc.TypedRouting.Test Let me know if you have any more questions. 👍 P. S. Have you checked https://github.com/ivaylokenov/MyTested.AspNetCore.Mvc for testing your MVC project? |
First, thanks for this excellent open source library! With that, I'm just wondering if there are any plans to move forward on this particular issue. Testing a controller which uses the UrlHelper extension methods throws I've made my first attempt at implementing the solution above, without much success, but at this point I'm effectively settled on just accepting the confidence my Postman tests give me on my controller functionality. But, it feels pretty wrong and would love to have a more easy to implement unit testing solution :/ Still better than magic strings all over a huge project though. |
Currently, developers need to do this before the tests:
https://github.com/ivaylokenov/AspNet.Mvc.TypedRouting/blob/master/test/AspNet.Mvc.TypedRouting.Test/TestInit.cs
Add Wiki page for unit testing.
The text was updated successfully, but these errors were encountered: