Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / UrlPartsBuilderTestCase.cs
bloba9858d6f6184751ae4cc85828ea864512f1965b9
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.Services;
18 using NUnit.Framework;
20 [TestFixture]
21 public class UrlPartsBuilderTestCase
23 [Test]
24 public void CanBuildPathUrls()
26 UrlParts builder = new UrlParts("controller", "action");
28 Assert.AreEqual("controller/action", builder.BuildPath());
31 [Test]
32 public void BuildPathWithPathInfo()
34 UrlParts builder = new UrlParts("controller", "action");
35 builder.PathInfo.Add("State").Add("FL");
37 Assert.AreEqual("controller/action/State/FL", builder.BuildPath());
40 [Test]
41 public void BuildPathWithPathInfoDictionary()
43 UrlParts builder = new UrlParts("controller", "action");
44 builder.PathInfoDict["State"] ="FL";
46 Assert.AreEqual("controller/action/State/FL", builder.BuildPath());
49 [Test]
50 public void BuildPathWithPathInfoAndQueryString()
52 UrlParts builder = new UrlParts("controller", "action");
53 builder.PathInfoDict["State"] = "FL";
54 builder.SetQueryString("type=Residential");
56 Assert.AreEqual("controller/action/State/FL?type=Residential", builder.BuildPath());
59 [Test]
60 public void PathInfoDictParse_AcceptsNull()
62 UrlParts builder = new UrlParts("controller", "action");
63 builder.PathInfoDict.Parse(null);
65 Assert.AreEqual("controller/action", builder.BuildPath());
68 [Test]
69 public void PathInfoDictParse_AcceptsEmptyString()
71 UrlParts builder = new UrlParts("controller", "action");
72 builder.PathInfoDict.Parse("");
74 Assert.AreEqual("controller/action", builder.BuildPath());
77 [Test]
78 public void PathInfoDictParse_CanHandleMissingSlash()
80 UrlParts builder = new UrlParts("controller", "action");
81 builder.PathInfoDict.Parse("State/Fl");
83 Assert.AreEqual("controller/action/State/Fl", builder.BuildPath());
86 [Test]
87 public void PathInfoDictParse_CanHandleMultipleEntries()
89 UrlParts builder = new UrlParts("controller", "action");
90 builder.PathInfoDict.Parse("/State/FL/Type/Home");
92 Assert.AreEqual("controller/action/State/FL/Type/Home", builder.BuildPath());
95 [Test]
96 public void PathInfoDictParse_CanHandleOddNumberOfEntries()
98 UrlParts builder = new UrlParts("controller", "action");
99 builder.PathInfoDict.Parse("/State/FL/Type/");
101 Assert.AreEqual("controller/action/State/FL/Type", builder.BuildPath());
104 [Test]
105 public void PathInfoDictParse_CanHandleOddNumberOfEntries2()
107 UrlParts builder = new UrlParts("controller", "action");
108 builder.PathInfoDict.Parse("/State/FL/Type");
110 Assert.AreEqual("controller/action/State/FL/Type", builder.BuildPath());
113 [Test]
114 public void ParseCanHandleAbsolutePaths()
116 UrlParts builder = UrlParts.Parse("http://localhost/home/index.ext");
118 Assert.AreEqual(0, builder.PathInfoDict.Count);
120 Assert.AreEqual("http://localhost/home/index.ext", builder.BuildPath());
123 [Test]
124 public void ParseCanHandleAbsolutePathsWithQueryString()
126 UrlParts builder = UrlParts.Parse("http://localhost/home/index.ext?id=1&type=home");
128 Assert.AreEqual(0, builder.PathInfoDict.Count);
129 Assert.AreEqual("id=1&type=home", builder.QueryStringAsString());
131 Assert.AreEqual("http://localhost/home/index.ext?id=1&type=home", builder.BuildPath());
134 [Test]
135 public void ParseCanHandleAbsolutePathsWithPathInfo()
137 UrlParts builder = UrlParts.Parse("http://localhost/home/index.ext/state/fl/");
139 Assert.AreEqual(1, builder.PathInfoDict.Count);
140 Assert.AreEqual("fl", builder.PathInfoDict["state"]);
141 Assert.AreEqual("", builder.QueryStringAsString());
143 Assert.AreEqual("http://localhost/home/index.ext/state/fl", builder.BuildPath());
146 [Test]
147 public void ParseCanHandleRelativePaths()
149 UrlParts builder = UrlParts.Parse("home/index.ext");
151 Assert.AreEqual("home/index.ext", builder.BuildPath());
154 [Test]
155 public void ParseCanHandleRelativePathsWithEmptyPathInfo()
157 UrlParts builder = UrlParts.Parse("home/index.ext/");
159 Assert.AreEqual("home/index.ext", builder.BuildPath());
162 [Test]
163 public void ParseCanHandleRelativePathsWithPathInfo()
165 UrlParts builder = UrlParts.Parse("home/index.ext/state/fl");
167 Assert.AreEqual(1, builder.PathInfoDict.Count);
168 Assert.AreEqual("fl", builder.PathInfoDict["state"]);
169 Assert.IsNull(builder.QueryStringAsString());
171 Assert.AreEqual("home/index.ext/state/fl", builder.BuildPath());
174 [Test]
175 public void ParseCanHandleRelativePathsWithPathInfo2()
177 UrlParts builder = UrlParts.Parse("home/index.ext/state/fl/");
179 Assert.AreEqual(1, builder.PathInfoDict.Count);
180 Assert.AreEqual("fl", builder.PathInfoDict["state"]);
181 Assert.IsNull(builder.QueryStringAsString());
183 Assert.AreEqual("home/index.ext/state/fl", builder.BuildPath());
186 [Test]
187 public void ParseCanHandleRelativePathsWithQueryString()
189 UrlParts builder = UrlParts.Parse("home/index.ext?id=1&name=john");
191 Assert.AreEqual(0, builder.PathInfoDict.Count);
192 Assert.AreEqual("id=1&name=john", builder.QueryStringAsString());
194 Assert.AreEqual("home/index.ext?id=1&name=john", builder.BuildPath());
197 [Test]
198 public void ParseCanHandleRelativePathsWithEmptyPathInfoAndQueryString()
200 UrlParts builder = UrlParts.Parse("home/index.ext/?id=1&name=john");
202 Assert.AreEqual(0, builder.PathInfoDict.Count);
203 Assert.AreEqual("id=1&name=john", builder.QueryStringAsString());
205 Assert.AreEqual("home/index.ext?id=1&name=john", builder.BuildPath());
208 [Test]
209 public void ParseCanHandleRelativePathsWithPathInfoAndQueryString()
211 UrlParts builder = UrlParts.Parse("home/index.ext/state/fl/?id=1&name=john");
213 Assert.AreEqual(1, builder.PathInfoDict.Count);
214 Assert.AreEqual("fl", builder.PathInfoDict["state"]);
215 Assert.AreEqual("id=1&name=john", builder.QueryStringAsString());
217 Assert.AreEqual("home/index.ext/state/fl?id=1&name=john", builder.BuildPath());
220 [Test]
221 public void QueryStringParsesStringCorrectly()
223 UrlParts builder = new UrlParts("home/index.ext");
225 builder.QueryString["state"] = "FL";
227 Assert.AreEqual("home/index.ext?state=FL", builder.BuildPath());
230 [Test]
231 public void QueryStringIsExtractedAndParsed()
233 UrlParts builder = new UrlParts("home/index.ext");
235 builder.SetQueryString("City=SP&State=MD");
237 builder.QueryString["type"] = "home";
239 Assert.AreEqual("home/index.ext?City=SP&State=MD&type=home", builder.BuildPath());
242 [Test]
243 public void QueryStringCanHandleDuplicatedEntries()
245 UrlParts builder = new UrlParts("home/index.ext");
247 builder.SetQueryString("City=SP&State=MD&State=NY");
249 Assert.AreEqual("home/index.ext?City=SP&State=MD&State=NY", builder.BuildPath());
252 [Test]
253 public void QueryStringCanReplaceEntries()
255 UrlParts builder = new UrlParts("home/index.ext");
257 builder.QueryString["page"] = "1";
259 Assert.AreEqual("home/index.ext?page=1", builder.BuildPath());
261 builder.QueryString.Set("page", "2");
263 Assert.AreEqual("home/index.ext?page=2", builder.BuildPath());
265 builder.QueryString.Set("page", "3");
267 Assert.AreEqual("home/index.ext?page=3", builder.BuildPath());