Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
//
// AssertExtensions.cs
//
// Author:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2009 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Web;
using System.Web.Routing;
using NUnit.Framework;
namespace MonoTests.System.Web.Routing
{
public delegate void AssertThrowsDelegate ();
public static class AssertExtensions
{
public static void Throws <EX> (AssertThrowsDelegate code)
{
Throws (typeof (EX), code);
}
public static void Throws <EX> (AssertThrowsDelegate code, string message)
{
Throws (typeof (EX), code, message);
}
public static void Throws (Type exceptionType, AssertThrowsDelegate code)
{
Throws (exceptionType, code, String.Empty);
}
public static void Throws (Type exceptionType, AssertThrowsDelegate code, string message)
{
if (code == null)
throw new ArgumentNullException ("code");
if (exceptionType == null)
throw new ArgumentNullException ("exceptionType");
try {
code ();
} catch (Exception ex) {
if (ex.GetType () != exceptionType)
Assert.Fail (message + " (got exception of type '" + ex.GetType () + "')");
// good!
return;
}
Assert.Fail (message);
}
}
}

View File

@@ -0,0 +1,100 @@
2012-12-23 Daniel Lo Nigro <daniel@dan.cx>
* RouteTest.cs: added tests for value types in route default values
(Xamarin bug #9116)
2009-09-09 Marek Habersack <mhabersack@novell.com>
* RouteTest.cs: added two tests for empty and null route URLs (bug
#537751)
2009-06-25 Marek Habersack <mhabersack@novell.com>
* RouteCollectionTest.cs, RouteTest.cs: added new tests for
GetVirtualPath
2009-06-04 Marek Habersack <mhabersack@novell.com>
* RouteCollectionTest.cs: added two more test cases to the bug
#502555 test. They check whether url generation matches defaults
case-insensitively.
2009-05-27 Marek Habersack <mhabersack@novell.com>
* RouteCollectionTest.cs: added a test for routes from
NerdDinner.
2009-05-25 Marek Habersack <mhabersack@novell.com>
* RouteTest.cs: added several tests for GetVirtualPath,
GetRouteData, ProcessConstraint and refactored some tests.
* RouteCollectionTest.cs: added several tests for GetVirtualPath
* AssertExtensions.cs: added some methods to make code testing for
exception throws look nicer.
2009-05-11 Marek Habersack <mhabersack@novell.com>
* RouteCollectionTest.cs: added test for bug #502555
2009-05-05 Marek Habersack <mhabersack@novell.com>
* RouteTest.cs: added test for bug #500739
2008-10-23 Atsushi Enomoto <atsushi@ximian.com>
* RouteTest.cs :
add one more case that used to cause out-of-range error.
2008-10-17 Atsushi Enomoto <atsushi@ximian.com>
* RouteValueDictionaryTest.cs : test for case-insensitive comparison.
2008-10-17 Atsushi Enomoto <atsushi@ximian.com>
* RouteTest.cs : added test for DynamicData default pattern.
2008-10-16 Atsushi Enomoto <atsushi@ximian.com>
* RouteValueDictionaryTest.cs : new test.
2008-10-10 Atsushi Enomoto <atsushi@ximian.com>
* UrlRoutingModuleTest.cs , TestStubTypes.cs : added test for
pipeline processing of requests.
2008-09-18 Atsushi Enomoto <atsushi@ximian.com>
* UrlRoutingModuleTest.cs, TestStubTypes.cs, RouteCollectionTest.cs:
some tests for RouteExistingFiles.
2008-09-18 Atsushi Enomoto <atsushi@ximian.com>
* RouteTest.cs : test ProcessConstraint().
* UrlRoutingHandlerTest.cs : more cosmetic test on thrown exception.
* TestStubTypes.cs : some notations.
2008-09-17 Atsushi Enomoto <atsushi@ximian.com>
* UrlRoutingModuleTest.cs: new test (including "huh?" ones).
* RouteTest.cs, TestStubTypes.cs, RouteCollectionTest.cs:
some test updates.
2008-09-12 Atsushi Enomoto <atsushi@ximian.com>
* RouteTest.cs, TestStubTypes.cs, HttpMethodConstraintTest.cs,
RouteCollectionTest.cs : test for Route.GetRouteData() and
HttpMethodConstraint.Match().
2008-09-12 Atsushi Enomoto <atsushi@ximian.com>
* RouteTest.cs, RouteCollectionTest.cs: added couple of tests for
Route Url parser.
2008-09-11 Atsushi Enomoto <atsushi@ximian.com>
* HttpMethodConstraintTest.cs, RouteCollectionTest.cs,
RouteDataTest.cs, RouteTest.cs, StopRoutingHandlerTest.cs,
TestStubTypes.cs, UrlRoutingHandlerTest.cs,
VirtualPathDataTest.cs : initial checkin.

View File

@@ -0,0 +1,227 @@
//
// System.Web.HttpResponseTest.cs - Unit tests for System.Web.HttpResponse
//
// Author:
// Miguel de Icaza <miguel@ximian.com>
//
// Copyright (C) 2005-2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Text;
using System.Web;
using System;
using System.Collections;
using System.Collections.Specialized;
using NUnit.Framework;
namespace MonoTests.Common
{
public class FakeHttpWorkerRequest : HttpWorkerRequest
{
const string appPath = "/";
string queryString;
public Hashtable KnownResponseHeaders;
public Hashtable UnknownResponseHeaders;
public int return_kind;
public FakeHttpWorkerRequest ()
: this (1)
{
// for Mono
AppDomain.CurrentDomain.SetData (".appVPath", appPath);
}
public FakeHttpWorkerRequest (int re)
{
KnownResponseHeaders = CollectionsUtil.CreateCaseInsensitiveHashtable ();
UnknownResponseHeaders = CollectionsUtil.CreateCaseInsensitiveHashtable ();
return_kind = re;
queryString = String.Empty;
}
public override string GetUriPath ()
{
return "/fake";
}
public override string GetFilePath ()
{
return GetUriPath ();
}
public override string GetQueryString ()
{
return queryString;
}
public void SetQueryString (string queryString)
{
this.queryString = queryString;
}
public override string GetRawUrl ()
{
#if NET_4_0
return "/GetRawUrl";
#else
return "GetRawUrl";
#endif
}
public override string GetHttpVerbName ()
{
return "GET";
}
public override string GetHttpVersion ()
{
if (return_kind == 1)
return "HTTP/1.0";
else
return "HTTP/1.1";
}
public override string GetRemoteAddress ()
{
return "__GetRemoteAddress";
}
public override int GetRemotePort ()
{
return 1010;
}
public override string GetLocalAddress ()
{
return "GetLocalAddress";
}
public override string GetAppPath ()
{
return appPath;
}
public override int GetLocalPort ()
{
return 2020;
}
public override string MapPath (string virtualPath)
{
#if TARGET_DOTNET
return "c:\\fakefile";
#else
return "/fakefile";
#endif
}
public bool status_sent;
public int status_code;
public string status_string;
public override void SendStatus (int s, string x)
{
status_sent = true;
status_code = s;
status_string = x;
}
void AddHeader (Hashtable table, string header_name, object header)
{
object o = table[header_name];
if (o == null)
table.Add (header_name, header);
else {
ArrayList al = o as ArrayList;
if (al == null) {
al = new ArrayList ();
al.Add (o);
table[header_name] = al;
} else
al = o as ArrayList;
al.Add (header);
}
}
bool headers_sent;
public override void SendKnownResponseHeader (int x, string j)
{
string header_name = HttpWorkerRequest.GetKnownRequestHeaderName (x);
AddHeader (KnownResponseHeaders, header_name, new KnownResponseHeader (x, j));
headers_sent = true;
}
public override void SendUnknownResponseHeader (string a, string b)
{
AddHeader (UnknownResponseHeaders, a, new UnknownResponseHeader (a, b));
headers_sent = true;
}
bool data_sent;
public byte[] data;
public int data_len;
public int total = 0;
public override void SendResponseFromMemory (byte[] arr, int x)
{
data_sent = true;
data = new byte[x];
for (int i = 0; i < x; i++)
data[i] = arr[i];
data_len = x;
total += data_len;
}
public override void SendResponseFromFile (string a, long b, long c)
{
data_sent = true;
}
public override void SendResponseFromFile (IntPtr a, long b, long c)
{
data_sent = true;
}
public override void FlushResponse (bool x)
{
}
public override void EndOfRequest ()
{
}
public override string GetKnownRequestHeader (int index)
{
return null;
}
public bool OutputProduced
{
get
{
return headers_sent || data_sent;
}
}
}
}

View File

@@ -0,0 +1,138 @@
//
// HttpMethodConstraintTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Web;
using System.Web.Routing;
using NUnit.Framework;
namespace MonoTests.System.Web.Routing
{
class MyHttpMethodConstraint : HttpMethodConstraint
{
public MyHttpMethodConstraint (params string [] args)
: base (args)
{
}
public bool CallMatch (HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
return Match (httpContext, route, parameterName, values, routeDirection);
}
}
[TestFixture]
public class HttpMethodConstraintTest
{
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorNullArgs ()
{
new HttpMethodConstraint (null);
}
[Test]
public void ConstructorEmptyArray ()
{
new HttpMethodConstraint (new string [0]);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void MatchNullContext ()
{
var c = new MyHttpMethodConstraint (new string [0]);
c.CallMatch (null, new Route (null, null), "foo", new RouteValueDictionary (), RouteDirection.IncomingRequest);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void MatchNullRoute ()
{
var c = new MyHttpMethodConstraint (new string [0]);
c.CallMatch (new HttpContextStub (), null, "foo", new RouteValueDictionary (), RouteDirection.IncomingRequest);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void MatchNullName ()
{
var c = new MyHttpMethodConstraint (new string [0]);
c.CallMatch (new HttpContextStub (), new Route (null, null), null, new RouteValueDictionary (), RouteDirection.IncomingRequest);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void MatchNullValues ()
{
var c = new MyHttpMethodConstraint (new string [0]);
c.CallMatch (new HttpContextStub (), new Route (null, null), "foo", null, RouteDirection.IncomingRequest);
}
[Test]
public void Match ()
{
var c = new MyHttpMethodConstraint (new string [0]);
Assert.IsFalse (c.CallMatch (new HttpContextStub (""), new Route (null, null), "foo", new RouteValueDictionary (), RouteDirection.IncomingRequest));
}
[Test]
[ExpectedException (typeof (NotImplementedException))]
public void MatchDependsOnRequest ()
{
// it tries to get HttpContext.Request only when HttpMethodConstraint actually has one or more values.
var c = new MyHttpMethodConstraint (new string [] {"GET"});
c.CallMatch (new HttpContextStub (), new Route (null, null), "foo", new RouteValueDictionary (), RouteDirection.IncomingRequest);
}
[Test]
public void Match2 ()
{
var c = new MyHttpMethodConstraint (new string [] {"GET"});
Assert.IsFalse (c.CallMatch (new HttpContextStub (""), new Route (null, null), "foo", new RouteValueDictionary (), RouteDirection.IncomingRequest), "#1");
Assert.IsTrue (c.CallMatch (new HttpContextStub ("", "", "GET"), new Route (null, null), "", new RouteValueDictionary (), RouteDirection.IncomingRequest), "#2");
Assert.IsFalse (c.CallMatch (new HttpContextStub ("", "", "POST"), new Route (null, null), "", new RouteValueDictionary (), RouteDirection.IncomingRequest), "#3");
// LAMESPEC: .NET allows case-insensitive comparison, which violates RFC 2616
// Assert.IsFalse (c.CallMatch (new HttpContextStub ("", "", "get"), new Route (null, null), "", new RouteValueDictionary (), RouteDirection.IncomingRequest), "#4");
}
[Test]
public void UrlGeneration ()
{
var c = new HttpMethodConstraint (new string[] { "GET" }) as IRouteConstraint;
var req = new HttpContextStub ("", "", "HEAD");
var values = new RouteValueDictionary () { { "httpMethod", "GET" } };
Assert.IsTrue (c.Match (req, new Route (null, null), "httpMethod", values, RouteDirection.UrlGeneration), "#1");
values = new RouteValueDictionary() { { "httpMethod", "POST" } };
Assert.IsFalse (c.Match (req, new Route (null, null), "httpMethod", values, RouteDirection.UrlGeneration), "#2");
}
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MonoTests.Common
{
class KnownResponseHeader
{
private int index;
private string value;
public KnownResponseHeader (int index, string value)
{
this.index = index;
this.value = value;
}
public int Index
{
get { return index; }
}
public string Value
{
get { return value; }
}
}
}

View File

@@ -0,0 +1,103 @@
//
// RequestContext.cs
//
// Authors:
// Marek Habersack <mhabersack@novell.com>
//
// Copyright (C) 2010 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Routing;
using NUnit.Framework;
namespace MonoTests.System.Web.Routing
{
[TestFixture]
public class RequestContextTest
{
#if NET_4_0
[Test]
public void DefaultConstructor ()
{
var rc = new RequestContext ();
Assert.AreEqual (null, rc.HttpContext, "#A1");
Assert.AreEqual (null, rc.RouteData, "#A2");
}
#endif
[Test]
public void Constructor_HttpContextBase_RouteData ()
{
RequestContext rc;
AssertExtensions.Throws<ArgumentNullException> (() => {
rc = new RequestContext (null, new RouteData ());
}, "#A1");
var ctx = new HttpContextWrapper (new HttpContext (new HttpRequest ("filename", "http://localhost/filename", String.Empty), new HttpResponse (new StringWriter ())));
AssertExtensions.Throws<ArgumentNullException> (() => {
rc = new RequestContext (ctx, null);
}, "#A2");
}
[Test]
public void HttpContext ()
{
var ctx = new HttpContextWrapper (new HttpContext (new HttpRequest ("filename", "http://localhost/filename", String.Empty), new HttpResponse (new StringWriter ())));
var rc = new RequestContext (ctx, new RouteData ());
Assert.AreSame (ctx, rc.HttpContext, "#A1");
#if NET_4_0
ctx = new HttpContextWrapper (new HttpContext (new HttpRequest ("filename", "http://localhost/filename", String.Empty), new HttpResponse (new StringWriter ())));
rc.HttpContext = ctx;
Assert.AreSame (ctx, rc.HttpContext, "#A2");
rc.HttpContext = null;
Assert.IsNull (rc.HttpContext, "#A3");
#endif
}
[Test]
public void RouteData ()
{
var ctx = new HttpContextWrapper (new HttpContext (new HttpRequest ("filename", "http://localhost/filename", String.Empty), new HttpResponse (new StringWriter ())));
var rd = new RouteData ();
var rc = new RequestContext (ctx, rd);
Assert.AreSame (rd, rc.RouteData, "#A1");
#if NET_4_0
rd = new RouteData ();
rc.RouteData = rd;
Assert.AreSame (rd, rc.RouteData, "#A2");
rc.RouteData = null;
Assert.IsNull (rc.RouteData, "#A3");
#endif
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,89 @@
//
// RouteDataTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Web;
using System.Web.Routing;
using NUnit.Framework;
namespace MonoTests.System.Web.Routing
{
[TestFixture]
public class RouteDataTest
{
[Test]
public void ConstructorNullArgs ()
{
new RouteData (null, null);
}
[Test]
public void DefaultValues ()
{
var d = new RouteData ();
Assert.IsNull (d.Route, "#1");
Assert.IsNull (d.RouteHandler, "#2");
Assert.AreEqual (0, d.DataTokens.Count, "#3");
Assert.AreEqual (0, d.Values.Count, "#4");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void GetRequiredStringNull ()
{
var d = new RouteData ();
d.GetRequiredString (null);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void GetRequiredStringNonexistent ()
{
var d = new RouteData ();
d.GetRequiredString ("a");
}
[Test]
public void GetRequiredStringExistent ()
{
var d = new RouteData ();
d.Values.Add ("a", "x");
Assert.AreEqual ("x", d.GetRequiredString ("a"));
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void GetRequiredStringForNonStringValue ()
{
var d = new RouteData ();
d.Values.Add ("a", 10);
Assert.AreEqual ("10", d.GetRequiredString ("a"));
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,86 @@
//
// RouteValueDictionaryTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Routing;
using NUnit.Framework;
namespace MonoTests.System.Web.Routing
{
[TestFixture]
public class RouteValueDictionaryTest
{
[Test]
public void ConstructorNullArgs ()
{
// null is allowed
new RouteValueDictionary ((object) null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorNullArgs2 ()
{
new RouteValueDictionary ((IDictionary<string,object>) null);
}
[Test]
public void ConstructorObject ()
{
var d = new RouteValueDictionary (new {Foo = "urn:foo", Bar = "urn:bar"});
Assert.AreEqual ("urn:foo", d ["Foo"], "#1");
Assert.AreEqual ("urn:bar", d ["Bar"], "#2");
Assert.IsNull (d ["Baz"], "#3");
}
[Test]
public void CaseInsensitiveMatch ()
{
var d = new RouteValueDictionary (new {Foo = "urn:foo", Bar = "urn:bar"});
Assert.AreEqual ("urn:foo", d ["foo"], "#1");
Assert.AreEqual ("urn:bar", d ["BAR"], "#2");
}
[Test]
public void Keys ()
{
var d = new RouteValueDictionary (new {Foo = "urn:foo", Bar = "urn:bar"});
int i = 0;
foreach (var k in d.Keys) {
if (k == "Foo")
i += 1;
if (k == "Bar")
i += 2;
}
Assert.AreEqual (3, i);
}
}
}

View File

@@ -0,0 +1,47 @@
//
// StopRoutingHandlerTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Web;
using System.Web.Routing;
using NUnit.Framework;
namespace MonoTests.System.Web.Routing
{
[TestFixture]
public class StopRoutingHandlerTest
{
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void GetHandler ()
{
new MyStopRoutingHandler ().CallGetHttpHandler (new RequestContext (new HttpContextStub (), new RouteData ()));
}
}
}

View File

@@ -0,0 +1,425 @@
//
// TestStubTypes.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Web;
using System.Web.Routing;
using NUnit.Framework;
namespace MonoTests.System.Web.Routing
{
class HttpContextStub : HttpContextBase
{
HttpRequestStub req;
bool returnNullRequest;
public HttpContextStub ()
: this (null)
{
}
public HttpContextStub (bool returnNullRequest)
: this (null)
{
this.returnNullRequest = returnNullRequest;
}
public HttpContextStub (string dummyRequestPath)
: this (dummyRequestPath, null)
{
}
public HttpContextStub (string dummyRequestPath, string pathInfo)
: this (dummyRequestPath, pathInfo, null)
{
}
public HttpContextStub (string dummyRequestPath, string pathInfo, string method)
{
if (dummyRequestPath != null) {
req = new HttpRequestStub (dummyRequestPath, pathInfo);
req.Method = method;
}
}
public override HttpRequestBase Request {
get {
if (returnNullRequest)
return null;
return req != null ? req : base.Request;
}
}
}
class HttpRequestStub : HttpRequestBase
{
public HttpRequestStub (string dummyRequestPath, string pathInfo)
{
req_path = dummyRequestPath;
path_info = pathInfo;
}
string req_path, path_info;
public override string AppRelativeCurrentExecutionFilePath {
get { return req_path ?? base.AppRelativeCurrentExecutionFilePath; }
}
public override string PathInfo {
get { return path_info ?? base.PathInfo; }
}
public override string HttpMethod {
get { return Method; }
}
public string Method { get; set; }
}
class MyDictionary : Hashtable
{
public override ICollection Keys {
get { return null; }
}
public override object this [object key] {
get {
//Console.Error.WriteLine ("Get: {0} {1}", key, key.GetHashCode ());
return base [key];
}
set {
//Console.Error.WriteLine ("Set: {0} {1} = {2}", key, key.GetHashCode (), value);
base [key] = value;
}
}
}
class HttpContextStub2 : HttpContextBase
{
public HttpContextStub2 ()
: this (null, null)
{
}
public HttpContextStub2 (string requestUrl, string path)
: this (requestUrl, path, null)
{
}
public HttpContextStub2 (string requestUrl, string path, string appPath)
{
request = new HttpRequestStub2 (requestUrl, path, appPath);
}
Hashtable items = new MyDictionary ();
HttpRequestStub request;
HttpResponseBase response;
public override IDictionary Items {
get { return items; }
}
public override HttpRequestBase Request {
get { return request ?? base.Request; }
}
public override HttpResponseBase Response {
get { return response ?? base.Response; }
}
public override void RewritePath (string path)
{
throw new ApplicationException (path);
}
public void SetResponse (HttpResponseBase response)
{
this.response = response;
}
public void SetRequest (HttpRequestStub request)
{
this.request = request;
}
}
class HttpRequestStub2 : HttpRequestStub
{
public HttpRequestStub2 (string dummyRequestPath, string dummyPath, string appPath)
: base (dummyRequestPath, String.Empty)
{
path = dummyPath;
app_path = appPath;
}
string path, app_path;
public override string ApplicationPath {
get { return app_path ?? base.ApplicationPath; }
}
public override string Path {
get { return path ?? base.Path; }
}
}
public class HttpResponseStub : HttpResponseBase
{
public HttpResponseStub ()
: this (0)
{
}
int impl_type;
public HttpResponseStub (int implType)
{
this.impl_type = implType;
}
public override string ApplyAppPathModifier (string virtualPath)
{
switch (impl_type) {
case 3:
return virtualPath; // pass thru
case 2:
return virtualPath + "_modified";
case 1:
throw new ApplicationException (virtualPath);
default:
return base.ApplyAppPathModifier (virtualPath);
}
}
}
class HttpContextStub3 : HttpContextStub2
{
public HttpContextStub3 (string requestUrl, string path, string appPath, bool supportHandler)
: base (requestUrl, path, appPath)
{
this.support_handler = supportHandler;
}
public override void RewritePath (string path)
{
RewrittenPath = path;
}
bool support_handler;
public IHttpHandler HttpHandler { get; set; }
public override IHttpHandler Handler {
get { return support_handler ? HttpHandler : base.Handler; }
set {
if (support_handler)
HttpHandler = value;
else
base.Handler = value;
}
}
public string RewrittenPath { get; set; }
}
#if NET_4_0
class FakeHttpRequestWrapper : HttpRequestWrapper
{
string requestUrl;
string path;
string appPath;
public FakeHttpRequestWrapper (string requestUrl, string path, string appPath)
: base (new HttpRequest (path, "http://localhost/", String.Empty))
{
this.requestUrl = requestUrl;
this.path = path;
this.appPath = appPath;
}
public override string AppRelativeCurrentExecutionFilePath
{
get
{
return appPath;
}
}
}
class HttpContextStub4 : HttpContextStub3
{
HttpRequestWrapper wrapper;
public override HttpRequestBase Request
{
get
{
return wrapper;
}
}
public HttpContextStub4 (string requestUrl, string path, string appPath, bool supportHandler)
: base (requestUrl, path, appPath, supportHandler)
{
wrapper = new FakeHttpRequestWrapper (requestUrl, path, appPath);
}
}
class HttpContextStub5 : HttpContextStub2
{
HttpRequestWrapper wrapper;
public override HttpRequestBase Request
{
get
{
return wrapper;
}
}
public HttpContextStub5 ()
: this (null, null)
{
}
public HttpContextStub5 (string requestUrl, string path)
: this (requestUrl, path, null)
{
}
public HttpContextStub5 (string requestUrl, string path, string appPath)
: base (requestUrl, path, appPath)
{
wrapper = new FakeHttpRequestWrapper (requestUrl, path, appPath);
}
}
#endif
public class MyStopRoutingHandler : StopRoutingHandler
{
public IHttpHandler CallGetHttpHandler (RequestContext rc)
{
return GetHttpHandler (rc);
}
}
public class MyUrlRoutingHandler : UrlRoutingHandler
{
public void DoProcessRequest (HttpContextBase httpContext)
{
ProcessRequest (httpContext);
}
protected override void VerifyAndProcessRequest (IHttpHandler httpHandler, HttpContextBase httpContext)
{
throw new ApplicationException ("MyUrlRoutingHandler");
}
}
public class ErrorRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler (RequestContext requestContext)
{
throw new ApplicationException ("ErrorRouteHandler");
}
}
public class MyRouteHandler : IRouteHandler
{
public MyRouteHandler ()
: this (new MyHttpHandler ())
{
}
public MyRouteHandler (IHttpHandler handler)
{
this.handler = handler;
}
IHttpHandler handler;
public IHttpHandler GetHttpHandler (RequestContext requestContext)
{
return handler;
}
}
public class MyHttpHandler : IHttpHandler
{
public bool IsReusable {
get { return true; }
}
public void ProcessRequest (HttpContext ctx)
{
throw new MyException ("HOGE");
}
}
public class MyException : Exception
{
public MyException (string msg) : base (msg) {}
}
public class NullRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler (RequestContext requestContext)
{
return null;
}
}
public class MyRoute : Route
{
public MyRoute (string url, IRouteHandler handler)
: this (url, handler, null)
{
}
public MyRoute (string url, IRouteHandler handler, Exception ex)
: base (url, handler)
{
this.ex = ex;
}
Exception ex;
public override VirtualPathData GetVirtualPath (RequestContext requestContext, RouteValueDictionary values)
{
if (ex != null)
throw ex;
return base.GetVirtualPath (requestContext, values);
}
public bool DoProcessConstraint (HttpContextBase httpContext, object constraint, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
return ProcessConstraint (httpContext, constraint, parameterName, values, routeDirection);
}
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MonoTests.Common
{
class UnknownResponseHeader
{
private string name;
private string value;
public UnknownResponseHeader (string name, string value)
{
this.name = name;
this.value = value;
}
public string Name
{
get { return name; }
}
public string Value
{
get { return value; }
}
}
}

View File

@@ -0,0 +1,150 @@
//
// UrlRoutingHandlerTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Web;
using System.Web.Routing;
using NUnit.Framework;
namespace MonoTests.System.Web.Routing
{
[TestFixture]
public class UrlRoutingHandlerTest
{
[SetUp]
public void SetUp ()
{
RouteTable.Routes.Clear ();
}
[Test]
public void SetRouteCollectionNull ()
{
var h = new MyUrlRoutingHandler ();
RouteTable.Routes.Add (new Route (null, null));
Assert.IsNotNull (h.RouteCollection, "#1");
Assert.AreEqual (RouteTable.Routes, h.RouteCollection, "#1-2");
h.RouteCollection = null;
Assert.IsNotNull (h.RouteCollection, "#2");
Assert.AreEqual (RouteTable.Routes, h.RouteCollection, "#2-2");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ProcessRequestNullArg ()
{
new MyUrlRoutingHandler ().DoProcessRequest (null);
}
[Test]
[ExpectedException (typeof (NotImplementedException))]
public void ProcessRequestForStubContext ()
{
var h = new MyUrlRoutingHandler ();
// it results in call to HttpContextBase.get_Request() and thus NIE.
h.DoProcessRequest (new HttpContextStub ());
}
[Test]
[ExpectedException (typeof (HttpException))]
public void ProcessRequestNoMatch ()
{
var h = new MyUrlRoutingHandler ();
Assert.AreEqual (0, h.RouteCollection.Count, "#1");
h.DoProcessRequest (new HttpContextStub ("~/foo"));
}
[Test]
[ExpectedException (typeof (NotImplementedException))]
public void ProcessRequestPathInfoNIE ()
{
var h = new MyUrlRoutingHandler ();
var r = new Route ("foo", null);
h.RouteCollection.Add (r);
// it internally calls RouteCollection.GetRouteData()
// and borks at HttpContextStub.Request.PathInfo NIE.
h.DoProcessRequest (new HttpContextStub ("~/foo"));
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ProcessRequestNoHandler ()
{
var h = new MyUrlRoutingHandler ();
var r = new Route ("foo", null);
h.RouteCollection.Add (r);
h.DoProcessRequest (new HttpContextStub ("~/foo", String.Empty));
}
[Test]
[ExpectedException (typeof (HttpException))]
public void ProcessRequestNoMatch2 ()
{
var h = new MyUrlRoutingHandler ();
var r = new Route ("foo", null);
h.RouteCollection.Add (r);
h.DoProcessRequest (new HttpContextStub ("~/bar", String.Empty));
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ProcessRequestMatchNoHandler ()
{
var h = new MyUrlRoutingHandler ();
var r = new Route ("foo", null);
h.RouteCollection.Add (r);
h.DoProcessRequest (new HttpContextStub ("~/foo", String.Empty));
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ProcessRequestMatchStop ()
{
var h = new MyUrlRoutingHandler ();
var r = new Route ("foo", new StopRoutingHandler ());
h.RouteCollection.Add (r);
h.DoProcessRequest (new HttpContextStub ("~/foo", String.Empty));
// thrown by StopRoutingHandler.GetHttpHandler().
}
[Test]
public void ProcessRequestMatchError ()
{
var h = new MyUrlRoutingHandler ();
var r = new Route ("foo", new ErrorRouteHandler ());
h.RouteCollection.Add (r);
try {
h.DoProcessRequest (new HttpContextStub ("~/foo", String.Empty));
Assert.Fail ("#1");
} catch (ApplicationException ex) {
Assert.AreEqual ("ErrorRouteHandler", ex.Message, "#2");
}
}
}
}

View File

@@ -0,0 +1,251 @@
//
// UrlRoutingModuleTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Web;
using System.Web.Routing;
using NUnit.Framework;
namespace MonoTests.System.Web.Routing
{
[TestFixture]
public class UrlRoutingModuleTest
{
[SetUp]
public void SetUp ()
{
RouteTable.Routes.Clear ();
}
[Test]
public void SetRouteCollectionNull ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new Route (null, null));
Assert.IsNotNull (m.RouteCollection, "#1");
Assert.AreEqual (RouteTable.Routes, m.RouteCollection, "#1-2");
m.RouteCollection = null;
Assert.IsNotNull (m.RouteCollection, "#2");
Assert.AreEqual (RouteTable.Routes, m.RouteCollection, "#2-2");
}
// PostMapRequestHandler
[Test]
public void PostMapRequestHandlerNoMatch ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new MyRoute (null, null));
m.PostMapRequestHandler (new HttpContextStub2 ());
}
[Test]
public void PostMapRequestHandlerNoPath ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new MyRoute ("foo/bar", new MyRouteHandler ()));
// ... huh? no NIE? what does it do then?
m.PostMapRequestHandler (new HttpContextStub2 ("~/foo/bar", null));
}
// PostResolveRequestCache
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void PostResolveRequestCacheNullRouteHandler ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new MyRoute ("foo/bar", null));
m.PostResolveRequestCache (new HttpContextStub2 ("~/foo/bar", null));
}
#if !NET_4_0
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void PostResolveRequestCacheNullHttpHandler ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new MyRoute ("foo/bar", new NullRouteHandler ()));
m.PostResolveRequestCache (new HttpContextStub2 ("~/foo/bar", null));
}
#endif
[Test]
[ExpectedException (typeof (NotImplementedException))]
public void PostResolveRequestCacheNoPath ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new MyRoute ("foo/bar", new MyRouteHandler ()));
// it tries to get HttpContextBase.Request.Path and causes NIE.
m.PostResolveRequestCache (new HttpContextStub2 ("~/foo/bar", null));
}
#if !NET_4_0
[Test]
public void PostResolveRequestCacheCallRewritePath ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
var hc = new HttpContextStub2 ("~/x/y", "z");
try {
m.PostResolveRequestCache (hc);
Assert.Fail ("#1");
} catch (ApplicationException ex) {
Assert.AreEqual ("~/UrlRouting.axd", ex.Message, "#2");
}
}
[Test]
public void PostResolveRequestCacheModifiedPath ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
var hc = new HttpContextStub2 ("~/x/y", "z", "apppath");
hc.SetResponse (new HttpResponseStub (2));
try {
m.PostResolveRequestCache (hc);
Assert.Fail ("#1");
} catch (ApplicationException ex) {
Assert.AreEqual ("~/UrlRouting.axd", ex.Message, "#2");
}
}
#endif
[Test]
public void PostResolveRequestCache ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
#if NET_4_0
var hc = new HttpContextStub4 ("~/x/y", "z", "apppath", false);
#else
var hc = new HttpContextStub3 ("~/x/y", "z", "apppath", false);
#endif
hc.SetResponse (new HttpResponseStub (2));
m.PostResolveRequestCache (hc);
#if NET_4_0
Assert.AreEqual (null, hc.RewrittenPath, "#1");
#else
Assert.AreEqual ("~/UrlRouting.axd", hc.RewrittenPath, "#1");
#endif
// it internally stores the handler
}
[Test]
public void PostResolveRequestCacheStopRoutingHttpHandler ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new MyRoute ("foo/bar", new StopRoutingHandler ()));
var hc = new HttpContextStub3 ("~/foo/bar", String.Empty, "apppath", false);
m.PostResolveRequestCache (hc);
Assert.IsNull (hc.RewrittenPath, "StopRoutingHandler should stop before the path is rewritten");
}
[Test]
[Ignore ("looks like RouteExistingFiles ( = false) does not affect... so this test needs more investigation")]
public void PostResolveRequestCachePathToExistingFile ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new MyRoute ("~/{foo}/{bar}", new MyRouteHandler ()));
var hc = new HttpContextStub2 ("~/hoge/fuga", String.Empty, ".");
// it tries to get HttpContextBase.Response, so set it.
hc.SetResponse (new HttpResponseStub (3));
try {
m.PostResolveRequestCache (hc);
Assert.Fail ("#1");
} catch (ApplicationException ex) {
Assert.AreEqual ("~/UrlRouting.axd", ex.Message, "#2");
}
}
[Test]
[ExpectedException (typeof (NotImplementedException))]
public void Pipeline1 ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
var hc = new HttpContextStub3 ("~/x/y", "z", "apppath", false);
hc.SetResponse (new HttpResponseStub (2));
m.PostResolveRequestCache (hc);
Assert.AreEqual ("~/UrlRouting.axd", hc.RewrittenPath, "#1");
// It tries to set Handler and causes NIE
m.PostMapRequestHandler (hc);
}
[Test]
public void Pipeline2 ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
#if NET_4_0
var hc = new HttpContextStub4 ("~/x/y", "z", "apppath", true);
#else
var hc = new HttpContextStub3 ("~/x/y", "z", "apppath", true);
#endif
hc.HttpHandler = new MyHttpHandler ();
hc.SetResponse (new HttpResponseStub (2));
m.PostResolveRequestCache (hc);
#if NET_4_0
Assert.AreEqual (null, hc.RewrittenPath, "#1");
#else
Assert.AreEqual ("~/UrlRouting.axd", hc.RewrittenPath, "#1");
#endif
// It tries to set Handler and causes NIE
m.PostMapRequestHandler (hc);
}
[Test]
#if !NET_4_0
[ExpectedException (typeof (ApplicationException))]
#endif
public void Pipeline3 ()
{
var m = new UrlRoutingModule ();
RouteTable.Routes.Add (new MyRoute ("{foo}/{bar}", new MyRouteHandler ()));
#if NET_4_0
var hc = new HttpContextStub5 ("~/x/y", String.Empty, "apppath");
#else
var hc = new HttpContextStub2 ("~/x/y", String.Empty, "apppath");
#endif
hc.SetResponse (new HttpResponseStub (2));
#if NET_4_0
Assert.IsNull (m.RouteCollection.GetRouteData (hc), "#0");
#else
Assert.IsNotNull (m.RouteCollection.GetRouteData (hc), "#0");
m.PostResolveRequestCache (hc);
try {
m.PostMapRequestHandler (hc);
Assert.Fail ("#1");
} catch (ApplicationException ex) {
Assert.AreEqual ("~/UrlRouting.axd", ex.Message, "#2");
}
#endif
}
}
}

View File

@@ -0,0 +1,46 @@
//
// VirtualPathDataTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell Inc. http://novell.com
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Web;
using System.Web.Routing;
using NUnit.Framework;
namespace MonoTests.System.Web.Routing
{
[TestFixture]
public class VirtualPathDataTest
{
[Test]
public void ConstructorNullArgs ()
{
new VirtualPathData (null, null);
}
}
}