UriTemplateTest.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. //
  2. // UriTemplate.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
  8. // Copyright 2011 Xamarin Inc (http://www.xamarin.com).
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Collections.Generic;
  31. using System.Collections.ObjectModel;
  32. using System.Collections.Specialized;
  33. using NUnit.Framework;
  34. namespace MonoTests.System
  35. {
  36. [TestFixture]
  37. public class UriTemplateTest
  38. {
  39. [Test]
  40. [ExpectedException (typeof (ArgumentNullException))]
  41. public void ConstructorNull ()
  42. {
  43. new UriTemplate (null);
  44. }
  45. [Test]
  46. public void ConstructorEmpty ()
  47. {
  48. // it does not raise an error at this state.
  49. new UriTemplate (String.Empty);
  50. }
  51. [Test]
  52. public void ConstructorNullDictionary ()
  53. {
  54. new UriTemplate (String.Empty, null);
  55. }
  56. [Test]
  57. public void IgnoreTrailingSlashDefault ()
  58. {
  59. Assert.IsFalse (new UriTemplate (String.Empty).IgnoreTrailingSlash);
  60. }
  61. [Test]
  62. [ExpectedException (typeof (FormatException))]
  63. public void ConstructorBrokenTemplate ()
  64. {
  65. // it used to be allowed but now it isn't in 3.5 SP1.
  66. new UriTemplate ("{");
  67. }
  68. [Test]
  69. [ExpectedException (typeof (FormatException))]
  70. public void ConstructorBrokenTemplate2 ()
  71. {
  72. new UriTemplate ("http://localhost:8080/{foo}/{");
  73. }
  74. [Test]
  75. [ExpectedException (typeof (FormatException))]
  76. public void ConstructorBrokenTemplate3 ()
  77. {
  78. new UriTemplate ("http://localhost:8080/{foo}/*/baz");
  79. }
  80. [Test]
  81. public void ToString ()
  82. {
  83. Assert.AreEqual ("urn:foo", new UriTemplate ("urn:foo").ToString (), "#1");
  84. // It used to be allowed but now it isn't in 3.5 SP1.
  85. //Assert.AreEqual ("{", new UriTemplate ("{").ToString (), "#2");
  86. }
  87. [Test]
  88. public void Variables ()
  89. {
  90. var t = new UriTemplate ("urn:foo");
  91. Assert.AreEqual (0, t.PathSegmentVariableNames.Count, "#1a");
  92. Assert.AreEqual (0, t.QueryValueVariableNames.Count, "#1b");
  93. t = new UriTemplate ("http://localhost:8080/");
  94. Assert.AreEqual (0, t.PathSegmentVariableNames.Count, "#2a");
  95. Assert.AreEqual (0, t.QueryValueVariableNames.Count, "#2b");
  96. t = new UriTemplate ("http://localhost:8080/foo/");
  97. Assert.AreEqual (0, t.PathSegmentVariableNames.Count, "#3a");
  98. Assert.AreEqual (0, t.QueryValueVariableNames.Count, "#3b");
  99. t = new UriTemplate ("http://localhost:8080/{foo}");
  100. Assert.AreEqual (1, t.PathSegmentVariableNames.Count, "#4a");
  101. Assert.AreEqual ("FOO", t.PathSegmentVariableNames [0], "#4b");
  102. Assert.AreEqual (0, t.QueryValueVariableNames.Count, "#4c");
  103. // This became invalid in 3.5 SP1
  104. //t = new UriTemplate ("http://localhost:8080/{foo}/{");
  105. //Assert.AreEqual (1, t.PathSegmentVariableNames.Count, "#5a");
  106. //Assert.AreEqual ("FOO", t.PathSegmentVariableNames [0], "#5b");
  107. //Assert.AreEqual (0, t.QueryValueVariableNames.Count, "#5c");
  108. t = new UriTemplate ("http://localhost:8080/hoge?test={foo}&test2={bar}");
  109. Assert.AreEqual (0, t.PathSegmentVariableNames.Count, "#6a");
  110. Assert.AreEqual (2, t.QueryValueVariableNames.Count, "#6b");
  111. Assert.AreEqual ("FOO", t.QueryValueVariableNames [0], "#6c");
  112. Assert.AreEqual ("BAR", t.QueryValueVariableNames [1], "#6d");
  113. }
  114. [Test]
  115. [ExpectedException (typeof (ArgumentException))]
  116. public void VariablesInSameSegment ()
  117. {
  118. new UriTemplate ("http://localhost:8080/{foo}{bar}");
  119. }
  120. [Test]
  121. [Category ("NotDotNet")] //.NET 3.5 SP1 incorrectly matches the port part
  122. public void VariablesInNonPathQuery ()
  123. {
  124. var t = new UriTemplate ("http://localhost:{foo}/");
  125. Assert.AreEqual (0, t.PathSegmentVariableNames.Count, "#8a");
  126. Assert.AreEqual (0, t.QueryValueVariableNames.Count, "#8b");
  127. }
  128. [Test]
  129. [ExpectedException (typeof (InvalidOperationException))]
  130. public void DuplicateNameInTemplate ()
  131. {
  132. // one name to two places to match
  133. new UriTemplate ("http://localhost:8080/hoge?test={foo}&test2={foo}");
  134. }
  135. [Test]
  136. [ExpectedException (typeof (InvalidOperationException))]
  137. public void DuplicateNameInTemplate2 ()
  138. {
  139. // one name to two places to match
  140. new UriTemplate ("http://localhost:8080/hoge/{foo}?test={foo}");
  141. }
  142. [Test]
  143. [ExpectedException (typeof (ArgumentNullException))]
  144. public void BindByNameNullBaseAddress ()
  145. {
  146. var t = new UriTemplate ("http://localhost:8080/");
  147. t.BindByName (null, new NameValueCollection ());
  148. }
  149. [Test]
  150. [ExpectedException (typeof (ArgumentException))]
  151. public void BindByNameRelativeBaseAddress ()
  152. {
  153. var t = new UriTemplate ("http://localhost:8080/");
  154. t.BindByName (new Uri ("", UriKind.Relative), new NameValueCollection ());
  155. }
  156. [Test]
  157. [Category ("NotWorking")] // not worthy
  158. public void BindByNameFileUriBaseAddress ()
  159. {
  160. var t = new UriTemplate ("http://localhost:8080/");
  161. var u = t.BindByName (new Uri ("file:///"), new NameValueCollection ());
  162. Assert.AreEqual ("file:///http://localhost:8080/", u.ToString ());
  163. }
  164. [Test] // it is allowed.
  165. public void BindByNameFileExtraNames ()
  166. {
  167. var t = new UriTemplate ("http://localhost:8080/");
  168. var n = new NameValueCollection ();
  169. n.Add ("name", "value");
  170. t.BindByName (new Uri ("http://localhost/"), n);
  171. }
  172. [Test]
  173. [ExpectedException (typeof (ArgumentException))]
  174. public void BindByNameFileMissingName ()
  175. {
  176. var t = new UriTemplate ("/{foo}/");
  177. t.BindByName (new Uri ("http://localhost/"), new NameValueCollection ());
  178. }
  179. [Test]
  180. [ExpectedException (typeof (ArgumentException))]
  181. public void BindInSameSegment ()
  182. {
  183. new UriTemplate ("/hoo/{foo}{bar}");
  184. }
  185. [Test]
  186. public void BindByName ()
  187. {
  188. var t = new UriTemplate ("/{foo}/{bar}/");
  189. var n = new NameValueCollection ();
  190. n.Add ("Bar", "value1"); // case insensitive
  191. n.Add ("FOO", "value2"); // case insensitive
  192. var u = t.BindByName (new Uri ("http://localhost/"), n);
  193. Assert.AreEqual ("http://localhost/value2/value1/", u.ToString ());
  194. }
  195. [Test]
  196. public void BindByName2 ()
  197. {
  198. var t = new UriTemplate ("{foo}/{bar}");
  199. var n = new NameValueCollection ();
  200. n.Add ("Bar", "value1"); // case insensitive
  201. n.Add ("FOO", "value2"); // case insensitive
  202. var u = t.BindByName (new Uri ("http://localhost/x"), n);
  203. Assert.AreEqual ("http://localhost/x/value2/value1", u.ToString ());
  204. }
  205. [Test]
  206. public void BindByName3 ()
  207. {
  208. var t = new UriTemplate ("Login?clientLoginData={clientLoginData}&credentials={credentials}");
  209. var n = new NameValueCollection ();
  210. var u = t.BindByName (new Uri ("http://localhost"), n);
  211. Assert.AreEqual ("http://localhost/Login", u.ToString (), "#1");
  212. }
  213. [Test]
  214. public void BindByNameManySlashes ()
  215. {
  216. var t = new UriTemplate ("////{foo}/{bar}/");
  217. var n = new NameValueCollection ();
  218. n.Add ("Bar", "value1"); // case insensitive
  219. n.Add ("FOO", "value2"); // case insensitive
  220. var u = t.BindByName (new Uri ("http://localhost/"), n);
  221. Assert.AreEqual ("http://localhost////value2/value1/", u.ToString ());
  222. }
  223. [Test]
  224. public void BindByNameManySlashes2 ()
  225. {
  226. var t = new UriTemplate ("////{foo}/{bar}/");
  227. var n = new NameValueCollection ();
  228. n.Add ("Bar", "value1"); // case insensitive
  229. n.Add ("FOO", "value2"); // case insensitive
  230. var u = t.BindByName (new Uri ("http://localhost//"), n);
  231. Assert.AreEqual ("http://localhost/////value2/value1/", u.ToString ());
  232. }
  233. [Test]
  234. public void BindByNameWithDefaults ()
  235. {
  236. var d = new Dictionary<string,string> ();
  237. d.Add ("Bar", "value1"); // case insensitive
  238. d.Add ("FOO", "value2"); // case insensitive
  239. var t = new UriTemplate ("/{foo}/{bar}/", d);
  240. var u = t.BindByName (new Uri ("http://localhost/"), new NameValueCollection ());
  241. Assert.AreEqual ("http://localhost/value2/value1/", u.ToString ());
  242. }
  243. [Test]
  244. [ExpectedException (typeof (ArgumentException))]
  245. public void BindByNameWithDefaults2 ()
  246. {
  247. var d = new Dictionary<string,string> ();
  248. d.Add ("Bar", "value1"); // case insensitive
  249. d.Add ("FOO", "value2"); // case insensitive
  250. var t = new UriTemplate ("/{foo}/{bar}/{baz}", d);
  251. t.BindByName (new Uri ("http://localhost/"), new NameValueCollection ()); // missing baz
  252. }
  253. [Test]
  254. [ExpectedException (typeof (ArgumentNullException))]
  255. public void BindByPositionNullBaseAddress ()
  256. {
  257. var t = new UriTemplate ("http://localhost:8080/");
  258. t.BindByPosition (null);
  259. }
  260. [Test]
  261. [ExpectedException (typeof (ArgumentException))]
  262. public void BindByPositionRelativeBaseAddress ()
  263. {
  264. var t = new UriTemplate ("http://localhost:8080/");
  265. t.BindByPosition (new Uri ("", UriKind.Relative));
  266. }
  267. [Test]
  268. [Category ("NotWorking")] // not worthy
  269. public void BindByPositionFileUriBaseAddress ()
  270. {
  271. var t = new UriTemplate ("http://localhost:8080/");
  272. Assert.AreEqual (new Uri ("file:///http://localhost:8080/"), t.BindByPosition (new Uri ("file:///")));
  273. }
  274. [Test] // it is NOT allowed (unlike BindByName)
  275. [ExpectedException (typeof (FormatException))]
  276. public void BindByPositionFileExtraValues ()
  277. {
  278. var t = new UriTemplate ("http://localhost:8080/");
  279. t.BindByPosition (new Uri ("http://localhost/"), "value");
  280. }
  281. [Test]
  282. [ExpectedException (typeof (FormatException))]
  283. public void BindByPositionFileMissingValues ()
  284. {
  285. var t = new UriTemplate ("/{foo}/");
  286. t.BindByPosition (new Uri ("http://localhost/"));
  287. }
  288. [Test]
  289. public void BindByPosition ()
  290. {
  291. var t = new UriTemplate ("/{foo}/{bar}/");
  292. var u = t.BindByPosition (new Uri ("http://localhost/"), "value1", "value2");
  293. Assert.AreEqual ("http://localhost/value1/value2/", u.ToString ());
  294. }
  295. [Test]
  296. [ExpectedException (typeof (FormatException))] // it does not allow default values
  297. public void BindByPositionWithDefaults ()
  298. {
  299. var d = new Dictionary<string,string> ();
  300. d ["baz"] = "value3";
  301. var t = new UriTemplate ("/{foo}/{bar}/{baz}", d);
  302. t.BindByPosition (new Uri ("http://localhost/"), "value1", "value2");
  303. }
  304. [Test]
  305. [ExpectedException (typeof (ArgumentNullException))]
  306. public void MatchNullArgument1 ()
  307. {
  308. var t = new UriTemplate ("/hooray");
  309. t.Match (null, new Uri ("http://localhost/"));
  310. }
  311. [Test]
  312. [ExpectedException (typeof (ArgumentNullException))]
  313. public void MatchNullArgument2 ()
  314. {
  315. var t = new UriTemplate ("/hooray");
  316. t.Match (new Uri ("http://localhost/"), null);
  317. }
  318. [Test]
  319. public void MatchNoTemplateItem ()
  320. {
  321. var t = new UriTemplate ("/hooray");
  322. var n = new NameValueCollection ();
  323. Assert.IsNotNull (t.Match (new Uri ("http://localhost/"), new Uri ("http://localhost/hooray")), "#1");
  324. Assert.IsNull (t.Match (new Uri ("http://localhost/"), new Uri ("http://localhost/foobar")), "#2");
  325. Assert.IsNull (t.Match (new Uri ("http://localhost/"), new Uri ("http://localhost/hooray/foobar")), "#3");
  326. }
  327. [Test]
  328. public void MatchWrongTemplate ()
  329. {
  330. var t = new UriTemplate ("/hoo{foo}");
  331. var n = new NameValueCollection ();
  332. var m = t.Match (new Uri ("http://localhost/"), new Uri ("http://localhost/hooray"));
  333. Assert.AreEqual ("ray", m.BoundVariables ["foo"], "#1");
  334. Assert.IsNull (t.Match (new Uri ("http://localhost/"), new Uri ("http://localhost/foobar")), "#2");
  335. Assert.IsNull (t.Match (new Uri ("http://localhost/"), new Uri ("http://localhost/hooray/foobar")), "#3");
  336. Assert.IsNull (t.Match (new Uri ("http://localhost/"), new Uri ("http://localhost/hoo/ray")), "#4");
  337. Assert.IsNull (t.Match (new Uri ("http://localhost/"), new Uri ("http://localhost/hoo")), "#5");
  338. // this matches (as if there were no template).
  339. Assert.IsNotNull (t.Match (new Uri ("http://localhost/"), new Uri ("http://localhost/hoo{foo}")), "#6");
  340. }
  341. [Test]
  342. public void Match ()
  343. {
  344. var t = new UriTemplate ("/{foo}/{bar}");
  345. var n = new NameValueCollection ();
  346. Uri baseUri = new Uri ("http://localhost/");
  347. Assert.IsNull (t.Match (baseUri, new Uri ("http://localhost/hooray")), "#1");
  348. Assert.IsNull (t.Match (baseUri, new Uri ("http://localhost/v1/v2/extra")), "#2");
  349. Assert.IsNull (t.Match (baseUri, new Uri ("http://localhost/1/2/")), "#3");
  350. UriTemplateMatch m = t.Match (baseUri, new Uri ("http://localhost/foooo/baaar"));
  351. Assert.IsNotNull (m, "#4");
  352. Assert.AreEqual ("foooo", m.BoundVariables ["foo"], "#5");
  353. Assert.AreEqual ("baaar", m.BoundVariables ["bar"], "#6");
  354. }
  355. [Test]
  356. public void Match2 ()
  357. {
  358. var t = new UriTemplate ("/{foo}/{bar}?p1={baz}");
  359. var n = new NameValueCollection ();
  360. Uri baseUri = new Uri ("http://localhost/");
  361. Assert.IsNotNull (t.Match (baseUri, new Uri ("http://localhost/X/Y")), "#1");
  362. UriTemplateMatch m = t.Match (baseUri, new Uri ("http://localhost/X/Y?p2=v&p1=vv"));
  363. Assert.IsNotNull (m, "#2");
  364. // QueryParameters must contain non-template query parameters.
  365. Assert.AreEqual (2, m.QueryParameters.Count, "#3");
  366. Assert.AreEqual ("v", m.QueryParameters ["p2"], "#4");
  367. Assert.AreEqual ("vv", m.QueryParameters ["p1"], "#5");
  368. }
  369. [Test]
  370. public void Match3 ()
  371. {
  372. var template = new UriTemplate ("test");
  373. var match1 = template.Match (new Uri ("http://something"), new Uri ("http://something/test"));
  374. var match2 = template.Match (new Uri ("http://something/something2"), new Uri ("http://something/something2/test"));
  375. Assert.IsNotNull (match1, "#1");
  376. Assert.IsNotNull (match2, "#2");
  377. }
  378. [Test]
  379. public void MatchWildcard ()
  380. {
  381. var t = new UriTemplate ("/hoge/*?p1={foo}");
  382. var m = t.Match (new Uri ("http://localhost"), new Uri ("http://localhost/hoge/ppp/qqq?p1=v1"));
  383. Assert.IsNotNull (m, "#0");
  384. Assert.IsNotNull (m.QueryParameters, "#1.0");
  385. Assert.AreEqual ("v1", m.QueryParameters ["p1"], "#1");
  386. Assert.IsNotNull (m.WildcardPathSegments, "#2.0");
  387. Assert.AreEqual (2, m.WildcardPathSegments.Count, "#2");
  388. Assert.AreEqual ("ppp", m.WildcardPathSegments [0], "#3");
  389. Assert.AreEqual ("qqq", m.WildcardPathSegments [1], "#4");
  390. }
  391. [Test]
  392. public void MatchWildcard2 ()
  393. {
  394. var t = new UriTemplate ("*");
  395. var m = t.Match (new Uri ("http://localhost"), new Uri ("http://localhost/hoge/ppp"));
  396. Assert.IsNotNull (m, "#0");
  397. Assert.AreEqual (0, m.QueryParameters.Count, "#1.0");
  398. Assert.AreEqual ("hoge", m.WildcardPathSegments [0], "#2");
  399. Assert.AreEqual ("ppp", m.WildcardPathSegments [1], "#3");
  400. }
  401. [Test]
  402. public void MatchWildcard3 ()
  403. {
  404. var t = new UriTemplate ("*?p1={foo}");
  405. var m = t.Match (new Uri ("http://localhost"), new Uri ("http://localhost/hoge/ppp/qqq?p1=v1"));
  406. Assert.IsNotNull (m, "#0");
  407. Assert.IsNotNull (m.QueryParameters, "#1.0");
  408. Assert.AreEqual ("v1", m.QueryParameters ["p1"], "#1");
  409. Assert.IsNotNull (m.WildcardPathSegments, "#2.0");
  410. Assert.AreEqual (3, m.WildcardPathSegments.Count, "#2");
  411. Assert.AreEqual ("hoge", m.WildcardPathSegments [0], "#3");
  412. Assert.AreEqual ("ppp", m.WildcardPathSegments [1], "#4");
  413. Assert.AreEqual ("qqq", m.WildcardPathSegments [2], "#5");
  414. }
  415. [Test]
  416. public void MatchIgnoreQueryParamNoValue ()
  417. {
  418. var t = new UriTemplate ("/{a}/*", true);
  419. var m = t.Match (new Uri ("http://s"), new Uri ("http://s/a/b?foo"));
  420. Assert.AreEqual (1, m.QueryParameters.Keys.Count, "#1");
  421. }
  422. [Test]
  423. public void IgnoreTrailingSlash ()
  424. {
  425. var t = new UriTemplate ("/{foo}/{bar}", true);
  426. var n = new NameValueCollection ();
  427. Uri baseUri = new Uri ("http://localhost/");
  428. Assert.IsNotNull (t.Match (baseUri, new Uri ("http://localhost/v1/v2/")), "#1");
  429. t = new UriTemplate ("/{foo}/{bar}", false);
  430. Assert.IsNull (t.Match (baseUri, new Uri ("http://localhost/v1/v2/")), "#2");
  431. }
  432. [Test]
  433. [Category ("NotWorking")]
  434. public void SimpleWebGet () {
  435. UriTemplate t = new UriTemplate ("GetBlog");
  436. Assert.IsNotNull(t.Match(new Uri("http://localhost:8000/BlogService"),
  437. new Uri("http://localhost:8000/BlogService/GetBlog")), "Matches simple WebGet method");
  438. Assert.IsNull(t.Match (new Uri ("http://localhost:8000/BlogService"),
  439. new Uri ("http://localhost:8000/BlogService/GetData")), "Doesn't match wrong WebGet method");
  440. }
  441. [Test]
  442. [ExpectedException (typeof (ArgumentException))]
  443. public void DictContainsNullValue ()
  444. {
  445. var t = new UriTemplate ("/id-{foo}/{bar}");
  446. var dic = new Dictionary<string,string> ();
  447. dic ["foo"] = null;
  448. dic ["bar"] = "bbb";
  449. t.BindByName (new Uri ("http://localhost:8080"), dic);
  450. }
  451. [Test]
  452. public void DictContainsCaseInsensitiveKey ()
  453. {
  454. var t = new UriTemplate ("/id-{foo}/{bar}");
  455. var dic = new Dictionary<string,string> ();
  456. dic ["foo"] = "aaa";
  457. dic ["Bar"] = "bbb";
  458. var uri = t.BindByName (new Uri ("http://localhost:8080"), dic);
  459. Assert.AreEqual ("http://localhost:8080/id-aaa/bbb", uri.ToString ());
  460. }
  461. [Test]
  462. public void NamedWildcard ()
  463. {
  464. UriTemplate template = new UriTemplate ("{*path}");
  465. UriTemplateMatch match = template.Match (new Uri ("http://localhost"), new Uri ("http://localhost/something"));
  466. Assert.IsNotNull (match, "#1");
  467. Assert.AreEqual ("something", match.BoundVariables ["path"], "#2");
  468. }
  469. [Test]
  470. [Category ("NotWorking")]
  471. public void EscapedUriCandidate ()
  472. {
  473. var candidateUri = new Uri (@"https://somehost:12345/path1/path2/path3/endprefix/tpath1/guid1/tpath2/~|~~|~%3F~|~Path{guid2}~|~/tpath3");
  474. var matchUri = new Uri (candidateUri.Scheme + "://" + candidateUri.Host + ":" + candidateUri.Port + @"/path1/path2/path3/endprefix");
  475. var template = new UriTemplate (@"tpath1/{guid}/tpath2/{encodedGuidString}/tpath3");
  476. var match = template.Match (matchUri, candidateUri);
  477. Assert.IsNotNull (match);
  478. Assert.That (match.BoundVariables ["GUID"] == "guid1");
  479. Assert.That (match.BoundVariables ["ENCODEDGUIDSTRING"] == "~|~~|~?~|~Path{guid2}~|~");
  480. }
  481. }
  482. }