Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / RedirectSupportTestCase.cs
blobbe2eebfe69fe11414e3a928062000c00530e6ede
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
17 using Castle.MonoRail.Framework.Helpers;
18 using Castle.MonoRail.Framework.Routing;
19 using Castle.MonoRail.Framework.Services;
20 using NUnit.Framework;
21 using Test;
23 [TestFixture]
24 public class RedirectSupportTestCase
26 private DefaultUrlBuilder urlBuilder;
27 private RoutingEngine engine;
29 [SetUp]
30 public void Init()
32 engine = new RoutingEngine();
33 urlBuilder = new DefaultUrlBuilder();
34 urlBuilder.ServerUtil = new MockServerUtility();
35 urlBuilder.RoutingEngine = engine;
38 [Test]
39 public void RedirectToSiteRootUsesAppVirtualDir()
41 UrlInfo url = new UrlInfo("area", "home", "index", "", ".castle");
42 MockResponse response = new MockResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());
43 response.RedirectToSiteRoot();
44 Assert.AreEqual("/", response.RedirectedTo);
46 url = new UrlInfo("area", "home", "index", "/app", ".castle");
47 response = new MockResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());
48 response.RedirectToSiteRoot();
49 Assert.AreEqual("/app/", response.RedirectedTo);
52 [Test]
53 public void RedirectToUrlDoesNotTouchUrl()
55 UrlInfo url = new UrlInfo("area", "home", "index", "", ".castle");
56 MockResponse response = new MockResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());
57 response.RedirectToUrl("/uol/com/folha");
58 Assert.AreEqual("/uol/com/folha", response.RedirectedTo);
61 [Test]
62 public void RedirectToUrlWithQueryStringAsDict()
64 UrlInfo url = new UrlInfo("area", "home", "index", "", ".castle");
65 MockResponse response = new MockResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());
66 response.RedirectToUrl("/uol/com/folha", DictHelper.Create("id=1", "name=john doe"));
67 Assert.AreEqual("/uol/com/folha?id=1&name=john+doe", response.RedirectedTo);
69 response.RedirectToUrl("/uol/com/folha?something=1", DictHelper.Create("id=1", "name=john doe"));
70 Assert.AreEqual("/uol/com/folha?something=1&id=1&name=john+doe", response.RedirectedTo);
73 [Test]
74 public void Redirect_ToControllerAction()
76 UrlInfo url = new UrlInfo("area", "home", "index", "", ".castle");
77 MockResponse response = new MockResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());
78 response.Redirect("cart", "view");
79 Assert.AreEqual("/area/cart/view.castle", response.RedirectedTo);
81 url = new UrlInfo("", "home", "index", "", ".castle");
82 response = new MockResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());
83 response.Redirect("cart", "view");
84 Assert.AreEqual("/cart/view.castle", response.RedirectedTo);
87 [Test]
88 public void Redirect_ToAreaControllerAction()
90 UrlInfo url = new UrlInfo("area", "home", "index", "", ".castle");
91 MockResponse response = new MockResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());
92 response.Redirect("admin", "cart", "view");
93 Assert.AreEqual("/admin/cart/view.castle", response.RedirectedTo);
95 url = new UrlInfo("", "home", "index", "", ".castle");
96 response = new MockResponse(url, urlBuilder, urlBuilder.ServerUtil, new RouteMatch());
97 response.Redirect("admin", "cart", "view");
98 Assert.AreEqual("/admin/cart/view.castle", response.RedirectedTo);
101 [Test]
102 public void RedirectUsingRoute_InheritingParameters()
104 engine.Add(new PatternRoute("/something/<param1>/admin/[controller]/[action]/[id]"));
106 RouteMatch match = new RouteMatch();
107 match.AddNamed("param1", "Homer");
109 UrlInfo url = new UrlInfo("area", "home", "index", "", ".castle");
110 MockResponse response = new MockResponse(url, urlBuilder, urlBuilder.ServerUtil, match);
111 response.RedirectUsingRoute("cart", "checkout", true);
112 Assert.AreEqual("/something/Homer/admin/cart/checkout", response.RedirectedTo);
115 [Test]
116 public void RedirectUsingRoute_SpecifyingParameters()
118 engine.Add(new PatternRoute("/something/<param1>/admin/[controller]/[action]/[id]"));
120 RouteMatch match = new RouteMatch();
122 UrlInfo url = new UrlInfo("area", "home", "index", "", ".castle");
123 MockResponse response = new MockResponse(url, urlBuilder, urlBuilder.ServerUtil, match);
124 response.RedirectUsingRoute("cart", "checkout", DictHelper.Create("param1=Marge"));
125 Assert.AreEqual("/something/Marge/admin/cart/checkout", response.RedirectedTo);