public void MultipleExpandVarArgs() { UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}"); Uri result = template.Expand("2", 21); result = template.Expand(1, "42"); Assert.AreEqual(new Uri("http://example.com/hotels/1/bookings/42"), result, "Invalid expanded template"); }
public void ExpandVarArgsDuplicateVariables() { UriTemplate template = new UriTemplate("http://example.com/order/{c}/{c}/{c}"); Assert.AreEqual(new string[] { "c" }, template.VariableNames, "Invalid variable names"); Uri result = template.Expand("cheeseburger"); Assert.AreEqual(new Uri("http://example.com/order/cheeseburger/cheeseburger/cheeseburger"), result, "Invalid expanded template"); }
public void ExpandDictionaryInvalidAmountVariables() { IDictionary<string, object> uriVariables = new Dictionary<string, object>(2); uriVariables.Add("hotel", 1); UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}"); template.Expand(uriVariables); }
public void ExpandVarArgs() { // absolute UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}"); Uri result = template.Expand("1", "42"); Assert.AreEqual(new Uri("http://example.com/hotels/1/bookings/42"), result, "Invalid expanded template"); // relative template = new UriTemplate("/hotels/{hotel}/bookings/{booking}"); result = template.Expand("1", "42"); Assert.AreEqual(new Uri("/hotels/1/bookings/42", UriKind.Relative), result, "Invalid expanded template"); }
public void ExpandDictionary() { IDictionary<string, object> uriVariables = new Dictionary<string, object>(2); uriVariables.Add("booking", "42"); uriVariables.Add("hotel", 1); // absolute UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}"); Uri result = template.Expand(uriVariables); Assert.AreEqual(new Uri("http://example.com/hotels/1/bookings/42"), result, "Invalid expanded template"); // relative template = new UriTemplate("hotels/{hotel}/bookings/{booking}"); result = template.Expand(uriVariables); Assert.AreEqual(new Uri("hotels/1/bookings/42", UriKind.Relative), result, "Invalid expanded template"); }
public void ExpandEncoded() { UriTemplate template = new UriTemplate("http://example.com/hotel list/{hotel}"); Uri result = template.Expand("Z\u00fcrich"); Assert.AreEqual(new Uri("http://example.com/hotel%20list/Z%C3%BCrich"), result, "Invalid expanded template"); }
public void MultipleExpandDictionary() { UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}"); IDictionary<string, object> uriVariables = new Dictionary<string, object>(2); uriVariables.Add("booking", 21); uriVariables.Add("hotel", "2"); Uri result = template.Expand(uriVariables); uriVariables = new Dictionary<string, object>(2); uriVariables.Add("booking", "42"); uriVariables.Add("hotel", "1"); result = template.Expand(uriVariables); Assert.AreEqual(new Uri("http://example.com/hotels/1/bookings/42"), result, "Invalid expanded template"); }
public void ExpandWithAtSign() { UriTemplate template = new UriTemplate("http://localhost/query={query}"); Uri uri = template.Expand("foo@bar"); Assert.AreEqual("http://localhost/query=foo@bar", uri.ToString()); }
public void ExpandVarArgsInvalidAmountVariables() { UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}"); template.Expand("1", "42", 100); }