1
// Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
;
25 public class DefaultUrlBuilderRouteIntegrationTestCase
27 private DefaultUrlBuilder urlBuilder
;
28 private RoutingEngine engine
;
33 engine
= new RoutingEngine();
34 urlBuilder
= new DefaultUrlBuilder();
35 urlBuilder
.ServerUtil
= new MockServerUtility();
36 urlBuilder
.RoutingEngine
= engine
;
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
));
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
));
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
));
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
));