One of the most powerful and useful features of Vici MVC is its built-in offline mode for unit testing. Vici MVC allows you to write methods that mimic a user navigating through the site. This allows you to write tests for your complete website, which is almost impossible with ASP.NET or other frameworks. This allows you to test the routing table, controllers and views in a single integrated framework.
Consider the following scenario we want to test:
This is the NUnit test fixture you could write for testing the scenario described above:
[TestFixture] public class WebSiteTest { [Test] public void TestLogin() { OfflineWebSession webSession = new OfflineWebSession(); webSession.FollowRedirects = true; // try to open a page not allowed for anonymous users webSession.PageGet("/youraccount"); // check if page was redirected to the login page Assert.AreEqual(webSession.CurrentPage, "/login"); // enter the login and password on the login page webSession.PostData["LOGIN"] = "john@doe.com"; webSession.PostData["PWD"] = "mymostsecretpassword"; // do login webSession.PagePost("/login"); // check if the page was redicted to the "My Account" page Assert.AreEqual(webSession.CurrentPage,"/youraccount"); // check if the correct user is logged in Assert.IsNotNull(WebApp.Session["USER_ID"]); Assert.AreEqual(9,WebApp.Session["USER_ID"]); // ALL TESTS PASSED } }
You can see right away that the possibilities are endless. You don't have to do anything specific in your application to allow unit testing. Just create a test fixture and perform the actions you want to test. That's it.