More working tests.
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / Services / DefaultUrlTokenizerTestCase.cs
blob6e583446a12585a29d74a6b583c0215b60e61234
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.Services
17 using System;
18 using Castle.MonoRail.Framework.Services;
19 using NUnit.Framework;
21 [TestFixture]
22 public class DefaultUrlTokenizerTestCase
24 private DefaultUrlTokenizer tokenizer;
26 [SetUp]
27 public void Init()
29 tokenizer = new DefaultUrlTokenizer();
32 [Test]
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);
45 [Test]
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);
59 [Test]
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);
73 [Test]
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);
87 [Test]
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 );
98 [Test]
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 );
109 [Test]
110 public void Area()
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 );
119 [Test]
120 public void Area2()
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 );
129 [Test]
130 public void Area3()
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 );
139 [Test]
140 public void VirDir()
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 );
149 [Test]
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);
159 [Test]
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")]
170 public void BadUrl()
172 tokenizer.TokenizeUrl("/index.rails", null, new Uri("http://localhost"), true, null);