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
18 using Castle
.MonoRail
.Framework
.Services
;
19 using NUnit
.Framework
;
22 public class DefaultUrlTokenizerTestCase
24 private DefaultUrlTokenizer tokenizer
;
29 tokenizer
= new DefaultUrlTokenizer();
33 public void AddingSimpleDefault()
35 tokenizer
.AddDefaultRule("index.rails", "", "client", "list");
37 UrlInfo info
= tokenizer
.TokenizeUrl("/index.rails", null, new Uri("http://localhost"), true, null);
38 Assert
.IsNotNull(info
);
39 Assert
.AreEqual("client", info
.Controller
);
40 Assert
.AreEqual("list", info
.Action
);
41 Assert
.AreEqual(String
.Empty
, info
.Area
);
42 Assert
.AreEqual("rails", info
.Extension
);
46 public void AddingSimpleDefault2()
48 tokenizer
.AddDefaultRule("index.rails", "", "client", "list");
49 tokenizer
.AddDefaultRule("list.rails", "", "product", "list");
51 UrlInfo info
= tokenizer
.TokenizeUrl("/list.rails", null, new Uri("http://localhost"), true, null);
52 Assert
.IsNotNull(info
);
53 Assert
.AreEqual("product", info
.Controller
);
54 Assert
.AreEqual("list", info
.Action
);
55 Assert
.AreEqual(String
.Empty
, info
.Area
);
56 Assert
.AreEqual("rails", info
.Extension
);
60 public void AddingSimpleDefaultWithArea()
62 tokenizer
.AddDefaultRule("index.rails", "public", "client", "list");
63 tokenizer
.AddDefaultRule("list.rails", "public", "product", "list");
65 UrlInfo info
= tokenizer
.TokenizeUrl("/list.rails", null, new Uri("http://localhost"), true, null);
66 Assert
.IsNotNull(info
);
67 Assert
.AreEqual("product", info
.Controller
);
68 Assert
.AreEqual("list", info
.Action
);
69 Assert
.AreEqual("public", info
.Area
);
70 Assert
.AreEqual("rails", info
.Extension
);
74 public void AddingSimpleDefaultWithArea2()
76 tokenizer
.AddDefaultRule("index.rails", "public", "client", "list");
77 tokenizer
.AddDefaultRule("list.rails", "public/simple", "product", "list");
79 UrlInfo info
= tokenizer
.TokenizeUrl("/list.rails", null, new Uri("http://localhost"), true, null);
80 Assert
.IsNotNull(info
);
81 Assert
.AreEqual("product", info
.Controller
);
82 Assert
.AreEqual("list", info
.Action
);
83 Assert
.AreEqual("public/simple", info
.Area
);
84 Assert
.AreEqual("rails", info
.Extension
);
88 public void SimpleUsage()
90 UrlInfo info
= tokenizer
.TokenizeUrl("/home/index.rails", null, new Uri("http://localhost"), true, null);
91 Assert
.IsNotNull( info
);
92 Assert
.AreEqual( "home", info
.Controller
);
93 Assert
.AreEqual( "index", info
.Action
);
94 Assert
.AreEqual( String
.Empty
, info
.Area
);
95 Assert
.AreEqual( "rails", info
.Extension
);
99 public void ExtensionIgnored()
101 UrlInfo info
= tokenizer
.TokenizeUrl("/home/index.something", null, new Uri("http://localhost"), true, null);
102 Assert
.IsNotNull( info
);
103 Assert
.AreEqual( "home", info
.Controller
);
104 Assert
.AreEqual( "index", info
.Action
);
105 Assert
.AreEqual( String
.Empty
, info
.Area
);
106 Assert
.AreEqual( "something", info
.Extension
);
112 UrlInfo info
= tokenizer
.TokenizeUrl("/myvirdirectory/home/index.rails", null, new Uri("http://localhost"), true, null);
113 Assert
.IsNotNull( info
);
114 Assert
.AreEqual( "home", info
.Controller
);
115 Assert
.AreEqual( "index", info
.Action
);
116 Assert
.AreEqual( "myvirdirectory", info
.Area
);
122 UrlInfo info
= tokenizer
.TokenizeUrl("/myvirdirectory/clients/home/index.rails", null, new Uri("http://localhost"), true, "/myvirdirectory");
123 Assert
.IsNotNull( info
);
124 Assert
.AreEqual( "home", info
.Controller
);
125 Assert
.AreEqual( "index", info
.Action
);
126 Assert
.AreEqual( "clients", info
.Area
);
132 UrlInfo info
= tokenizer
.TokenizeUrl("/myvirdirectory/mysite/clients/home/index.rails", null, new Uri("http://localhost"), true, "/myvirdirectory");
133 Assert
.IsNotNull( info
);
134 Assert
.AreEqual( "home", info
.Controller
);
135 Assert
.AreEqual( "index", info
.Action
);
136 Assert
.AreEqual( "mysite/clients", info
.Area
);
142 UrlInfo info
= tokenizer
.TokenizeUrl("/myvirdirectory/home/index.rails", null, new Uri("http://localhost"), true, "/myvirdirectory");
143 Assert
.IsNotNull( info
);
144 Assert
.AreEqual( "home", info
.Controller
);
145 Assert
.AreEqual( "index", info
.Action
);
146 Assert
.AreEqual( String
.Empty
, info
.Area
);
150 public void VirDirNonLowerCase()
152 UrlInfo info
= tokenizer
.TokenizeUrl("/MyVirDirectory/home/index.rails", null, new Uri("http://localhost"), true, "/myvirdirectory");
153 Assert
.IsNotNull(info
);
154 Assert
.AreEqual("home", info
.Controller
);
155 Assert
.AreEqual("index", info
.Action
);
156 Assert
.AreEqual(String
.Empty
, info
.Area
);
160 public void EmptyVirDir()
162 UrlInfo info
= tokenizer
.TokenizeUrl("/home/index.rails", null, new Uri("http://localhost"), true, "");
163 Assert
.IsNotNull( info
);
164 Assert
.AreEqual( "home", info
.Controller
);
165 Assert
.AreEqual( "index", info
.Action
);
166 Assert
.AreEqual( String
.Empty
, info
.Area
);
169 [Test
, ExpectedException(typeof(UrlTokenizerException
), "Url smaller than 2 tokens")]
172 tokenizer
.TokenizeUrl("/index.rails", null, new Uri("http://localhost"), true, null);