Skip to content

Instantly share code, notes, and snippets.

@starteleport
Created March 6, 2013 10:03
Show Gist options
  • Save starteleport/5098244 to your computer and use it in GitHub Desktop.
Save starteleport/5098244 to your computer and use it in GitHub Desktop.
Ambiguous UrlExtensions.ToUrl method behaviour
[Route("/route/{Id}")]
public class JustId : IReturn
{
public long Id { get; set; }
}
[Route("route/{Id}")]
public class JustId_NoSlash : IReturn
{
public long Id { get; set; }
}
[TestFixture]
public class UrlExtensionTests
{
[Test]
public void Starting_slash_test_Fails()
{
var serviceEndpoint = new Uri("http://localhost/api/", UriKind.Absolute);
var actionUrl = new Uri(new JustId { Id = 1 }.ToUrl("GET"), UriKind.Relative);
Assert.That(new Uri(serviceEndpoint, actionUrl).ToString(), Is.EqualTo("http://localhost/api/route/1"));
}
[Test]
public void Starting_slash_test_Passes()
{
var serviceEndpoint = new Uri("http://localhost/api/", UriKind.Absolute);
var actionUrl = new Uri(new JustId_NoSlash { Id = 1 }.ToUrl("GET"), UriKind.Relative);
Assert.That(new Uri(serviceEndpoint, actionUrl).ToString(), Is.EqualTo("http://localhost/api/route/1"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment