public
Last active

How to test a ASP.NET Web API route using my contribution to WebApiContrib, RouteTestingExtensions.

  • Download Gist
SampleRouteTest.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
using System.Web.Routing;
using WebApiContrib.Testing;
 
namespace FooBar
{
[TestFixture]
public void RouteFixture
{
[SetUp]
public void Setup()
{
// Register your routes
RouteTable.Routes.Clear();
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
[Test]
public void ValidateRoute()
{
// Assert that the url is routed using the appropriate controller and parameters
const string url = "~/api/sample/5";
url.ShouldMapTo<SampleController>(x => x.Get(5));
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.