/MR3/tests/Castle.MonoRail.Tests/Routing/RouteMatchingTests.UriGen.cs

https://github.com/castleproject/MonoRail · C# · 140 lines · 104 code · 22 blank · 14 comment · 0 complexity · 114f627b6d538abba38251c8c6bce7e1 MD5 · raw file

  1. #region License
  2. // Copyright 2004-2012 Castle Project - http://www.castleproject.org/
  3. // Hamilton Verissimo de Oliveira and individual contributors as indicated.
  4. // See the committers.txt/contributors.txt in the distribution for a
  5. // full listing of individual contributors.
  6. //
  7. // This is free software; you can redistribute it and/or modify it
  8. // under the terms of the GNU Lesser General Public License as
  9. // published by the Free Software Foundation; either version 3 of
  10. // the License, or (at your option) any later version.
  11. //
  12. // You should have received a copy of the GNU Lesser General Public
  13. // License along with this software; if not, write to the Free
  14. // Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  15. // 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  16. #endregion
  17. namespace Castle.MonoRail.Routing.Tests
  18. {
  19. using Castle.MonoRail.Routing;
  20. using Castle.MonoRail.Routing.Tests.Stubs;
  21. using FluentAssertions;
  22. using NUnit.Framework;
  23. public partial class RouteMatchingTests
  24. {
  25. [Test]
  26. public void LiteralMatching_DoubleTerms_GeneratesCorrectUri()
  27. {
  28. const string path = "/something/else";
  29. _router.Match(path, new DummyHandlerMediator());
  30. var data = _router.TryMatch("/something/else");
  31. data.Uri.AbsoluteUri.Should().Be("http://localhost:3333/something/else");
  32. }
  33. [Test]
  34. public void VPath_LiteralMatching_DoubleTerms_GeneratesCorrectUri()
  35. {
  36. const string path = "/something/else";
  37. _router.Match(path, new DummyHandlerMediator());
  38. var data = _router.TryMatch("/app/something/else", "/app");
  39. data.Uri.AbsoluteUri.Should().Be("http://localhost:3333/app/something/else");
  40. }
  41. [Test]
  42. public void LiteralAndGreedy_GreedyIsOptionalByDefault_GeneratesCorrectUri()
  43. {
  44. const string path = "/something/**";
  45. _router.Match(path, new DummyHandlerMediator());
  46. var data = _router.TryMatch("/something");
  47. data.Uri.AbsoluteUri.Should().Be("http://localhost:3333/something");
  48. }
  49. [Test]
  50. public void LiteralAndGreedy_GreedyIsOptionalByDefaultButMatchesTrailingFwdSlash_GeneratesCorrectUri()
  51. {
  52. const string path = "/something/**";
  53. _router.Match(path, new DummyHandlerMediator());
  54. var data = _router.TryMatch("/something/");
  55. data.Uri.AbsoluteUri.Should().Be("http://localhost:3333/something/");
  56. }
  57. [Test]
  58. public void LiteralAndGreedy_GreedyIsOptionalByDefaultButForDotMatchForCharIsRequired2_GeneratesCorrectUri()
  59. {
  60. const string path = "/something.**";
  61. _router.Match(path, new DummyHandlerMediator());
  62. var data = _router.TryMatch("/something.");
  63. data.Uri.OriginalString.Should().Be("http://localhost:3333/something.");
  64. data.Uri.AbsoluteUri.Should().Be("http://localhost:3333/something");
  65. }
  66. [Test]
  67. public void LiteralAndGreedy_GreedyIsOptionalByDefaultButForDotMatchForCharIsRequired3_GeneratesCorrectUri()
  68. {
  69. const string path = "/something.**";
  70. _router.Match(path, new DummyHandlerMediator());
  71. var data = _router.TryMatch("/something.pdf");
  72. data.Uri.OriginalString.Should().Be("http://localhost:3333/something.");
  73. data.Uri.AbsoluteUri.Should().Be("http://localhost:3333/something");
  74. }
  75. [Test]
  76. public void LiteralAndGreedy_GreedyMatch1Segment_GeneratesCorrectUri()
  77. {
  78. const string path = "/something/**";
  79. _router.Match(path, new DummyHandlerMediator());
  80. var data = _router.TryMatch("/something/some");
  81. data.Uri.AbsoluteUri.Should().Be("http://localhost:3333/something/");
  82. }
  83. [Test]
  84. public void LiteralAndGreedy_GreedyMatch2Segments_GeneratesCorrectUri()
  85. {
  86. const string path = "/something/**";
  87. _router.Match(path, new DummyHandlerMediator());
  88. var data = _router.TryMatch("/something/some/1/");
  89. data.Uri.AbsoluteUri.Should().Be("http://localhost:3333/something/");
  90. }
  91. [Test]
  92. public void VPath_LiteralAndGreedy_GreedyMatch2Segments_GeneratesCorrectUri()
  93. {
  94. const string path = "/something/**";
  95. _router.Match(path, new DummyHandlerMediator());
  96. var data = _router.TryMatch("/app/something/some/1/", "/app");
  97. data.Uri.OriginalString.Should().Be("http://localhost:3333/app/something/");
  98. data.Uri.AbsoluteUri.Should().Be("http://localhost:3333/app/something/");
  99. }
  100. [Test]
  101. public void NestedRouteWithGreedyTerm_GeneratesCorrectUri()
  102. {
  103. _router.Match("/something",
  104. config =>
  105. {
  106. config.Invariables(dc => dc.Controller("Something"));
  107. config.Match("/$metadata", rc => rc.Invariables(dc => dc.Action("Metadata")));
  108. config.Match("/**");
  109. });
  110. var data = _router.TryMatch("/something/$metadata");
  111. data.Uri.OriginalString.Should().Be("http://localhost:3333/something/$metadata");
  112. data.Uri.AbsoluteUri.Should().Be("http://localhost:3333/something/$metadata");
  113. data = _router.TryMatch("/something/Products(0)");
  114. data.Uri.OriginalString.Should().Be("http://localhost:3333/something/");
  115. data.Uri.AbsoluteUri.Should().Be("http://localhost:3333/something/");
  116. }
  117. }
  118. }