Fix the build.
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / DefaultUrlTokenizerTestCase.cs
blobbc0a89f7efe199bb56d0ea85b377e3871e789b5a
1 // Copyright 2004-2007 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 System;
18 using Castle.MonoRail.Framework.Internal;
19 using Castle.MonoRail.Framework.Services;
20 using NUnit.Framework;
22 [TestFixture]
23 public class DefaultUrlTokenizerTestCase
25 private DefaultUrlTokenizer tokenizer;
27 [SetUp]
28 public void Init()
30 tokenizer = new DefaultUrlTokenizer();
33 [Test]
34 public void AddingSimpleDefault()
36 tokenizer.AddDefaultRule("index.rails", "", "client", "list");
38 UrlInfo info = tokenizer.TokenizeUrl("/index.rails", null, new Uri("http://localhost"), true, null);
39 Assert.IsNotNull(info);
40 Assert.AreEqual("client", info.Controller);
41 Assert.AreEqual("list", info.Action);
42 Assert.AreEqual(String.Empty, info.Area);
43 Assert.AreEqual("rails", info.Extension);
46 [Test]
47 public void AddingSimpleDefault2()
49 tokenizer.AddDefaultRule("index.rails", "", "client", "list");
50 tokenizer.AddDefaultRule("list.rails", "", "product", "list");
52 UrlInfo info = tokenizer.TokenizeUrl("/list.rails", null, new Uri("http://localhost"), true, null);
53 Assert.IsNotNull(info);
54 Assert.AreEqual("product", info.Controller);
55 Assert.AreEqual("list", info.Action);
56 Assert.AreEqual(String.Empty, info.Area);
57 Assert.AreEqual("rails", info.Extension);
60 [Test]
61 public void AddingSimpleDefaultWithArea()
63 tokenizer.AddDefaultRule("index.rails", "public", "client", "list");
64 tokenizer.AddDefaultRule("list.rails", "public", "product", "list");
66 UrlInfo info = tokenizer.TokenizeUrl("/list.rails", null, new Uri("http://localhost"), true, null);
67 Assert.IsNotNull(info);
68 Assert.AreEqual("product", info.Controller);
69 Assert.AreEqual("list", info.Action);
70 Assert.AreEqual("public", info.Area);
71 Assert.AreEqual("rails", info.Extension);
74 [Test]
75 public void AddingSimpleDefaultWithArea2()
77 tokenizer.AddDefaultRule("index.rails", "public", "client", "list");
78 tokenizer.AddDefaultRule("list.rails", "public/simple", "product", "list");
80 UrlInfo info = tokenizer.TokenizeUrl("/list.rails", null, new Uri("http://localhost"), true, null);
81 Assert.IsNotNull(info);
82 Assert.AreEqual("product", info.Controller);
83 Assert.AreEqual("list", info.Action);
84 Assert.AreEqual("public/simple", info.Area);
85 Assert.AreEqual("rails", info.Extension);
88 [Test]
89 public void SimpleUsage()
91 UrlInfo info = tokenizer.TokenizeUrl("/home/index.rails", null, new Uri("http://localhost"), true, null);
92 Assert.IsNotNull( info );
93 Assert.AreEqual( "home", info.Controller );
94 Assert.AreEqual( "index", info.Action );
95 Assert.AreEqual( String.Empty, info.Area );
96 Assert.AreEqual( "rails", info.Extension );
99 [Test]
100 public void ExtensionIgnored()
102 UrlInfo info = tokenizer.TokenizeUrl("/home/index.something", null, new Uri("http://localhost"), true, null);
103 Assert.IsNotNull( info );
104 Assert.AreEqual( "home", info.Controller );
105 Assert.AreEqual( "index", info.Action );
106 Assert.AreEqual( String.Empty, info.Area );
107 Assert.AreEqual( "something", info.Extension );
110 [Test]
111 public void Area()
113 UrlInfo info = tokenizer.TokenizeUrl("/myvirdirectory/home/index.rails", null, new Uri("http://localhost"), true, null);
114 Assert.IsNotNull( info );
115 Assert.AreEqual( "home", info.Controller );
116 Assert.AreEqual( "index", info.Action );
117 Assert.AreEqual( "myvirdirectory", info.Area );
120 [Test]
121 public void Area2()
123 UrlInfo info = tokenizer.TokenizeUrl("/myvirdirectory/clients/home/index.rails", null, new Uri("http://localhost"), true, "/myvirdirectory");
124 Assert.IsNotNull( info );
125 Assert.AreEqual( "home", info.Controller );
126 Assert.AreEqual( "index", info.Action );
127 Assert.AreEqual( "clients", info.Area );
130 [Test]
131 public void Area3()
133 UrlInfo info = tokenizer.TokenizeUrl("/myvirdirectory/mysite/clients/home/index.rails", null, new Uri("http://localhost"), true, "/myvirdirectory");
134 Assert.IsNotNull( info );
135 Assert.AreEqual( "home", info.Controller );
136 Assert.AreEqual( "index", info.Action );
137 Assert.AreEqual( "mysite/clients", info.Area );
140 [Test]
141 public void VirDir()
143 UrlInfo info = tokenizer.TokenizeUrl("/myvirdirectory/home/index.rails", null, new Uri("http://localhost"), true, "/myvirdirectory");
144 Assert.IsNotNull( info );
145 Assert.AreEqual( "home", info.Controller );
146 Assert.AreEqual( "index", info.Action );
147 Assert.AreEqual( String.Empty, info.Area );
150 [Test]
151 public void VirDirNonLowerCase()
153 UrlInfo info = tokenizer.TokenizeUrl("/MyVirDirectory/home/index.rails", null, new Uri("http://localhost"), true, "/myvirdirectory");
154 Assert.IsNotNull(info);
155 Assert.AreEqual("home", info.Controller);
156 Assert.AreEqual("index", info.Action);
157 Assert.AreEqual(String.Empty, info.Area);
160 [Test]
161 public void EmptyVirDir()
163 UrlInfo info = tokenizer.TokenizeUrl("/home/index.rails", null, new Uri("http://localhost"), true, "");
164 Assert.IsNotNull( info );
165 Assert.AreEqual( "home", info.Controller );
166 Assert.AreEqual( "index", info.Action );
167 Assert.AreEqual( String.Empty, info.Area );
170 [Test, ExpectedException(typeof(UrlTokenizerException), "Url smaller than 2 tokens")]
171 public void BadUrl()
173 tokenizer.TokenizeUrl("/index.rails", null, new Uri("http://localhost"), true, null);