Minor style changes
[castle.git] / MonoRail / Castle.MonoRail.Framework.Tests / Routing / RegexRuleTestCase.cs
blob18a219da457d989ee008a4480ef75019f6f104c4
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.Routing
17 using System.Collections;
18 using Castle.MonoRail.Framework.Routing;
19 using NUnit.Framework;
21 [TestFixture]
22 public class RegexRuleTestCase
24 [Test]
25 public void ShouldMatchAndGenerateAnInformativeResult()
27 RegexRule rule = RegexRule.Build("ProductById", "product/(?<id>\\d+)", typeof(ProductController), "View");
29 RouteMatch match = new RouteMatch(typeof(ProductController), "name", "view");
31 Assert.IsFalse(rule.Matches("localhost", "", "product/", new RouteMatch(typeof(ProductController), "name", "view")));
32 Assert.IsFalse(rule.Matches("localhost", "", "product/iPod", new RouteMatch(typeof(ProductController), "name", "view")));
33 Assert.IsTrue(rule.Matches("localhost", "", "product/1", match));
35 Assert.AreEqual(0, match.Literals.Count);
36 Assert.AreEqual(2, match.Parameters.Count);
37 Assert.AreEqual("1", match.Parameters["id"]);
40 [Test]
41 public void ShouldMatchNamedGroups()
43 RegexRule rule = RegexRule.Build("ProductById", "product/(?<id>\\d+)/(?<page>\\d+)", typeof(ProductController), "View");
45 RouteMatch match = new RouteMatch(typeof(ProductController), "name", "view");
47 Assert.IsFalse(rule.Matches("localhost", "", "product/", new RouteMatch(typeof(ProductController), "name", "view")));
48 Assert.IsFalse(rule.Matches("localhost", "", "product/iPod", new RouteMatch(typeof(ProductController), "name", "view")));
49 Assert.IsFalse(rule.Matches("localhost", "", "product/1", new RouteMatch(typeof(ProductController), "name", "view")));
50 Assert.IsTrue(rule.Matches("localhost", "", "product/12/10", match));
52 Assert.AreEqual(0, match.Literals.Count);
53 Assert.AreEqual(3, match.Parameters.Count);
54 Assert.AreEqual("12", match.Parameters["id"]);
55 Assert.AreEqual("10", match.Parameters["page"]);
58 public class ProductController : Controller { }