Ver código fonte

2006-01-30 Gonzalo Paniagua Javier <[email protected]>

	* VirtualPathUtilityTest.cs: added new tests.


svn path=/trunk/mcs/; revision=56279
Gonzalo Paniagua Javier 20 anos atrás
pai
commit
239ea5d7fd

+ 4 - 0
mcs/class/System.Web/Test/System.Web/ChangeLog

@@ -1,3 +1,7 @@
+2006-01-30 Gonzalo Paniagua Javier <[email protected]>
+
+	* VirtualPathUtilityTest.cs: added new tests.
+
 2005-12-08 Gonzalo Paniagua Javier <[email protected]>
 
 	* HttpRequestTest.cs: ignore test.

+ 233 - 47
mcs/class/System.Web/Test/System.Web/VirtualPathUtilityTest.cs

@@ -3,8 +3,9 @@
 //
 // Author:
 //	Chris Toshok  <[email protected]>
+//	Gonzalo Paniagua Javier ([email protected])
 //
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005,2006 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
@@ -30,6 +31,7 @@
 
 using System;
 using System.Web;
+using VPU = System.Web.VirtualPathUtility;
 
 using NUnit.Framework;
 
@@ -40,40 +42,40 @@ namespace MonoTests.System.Web {
 		[Test]
 		public void AppendTrailingSlash ()
 		{
-			Assert.AreEqual ("/hithere/", VirtualPathUtility.AppendTrailingSlash ("/hithere"), "A1");
-			Assert.AreEqual ("/hithere/", VirtualPathUtility.AppendTrailingSlash ("/hithere/"), "A2");
-			Assert.AreEqual ("/", VirtualPathUtility.AppendTrailingSlash ("/"), "A3");
-			Assert.AreEqual ("", VirtualPathUtility.AppendTrailingSlash (""), "A4");
-			Assert.AreEqual (null, VirtualPathUtility.AppendTrailingSlash (null), "A5");
+			Assert.AreEqual ("/hithere/", VPU.AppendTrailingSlash ("/hithere"), "A1");
+			Assert.AreEqual ("/hithere/", VPU.AppendTrailingSlash ("/hithere/"), "A2");
+			Assert.AreEqual ("/", VPU.AppendTrailingSlash ("/"), "A3");
+			Assert.AreEqual ("", VPU.AppendTrailingSlash (""), "A4");
+			Assert.AreEqual (null, VPU.AppendTrailingSlash (null), "A5");
 		}
 
 		[Test]
 		public void Combine ()
 		{
-			Assert.AreEqual ("/there", VirtualPathUtility.Combine ("/hi", "there"), "A1");
-			Assert.AreEqual ("/hi/you", VirtualPathUtility.Combine ("/hi/there", "you"), "A2");
-			Assert.AreEqual ("/hi/there/you", VirtualPathUtility.Combine ("/hi/there/", "you"), "A3");
+			Assert.AreEqual ("/there", VPU.Combine ("/hi", "there"), "A1");
+			Assert.AreEqual ("/hi/you", VPU.Combine ("/hi/there", "you"), "A2");
+			Assert.AreEqual ("/hi/there/you", VPU.Combine ("/hi/there/", "you"), "A3");
 		}
 
 		[Test]
 		[ExpectedException (typeof (ArgumentException))]
 		public void Combine_ArgException1 ()
 		{
-			Assert.AreEqual ("hi/there/you", VirtualPathUtility.Combine ("hi/there", "you"), "A1");
+			Assert.AreEqual ("hi/there/you", VPU.Combine ("hi/there", "you"), "A1");
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (ArgumentNullException))]
 		public void Combine_ArgException2 ()
 		{
-			Assert.AreEqual ("hi/there", VirtualPathUtility.Combine ("hi/there", null), "A1");
+			Assert.AreEqual ("hi/there", VPU.Combine ("hi/there", null), "A1");
 		}
 
 		[Test]
 		[ExpectedException (typeof (ArgumentNullException))]
 		public void Combine_ArgException3 ()
 		{
-			Assert.AreEqual ("hi/there", VirtualPathUtility.Combine (null, "there"), "A1");
+			Assert.AreEqual ("hi/there", VPU.Combine (null, "there"), "A1");
 		}
 
 		[Test]
@@ -85,7 +87,7 @@ namespace MonoTests.System.Web {
 		*/
 		public void Combine_ArgException4 ()
 		{
-			Assert.AreEqual ("/you", VirtualPathUtility.Combine ("", "you"), "A1");
+			Assert.AreEqual ("/you", VPU.Combine ("", "you"), "A1");
 		}
 
 		[Test]
@@ -97,15 +99,15 @@ namespace MonoTests.System.Web {
 		*/
 		public void Combine_ArgException5 ()
 		{
-			Assert.AreEqual ("/hi", VirtualPathUtility.Combine ("/hi", ""), "A1");
+			Assert.AreEqual ("/hi", VPU.Combine ("/hi", ""), "A1");
 		}
 
 		[Test]
 		public void GetDirectory ()
 		{
-			Assert.AreEqual ("/hi/", VirtualPathUtility.GetDirectory ("/hi/there"), "A1");
-			Assert.AreEqual ("/hi/", VirtualPathUtility.GetDirectory ("/hi/there/"), "A2");
-			Assert.AreEqual (null, VirtualPathUtility.GetDirectory ("/"), "A3");
+			Assert.AreEqual ("/hi/", VPU.GetDirectory ("/hi/there"), "A1");
+			Assert.AreEqual ("/hi/", VPU.GetDirectory ("/hi/there/"), "A2");
+			Assert.AreEqual (null, VPU.GetDirectory ("/"), "A3");
 		}
 
 		[Test]
@@ -117,103 +119,103 @@ namespace MonoTests.System.Web {
 		 */
 		public void GetDirectory_ArgException1 ()
 		{
-			Assert.AreEqual ("", VirtualPathUtility.GetDirectory (""), "A1");
+			Assert.AreEqual ("", VPU.GetDirectory (""), "A1");
 		}
 
 		[Test]
 		public void GetExtension ()
 		{
-			Assert.AreEqual (".aspx", VirtualPathUtility.GetExtension ("/hi/index.aspx"), "A1");
-			Assert.AreEqual (".aspx", VirtualPathUtility.GetExtension ("index.aspx"), "A2");
-			Assert.AreEqual ("", VirtualPathUtility.GetExtension ("/hi/index"), "A3");
+			Assert.AreEqual (".aspx", VPU.GetExtension ("/hi/index.aspx"), "A1");
+			Assert.AreEqual (".aspx", VPU.GetExtension ("index.aspx"), "A2");
+			Assert.AreEqual ("", VPU.GetExtension ("/hi/index"), "A3");
 		}
 
 		[Test]
 		[ExpectedException (typeof (ArgumentNullException))]
 		public void GetExtension_ArgException1 ()
 		{
-			Assert.AreEqual (null, VirtualPathUtility.GetExtension (null), "A1");
+			Assert.AreEqual (null, VPU.GetExtension (null), "A1");
 		}
 
 		[Test]
 		[ExpectedException (typeof (ArgumentNullException))]
 		public void GetExtension_ArgException2 ()
 		{
-			Assert.AreEqual ("", VirtualPathUtility.GetExtension (""), "A1");
+			Assert.AreEqual ("", VPU.GetExtension (""), "A1");
 		}
 
 		[Test]
 		public void GetFileName ()
 		{
-			Assert.AreEqual ("index.aspx", VirtualPathUtility.GetFileName ("/hi/index.aspx"), "A1");
-			Assert.AreEqual ("hi", VirtualPathUtility.GetFileName ("/hi/"), "A2");
+			Assert.AreEqual ("index.aspx", VPU.GetFileName ("/hi/index.aspx"), "A1");
+			Assert.AreEqual ("hi", VPU.GetFileName ("/hi/"), "A2");
 		}
 
 		[Test]
 		[ExpectedException (typeof (ArgumentNullException))]
 		public void GetFileName_ArgException1 ()
 		{
-			Assert.AreEqual (null, VirtualPathUtility.GetFileName (null), "A1");
+			Assert.AreEqual (null, VPU.GetFileName (null), "A1");
 		}
 
 		[Test]
 		[ExpectedException (typeof (ArgumentNullException))]
 		public void GetFileName_ArgException2 ()
 		{
-			Assert.AreEqual ("", VirtualPathUtility.GetFileName (""), "A1");
+			Assert.AreEqual ("", VPU.GetFileName (""), "A1");
 		}
 
 		[Test]
 		[ExpectedException (typeof (ArgumentException))]
 		public void GetFileName_ArgException3 ()
 		{
-			Assert.AreEqual ("index.aspx", VirtualPathUtility.GetFileName ("index.aspx"), "A1");
+			Assert.AreEqual ("index.aspx", VPU.GetFileName ("index.aspx"), "A1");
 		}
 
 		[Test]
 		public void IsAbsolute ()
 		{
-			Assert.IsTrue (VirtualPathUtility.IsAbsolute ("/"), "A1");
-			Assert.IsTrue (VirtualPathUtility.IsAbsolute ("/hi/there"), "A2");
-			Assert.IsFalse (VirtualPathUtility.IsAbsolute ("hi/there"), "A3");
-			Assert.IsFalse (VirtualPathUtility.IsAbsolute ("./hi"), "A4");
+			Assert.IsTrue (VPU.IsAbsolute ("/"), "A1");
+			Assert.IsTrue (VPU.IsAbsolute ("/hi/there"), "A2");
+			Assert.IsFalse (VPU.IsAbsolute ("hi/there"), "A3");
+			Assert.IsFalse (VPU.IsAbsolute ("./hi"), "A4");
 		}
 
 		[Test]
 		[ExpectedException (typeof (ArgumentNullException))]
 		public void IsAbsolute_ArgException1 ()
 		{
-			Assert.IsFalse (VirtualPathUtility.IsAbsolute (""), "A1");
+			Assert.IsFalse (VPU.IsAbsolute (""), "A1");
 		}
 
 		[Test]
 		[ExpectedException (typeof (ArgumentNullException))]
 		public void IsAbsolute_ArgException2 ()
 		{
-			Assert.IsFalse (VirtualPathUtility.IsAbsolute (null), "A1");
+			Assert.IsFalse (VPU.IsAbsolute (null), "A1");
 		}
 
 		[Test]
 		public void IsAppRelative ()
 		{
-			Assert.IsTrue (VirtualPathUtility.IsAppRelative ("~/Stuff"), "A1");
-			Assert.IsFalse (VirtualPathUtility.IsAppRelative ("./Stuff"), "A2");
-			Assert.IsFalse (VirtualPathUtility.IsAppRelative ("/Stuff"), "A3");
-			Assert.IsFalse (VirtualPathUtility.IsAppRelative ("/"), "A4");
+			Assert.IsTrue (VPU.IsAppRelative ("~/Stuff"), "A1");
+			Assert.IsFalse (VPU.IsAppRelative ("./Stuff"), "A2");
+			Assert.IsFalse (VPU.IsAppRelative ("/Stuff"), "A3");
+			Assert.IsFalse (VPU.IsAppRelative ("/"), "A4");
 		}
 
 		[Test]
 		[ExpectedException (typeof (ArgumentNullException))]
 		public void IsAppRelative_ArgException1 ()
 		{
-			Assert.IsFalse (VirtualPathUtility.IsAppRelative (""), "A1");
+			Assert.IsFalse (VPU.IsAppRelative (""), "A1");
 		}
 
 		[Test]
 		[ExpectedException (typeof (ArgumentNullException))]
 		public void IsAppRelative_ArgException2 ()
 		{
-			Assert.IsFalse (VirtualPathUtility.IsAppRelative (null), "A1");
+			Assert.IsFalse (VPU.IsAppRelative (null), "A1");
 		}
 
 #if false
@@ -226,20 +228,204 @@ namespace MonoTests.System.Web {
 		*/
 		public void MakeRelative ()
 		{
-			Assert.AreEqual ("../bar", VirtualPathUtility.MakeRelative ("~/foo/hi", "~/foo/bar"), "A1");
+			Assert.AreEqual ("../bar", VPU.MakeRelative ("~/foo/hi", "~/foo/bar"), "A1");
 		}
 #endif
 
 		[Test]
 		public void RemoveTrailingSlash ()
 		{
-			Assert.AreEqual ("/hi/there", VirtualPathUtility.RemoveTrailingSlash ("/hi/there/"), "A1");
-			Assert.AreEqual ("/hi/there", VirtualPathUtility.RemoveTrailingSlash ("/hi/there"), "A2");
-			Assert.AreEqual ("/", VirtualPathUtility.RemoveTrailingSlash ("/"), "A3");
-			Assert.AreEqual (null, VirtualPathUtility.RemoveTrailingSlash (""), "A4");
-			Assert.AreEqual (null, VirtualPathUtility.RemoveTrailingSlash (null), "A5");
+			Assert.AreEqual ("/hi/there", VPU.RemoveTrailingSlash ("/hi/there/"), "A1");
+			Assert.AreEqual ("/hi/there", VPU.RemoveTrailingSlash ("/hi/there"), "A2");
+			Assert.AreEqual ("/", VPU.RemoveTrailingSlash ("/"), "A3");
+			Assert.AreEqual (null, VPU.RemoveTrailingSlash (""), "A4");
+			Assert.AreEqual (null, VPU.RemoveTrailingSlash (null), "A5");
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Combine1 ()
+		{
+			VPU.Combine (null, "something");
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void Combine2 ()
+		{
+			VPU.Combine ("something", null);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void GetDirectory1 ()
+		{
+			VPU.GetDirectory (null);
+		}
+		
+		[Test]
+		[ExpectedException (typeof (ArgumentException))]
+		public void GetDirectory2 ()
+		{
+			VPU.GetDirectory ("");
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void GetDirectory3 ()
+		{
+			VPU.GetDirectory ("hola");
+		}
+
+		[Test]
+		public void GetDirectory4 ()
+		{
+			Assert.AreEqual ("/direc/", VPU.GetDirectory ("/direc/somefilenoextension"));
+			Assert.AreEqual ("/direc/", VPU.GetDirectory ("/direc/somefile.aspx"));
+			Assert.AreEqual ("/direc/", VPU.GetDirectory ("/////direc///somefile.aspx"));
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void GetExtension1 ()
+		{
+			VPU.GetExtension (null);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void GetExtension2 ()
+		{
+			// Amazing.
+			VPU.GetExtension ("");
+		}
+
+		[Test]
+		public void GetExtension3 ()
+		{
+			Assert.AreEqual ("", VPU.GetExtension ("/direc/somefilenoextension"));
+			Assert.AreEqual ("", VPU.GetExtension ("/"));
+			Assert.AreEqual (".aspx", VPU.GetDirectory ("/////direc///somefile.aspx"));
+		}
+
+		[Test]
+		public void GetFileName1 ()
+		{
+			Assert.AreEqual ("", VPU.GetFileName ("/"));
+			Assert.AreEqual ("hola", VPU.GetFileName ("/hola"));
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void GetFileName2 ()
+		{
+			VPU.GetFileName (null);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void GetFileName3 ()
+		{
+			VPU.GetFileName ("");
+		}
+
+		[Test]
+		[ExpectedException (typeof (NullReferenceException))]
+		public void MakeRelative1 ()
+		{
+			VPU.MakeRelative (null, "");
+		}
+
+		[Test]
+		[ExpectedException (typeof (NullReferenceException))]
+		public void MakeRelative2 ()
+		{
+			VPU.MakeRelative ("", null);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentOutOfRangeException))]
+		public void MakeRelative3 ()
+		{
+			VPU.MakeRelative ("/", "i");
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentOutOfRangeException))]
+		public void MakeRelative4 ()
+		{
+			VPU.MakeRelative ("aa", "/i");
+		}
+
+		[Test]
+		public void MakeRelative5 ()
+		{
+			Assert.AreEqual ("", VPU.MakeRelative ("", ""));
+			Assert.AreEqual ("", VPU.MakeRelative ("/something", ""));
+			Assert.AreEqual ("./", VPU.MakeRelative ("/", "/"));
+		}
+
+		[Test]
+		public void RemoveTrailingSlash2 ()
+		{
+			Assert.AreEqual (null, VPU.RemoveTrailingSlash (null));
+			Assert.AreEqual (null, VPU.RemoveTrailingSlash (""));
+			Assert.AreEqual ("/", VPU.RemoveTrailingSlash ("/"));
+			Assert.AreEqual ("////", VPU.RemoveTrailingSlash ("/////"));
+			Assert.AreEqual ("/pepe", VPU.RemoveTrailingSlash ("/pepe"));
+			Assert.AreEqual ("/pepe", VPU.RemoveTrailingSlash ("/pepe/"));
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void ToAbsolute1 ()
+		{
+			VPU.ToAbsolute (null);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void ToAbsolute2 ()
+		{
+			VPU.ToAbsolute ("");
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentException))]
+		public void ToAbsolute3 ()
+		{
+			VPU.ToAbsolute ("..");
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentException))]
+		public void ToAbsolute4 ()
+		{
+			VPU.ToAbsolute ("...");
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentException))]
+		public void ToAbsolute5 ()
+		{
+			VPU.ToAbsolute ("../blah");
+		}
+
+		[Test]
+		[ExpectedException (typeof (HttpException))]
+		public void ToAbsolute6 ()
+		{
+			VPU.ToAbsolute ("~/");
+		}
+
+		[Test]
+		[ExpectedException (typeof (HttpException))]
+		public void ToAbsolute7 ()
+		{
+			Assert.AreEqual ("/", VPU.ToAbsolute ("/"));
 		}
 	}
 }
 
 #endif
+