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!
This is a test I have to check that my login method on my security controller is doing the right thing:
[TestMethod]
public void Login()
{
var authProvider = new Mock<IAuthenticationProvider>();
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.");
}
My explanation of the test would be:
What I would like to have is a third assert, to see if the view to be rendered actually exists.
Some secondary questions I have would be:
Thanks!
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.
Approach 4: Using OBJECT_ID() function But specifying Database Name and Schema Name provides an option to check the existence of the View in the specified database and within a specified schema, instead of checking in the current database across all the schemas.
A view is a virtual table whose contents are defined by a query. Like a table, a view consists of a set of named columns and rows of data. Unless indexed, a view does not exist as a stored set of data values in a database.
Views are acceptable when you want to restrict users to a particular subset of data. For instance, if you do not delete records but only mark the current one as active and the older versions as inactive, you want a view to use to select only the active records.
No, I don't think you should split the test up as long as its just mainly a third assert and not very much more code.
Yes, I think a more descriptive name would be helpful.
Since you've verified it has the correct view name already, wouldn't simply successfully rendering the view verify its existence?
I think that its great you are working on complete test coverage but here I feel like there might be more effective use of your time if you were able to move on to the part where you verify that the units that perform the actual specific login functions (such as verifying password hashes or whatever) are working correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With