PageRenderTime 120ms CodeModel.GetById 111ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Manos.Tests/Manos.Routing/MatchOperationFactoryTest.cs

http://github.com/jacksonh/manos
C# | 157 lines | 97 code | 37 blank | 23 comment | 0 complexity | d392c89403fbe2a7403a8bd2f080252b MD5 | raw file
  1//
  2// Copyright (C) 2010 Jackson Harper (jackson@manosdemono.com)
  3//
  4// Permission is hereby granted, free of charge, to any person obtaining
  5// a copy of this software and associated documentation files (the
  6// "Software"), to deal in the Software without restriction, including
  7// without limitation the rights to use, copy, modify, merge, publish,
  8// distribute, sublicense, and/or sell copies of the Software, and to
  9// permit persons to whom the Software is furnished to do so, subject to
 10// the following conditions:
 11// 
 12// The above copyright notice and this permission notice shall be
 13// included in all copies or substantial portions of the Software.
 14// 
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 16// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 17// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 18// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 19// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 20// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 21// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 22//
 23//
 24
 25
 26using System;
 27using NUnit.Framework;
 28
 29using Manos.Routing;
 30using Manos.ShouldExt;
 31
 32
 33namespace Manos.Routing.Tests
 34{
 35
 36	[TestFixture()]
 37	public class MatchOperationFactoryTest
 38	{
 39
 40		[Test ()]
 41		public void TestCreateNull ()
 42		{
 43			Should.Throw<ArgumentNullException> (() => MatchOperationFactory.Create (null));
 44		}
 45		
 46		[Test ()]
 47		public void TestIsNop ()
 48		{
 49			IMatchOperation op;
 50			
 51			op = MatchOperationFactory.Create (String.Empty);
 52			Should.BeInstanceOf<NopMatchOperation> (op, "a1");
 53		}
 54		
 55		[Test()]
 56		public void TestIsRegex ()
 57		{
 58			IMatchOperation op;
 59			
 60			op = MatchOperationFactory.Create ("dog.");
 61			Should.BeInstanceOf<RegexMatchOperation> (op, "a1");
 62			
 63			op = MatchOperationFactory.Create (".dog");
 64			Should.BeInstanceOf<RegexMatchOperation> (op, "a2");
 65			
 66			op = MatchOperationFactory.Create ("d.og");
 67			Should.BeInstanceOf<RegexMatchOperation> (op, "a3");
 68			
 69			op = MatchOperationFactory.Create (".");
 70			Should.BeInstanceOf<RegexMatchOperation> (op, "a4");
 71			
 72			op = MatchOperationFactory.Create ("[dog]");
 73			Should.BeInstanceOf<RegexMatchOperation> (op, "a6");
 74			
 75			op = MatchOperationFactory.Create ("(dog)");
 76			Should.BeInstanceOf<RegexMatchOperation> (op, "a7");
 77			
 78			op = MatchOperationFactory.Create ("^dog");
 79			Should.BeInstanceOf<RegexMatchOperation> (op, "a8");
 80			
 81			op = MatchOperationFactory.Create ("dog*");
 82			Should.BeInstanceOf<RegexMatchOperation> (op, "a9");
 83			
 84			op = MatchOperationFactory.Create (".*dog");
 85			Should.BeInstanceOf<RegexMatchOperation> (op, "a10");
 86			
 87			op = MatchOperationFactory.Create ("$dog");
 88			Should.BeInstanceOf<RegexMatchOperation> (op, "a11");
 89			
 90			op = MatchOperationFactory.Create ("dog$");
 91			Should.BeInstanceOf<RegexMatchOperation> (op, "a12");
 92		}
 93		
 94		[Test]
 95		public void Create_SimpleMatchInMiddle_CreatesSimpleMatch ()
 96		{
 97			IMatchOperation op = MatchOperationFactory.Create ("/Foo/{bar}/");
 98			
 99			Should.BeInstanceOf<SimpleMatchOperation> (op);
100		}
101		
102		[Test]
103		public void Create_SimpleMatchAtBeginning_CreatesSimpleMatch ()
104		{
105			IMatchOperation op = MatchOperationFactory.Create ("{bar}/Foo");
106			
107			Should.BeInstanceOf<SimpleMatchOperation> (op);
108		}
109		
110		[Test]
111		public void Create_SimpleMatchAtEnd_CreatesSimpleMatch ()
112		{
113			IMatchOperation op = MatchOperationFactory.Create ("/Foo/{bar}");
114			
115			Should.BeInstanceOf<SimpleMatchOperation> (op);
116		}
117		
118		[Test]
119		public void Create_SimpleMatchIsWholePattern_CreatesSimpleMatch ()
120		{
121			IMatchOperation op = MatchOperationFactory.Create ("{bar}");
122			
123			Should.BeInstanceOf<SimpleMatchOperation> (op);
124		}
125		
126		[Test]
127		public void Create_EscapedOpenSimpleMatch_CreatesStringMatch ()
128		{
129			IMatchOperation op = MatchOperationFactory.Create ("{{bar}");
130			
131			Should.BeInstanceOf<StringMatchOperation> (op);
132		}
133		
134		[Test]
135		public void Create_EscapedCloseSimpleMatch_CreatesStringMatch ()
136		{
137			IMatchOperation op = MatchOperationFactory.Create ("{bar}}");
138			
139			Should.BeInstanceOf<StringMatchOperation> (op);
140		}
141		
142		[Test]
143		public void TestIsString ()
144		{
145			IMatchOperation op;
146			
147			op = MatchOperationFactory.Create ("foobar");
148			Should.BeInstanceOf<StringMatchOperation> (op, "a1");
149			
150			op = MatchOperationFactory.Create ("1");
151			Should.BeInstanceOf<StringMatchOperation> (op, "a2");
152			
153			op = MatchOperationFactory.Create ("i am the walrus");
154			Should.BeInstanceOf<StringMatchOperation> (op, "a3");
155		}
156	}
157}