Created
February 28, 2009 14:01
-
-
Save hotgazpacho/71959 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
using System.Web.Routing; | |
using MvcContrib.TestHelper; | |
using NUnit.Framework; | |
using NUnit.Framework.SyntaxHelpers; | |
namespace NUnitMvc.Routes | |
{ | |
/// <summary> | |
/// Summary description for RouteTests. | |
/// </summary> | |
[TestFixture] | |
public class DefaultRouteTests | |
{ | |
/// <summary> | |
/// Perform generic test initialization. Because this method is | |
/// marked with the <code>SetUp</code> attribute, it is called | |
/// prior to the invocation of each test. | |
/// </summary> | |
[SetUp] | |
public void Init() | |
{ | |
} | |
/// <summary> | |
/// Perform generic post-test cleanup. Because this method is | |
/// marked with the <code>tearDown</code> attribute, it is called | |
/// following the completion of each test method. | |
/// </summary> | |
[TearDown] | |
public void Dispose() | |
{ | |
} | |
[Test] | |
public void DefaultRouteMapsToHomeController() | |
{ | |
RouteData routeData = "~/".Route(); | |
RouteValueDictionary expected = new RouteValueDictionary | |
{ | |
{"controller", "home"}, | |
{"action", "index"} | |
}; | |
CollectionAssert.AreEquivalent(expected, routeData.Values); | |
} | |
[Test] | |
public void RouteWithOnlyControllerMapsToIndexAction() | |
{ | |
RouteData routeData = "~/Home".Route(); | |
RouteValueDictionary expected = new RouteValueDictionary | |
{ | |
{"controller", "home"}, | |
{"action", "index"} | |
}; | |
CollectionAssert.AreEquivalent(expected, routeData.Values); | |
} | |
[Test] | |
public void RouteWithOnlyControllerAndActionMapsToExpectedAction() | |
{ | |
string controller = "Home"; | |
string action = "About"; | |
RouteData routeData = string.Format("~/{0}/{1}", controller, action).Route(); | |
RouteValueDictionary expected = new RouteValueDictionary | |
{ | |
{"controller", controller}, | |
{"action", action} | |
}; | |
CollectionAssert.AreEquivalent(expected, routeData.Values); | |
} | |
[Test] | |
public void RouteWithControllerActionAndIdMapsWithId() | |
{ | |
string controller = "Home"; | |
string action = "Details"; | |
int id = 1; | |
RouteData routeData = string.Format("~/{0}/{1}/{2}", controller, action, id).Route(); | |
RouteValueDictionary expected = new RouteValueDictionary | |
{ | |
{"controller", controller}, | |
{"action", action}, | |
{"id", id } | |
}; | |
CollectionAssert.AreEquivalent(expected, routeData.Values); | |
} | |
[Test] | |
public void RouteWithTooManySegments() | |
{ | |
RouteData routeData = "~/Home/Details/1/c".Route(); | |
Assert.IsNull(routeData); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment