How do I write a unit test to test the UriTemplates (such as [WebGet(Uritemlpate="{clientId}/returns")] in my WCF services?
For example, in Global.asax I have:
private void RegisterRoutes()
{
RouteTable.Routes.Add(new ServiceRoute("clients",
new WebServiceHostFactory(), typeof(ClientService)));
}
In the ClientService I have a [WebGet(Uritemlpate="uri_1")]:
[ServiceContract]
public class ClientService
{
[WebGet(UriTemplate = "uri_1")]
public string GetCollection()
{
return "Method 1";
}
[WebGet(UriTemplate = "uri_2")]
public string GetCollections()
{
return "Method 2";
}
}
I want to have a test that Asserts the url clients/uri_1 hits exactly method GetCollection of ClientService.
You can
Unit Testthe methodsGetCollectionandGetCollectionsby just calling them and checking the return is not null.What you are actually want to do is an
Integration Test. This requires the external dependency of a web server. Check out the difference between the types hereWhat is Unit test, Integration Test, Smoke test, Regression Test?
It is worth while having both. We run
Unit Testswhen we commit code automatically, it is them auto-deployed to a integrations. domain, theIntegration Testsare then run against this.