Skip to content

Instantly share code, notes, and snippets.

@hotgazpacho
Created February 28, 2009 13:29
Show Gist options
  • Save hotgazpacho/71955 to your computer and use it in GitHub Desktop.
Save hotgazpacho/71955 to your computer and use it in GitHub Desktop.
[Test]
public void DefaultRouteMapsToHomeController()
{
RouteData routeData = "~/".Route();
Assert.That(routeData.Values["controller"], Is.EqualTo("home").IgnoreCase);
Assert.That(routeData.Values["action"], Is.EqualTo("index").IgnoreCase);
Assert.That(routeData.Values["id"], Is.Null);
}
[Test]
public void RouteWithOnlyControllerMapsToIndexAction()
{
RouteData routeData = "~/Home".Route();
Assert.That(routeData.Values["controller"], Is.EqualTo("home").IgnoreCase);
Assert.That(routeData.Values["action"], Is.EqualTo("index").IgnoreCase);
Assert.That(routeData.Values["id"], Is.Null);
}
[Test]
public void RouteWithOnlyControllerAndActionMapsToExpectedAction()
{
string controller = "Home";
string action = "About";
RouteData routeData = string.Format("~/{0}/{1}", controller, action).Route();
Assert.That(routeData.Values["controller"], Is.EqualTo(controller).IgnoreCase);
Assert.That(routeData.Values["action"], Is.EqualTo(action).IgnoreCase);
Assert.That(routeData.Values["id"], Is.Null);
}
[Test]
public void RouteWithControllerActionAndIdMapsWithId()
{
string controller = "Home";
string action = "Details";
int id = 1;
RouteData routeData = string.Format("~/{0}/{1}/{2}", controller, action, id).Route();
Assert.That(routeData.Values["controller"], Is.EqualTo(controller).IgnoreCase);
Assert.That(routeData.Values["action"], Is.EqualTo(action).IgnoreCase);
Assert.That(routeData.Values["id"], Is.EqualTo(id));
}
[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