Note that there are some explanatory texts on larger screens.

plurals
  1. POMaking sure a view exists
    primarykey
    data
    text
    <p>I'm currently looking into unit testing for a new application I have to create. I've got the basic testing going nicely (testing the ActionResult classes is pretty nice). One thing I do want to make sure though, is that a viewpage exists in my solution. I'm not 100% sure my test is correct, so if anyone had suggestions, please don't hesitate!</p> <p>This is a test I have to check that my login method on my security controller is doing the right thing:</p> <pre><code>[TestMethod] public void Login() { var authProvider = new Mock&lt;IAuthenticationProvider&gt;(); var controller = new SecurityController(authProvider.Object); var result = controller.Login() as ViewResult; Assert.IsNotNull(result, "ActionResult should be of type ViewResult."); Assert.AreEqual(result.ViewName, "login", "Does not render login page."); } </code></pre> <p>My explanation of the test would be:</p> <ul> <li>call the method 'Login' on the controller</li> <li>Confirm it's rendering a view (by checking if it returns a ViewResult object)</li> <li>Confirm it's rendering the right view (by checking the viewname)</li> </ul> <p>What I would like to have is a third assert, to see if the view to be rendered actually exists.</p> <p>Some secondary questions I have would be:</p> <ul> <li>Should I split this test up?</li> <li>Should I rename it (like, err, LoginRendersCorrectView or something)</li> </ul> <p>Thanks!</p> <hr> <p>Note: I'm explicitly trying to avoid having to check the filesystem. I'm sort of hoping for a way to use the ViewEngine to confirm the view actually exists.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload