Refactored the Kernel registration fluent interface to be more readable, better suppo...
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / Services / DefaultUrlBuilderRouteIntegrationTestCase.cs
blob189ecebe73e453dd9d8a6df3da3de0f6cf2f672b
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework.Tests.Services
17 using System.Collections.Specialized;
18 using Castle.MonoRail.Framework.Helpers;
19 using Castle.MonoRail.Framework.Routing;
20 using Castle.MonoRail.Framework.Services;
21 using NUnit.Framework;
22 using Test;
24 [TestFixture]
25 public class DefaultUrlBuilderRouteIntegrationTestCase
27 private DefaultUrlBuilder urlBuilder;
28 private RoutingEngine engine;
30 [SetUp]
31 public void Init()
33 engine = new RoutingEngine();
34 urlBuilder = new DefaultUrlBuilder();
35 urlBuilder.ServerUtil = new MockServerUtility();
36 urlBuilder.RoutingEngine = engine;
39 [Test]
40 public void ShouldTryToBuildUrlUsingMatchingRoutingRule()
42 engine.Add(new PatternRoute("/<area>/<controller>/something/<action>/[id]"));
43 engine.Add(new PatternRoute("/<controller>/something/<action>/[id]"));
45 UrlInfo url = new UrlInfo("", "controller", "action", "", ".castle");
47 HybridDictionary dict = new HybridDictionary(true);
48 dict["controller"] = "cart";
49 dict["action"] = "new";
50 dict["params"] = DictHelper.Create("id=10");
52 Assert.AreEqual("/cart/something/new/10", urlBuilder.BuildUrl(url, dict));
55 [Test]
56 public void OptionalPartsShouldMatchOnlyIfExplictlyPresent()
58 engine.Add(new PatternRoute("/<controller>/something/[action]/[id]"));
60 UrlInfo url = new UrlInfo("", "controller", "action", "", ".castle");
62 HybridDictionary dict = new HybridDictionary(true);
63 dict["controller"] = "home";
65 Assert.AreEqual("/home/something",
66 urlBuilder.BuildUrl(url, dict));
69 [Test]
70 public void ParametersJustToResolveAmbuiguity()
72 engine.Add(new PatternRoute("/something/<param1>/admin/[controller]/[action]/[id]"));
74 UrlInfo url = new UrlInfo("", "controller", "action", "", ".castle");
76 HybridDictionary dict = new HybridDictionary(true);
77 dict["controller"] = "Cart";
78 dict["action"] = "new";
79 dict["params"] = DictHelper.Create("param1=Homer");
81 Assert.AreEqual("/something/Homer/admin/Cart/new",
82 urlBuilder.BuildUrl(url, dict));
85 [Test]
86 public void ShouldAppendQueryString()
88 engine.Add(new PatternRoute("/<controller>/something/<action>/[id]"));
90 UrlInfo url = new UrlInfo("", "controller", "action", "", ".castle");
92 HybridDictionary dict = new HybridDictionary(true);
93 dict["controller"] = "cart";
94 dict["action"] = "new";
95 dict["querystring"] = DictHelper.Create("name=john");
97 Assert.AreEqual("/cart/something/new?name=john", urlBuilder.BuildUrl(url, dict));
99 dict = new HybridDictionary(true);
100 dict["controller"] = "cart";
101 dict["action"] = "new";
102 dict["params"] = DictHelper.Create("id=10");
103 dict["querystring"] = DictHelper.Create("name=john");
105 Assert.AreEqual("/cart/something/new/10?name=john", urlBuilder.BuildUrl(url, dict));