Thursday, 22 August 2013

Testing ASP.NET Web API POST Routes with WebApiContrib.Testing

Testing ASP.NET Web API POST Routes with WebApiContrib.Testing

I am trying to set up some route tests using the WebApiContrib.Testing
library. My get tests (like this) work fine...
[Test]
[Category("Auth Api Tests")]
public void TheAuthControllerAcceptsASingleItemGetRouteWithAHashString()
{
"~/auth/sjkfhiuehfkshjksdfh".ShouldMapTo<AuthController>(c =>
c.Get("sjkfhiuehfkshjksdfh"));
}
I am rather lost on the post test - I currently have the following which
fails with a NotImplementedException...
[Test]
[Category("Auth Api Tests")]
public void TheAuthControllerAcceptsAPost()
{
"~/auth".ShouldMapTo<AuthController>(c => c.Post(new
AuthenticationCredentialsModel()), "POST");
}
Here's the setup and teardown for completeness...
[SetUp]
public void SetUpTest()
{
RouteConfig.RegisterRoutes(RouteTable.Routes);
WebApiConfig.Register(GlobalConfiguration.Configuration);
}
[TearDown]
public void TearDownTest()
{
RouteTable.Routes.Clear();
GlobalConfiguration.Configuration.Routes.Clear();
}
The route I am trying to test is the default POST route, which maps to
this method call...
[AllowAnonymous]
public HttpResponseMessage Post([FromBody]
AuthenticationCredentialsModel model)
{ *** Some code here that doesn't really matter *** }

No comments:

Post a Comment