Skip to content

Instantly share code, notes, and snippets.

@pmhsfelix
Created August 11, 2011 16:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmhsfelix/1140101 to your computer and use it in GitHub Desktop.
Save pmhsfelix/1140101 to your computer and use it in GitHub Desktop.
Operation URI resolution
[ServiceContract]
class TheResolverTestService
{
[WebGet(UriTemplate="op1/{prm1}/{prm2}")]
public void Oper1(string prm1, int prm2)
{
}
[WebGet(UriTemplate = "op2/{prm1}/middle/{prm2}")]
[OperationContract(Name="op2")]
public void Oper1(HttpRequestMessage req, string prm1, int prm2)
{
}
}
[TestFixture]
class UriResolverTests
{
[Test]
public void Test()
{
using (var host = new HttpServiceHost(typeof(TheResolverTestService), new Uri("http://localhost:8080/somebase/")))
{
host.Open();
var r = new UriResolver<TheResolverTestService>(host.Description.Endpoints[0]);
Assert.AreEqual(new Uri("http://localhost:8080/somebase/op1/prm1value/13"),
r.Resolve(s => s.Oper1("prm1value", 13)));
Assert.AreEqual(new Uri("http://localhost:8080/somebase/op2/prm1value/middle/13"),
r.Resolve(s => s.Oper1(default(HttpRequestMessage),"prm1value", 13)));
Assert.AreEqual(new Uri("http://localhost:8080/somebase/op2/prm1value/middle/13"),
r.Resolve(s => s.Oper1(default(HttpRequestMessage), "prm1"+"value", 10+3)));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment