How to run controller action from test?
Yes, simple new MyController().TestAction() kinda works and returns some of ActionResult's, but actually there's no render actions performed and that's why I can't see any of view errors (and even the lack of view!).
ActionResult::ExecuteResult looks like a good point to start, but in requires ControllerContext at least and simple newking is not enough.
            Asked
            
        
        
            Active
            
        
            Viewed 33 times
        
    0
            
            
        
        Troll the Legacy
        
- 675
 - 2
 - 7
 - 22
 
- 
                    Possible duplicate of [How to test an MVC controller with instantiation and action invocation from request content?](https://stackoverflow.com/questions/42089519/how-to-test-an-mvc-controller-with-instantiation-and-action-invocation-from-requ) – jtabuloc Apr 09 '19 at 05:31
 - 
                    What you are looking for is an integration test and not a unit test. See this [answer](https://stackoverflow.com/questions/42089519/how-to-test-an-mvc-controller-with-instantiation-and-action-invocation-from-requ/42090980#42090980). – jtabuloc Apr 09 '19 at 05:33
 - 
                    Why I can't just fetch result from action and catch exceptions? – Troll the Legacy Apr 09 '19 at 05:47
 - 
                    Because razor is an engine that needs to be hosted before it can render a view. I've read that Razor is not a part asp.net-mvc framework I can't remember where the article is. This could explain why you can't see any view being rendered. I could be wrong but that is what I know. IMHO, I don't know if your idea could work but imagine how many dependencies you need to plumb before you can run a simple 'unit test' in the approach you want. – jtabuloc Apr 09 '19 at 06:00