2009-05-26 Marek Habersack <mhabersack@novell.com>
authorMarek Habersack <grendel@twistedcode.net>
Tue, 26 May 2009 12:42:15 +0000 (12:42 -0000)
committerMarek Habersack <grendel@twistedcode.net>
Tue, 26 May 2009 12:42:15 +0000 (12:42 -0000)
* Test/System.Web.UI/ScriptReferenceBaseTest.cs: added tests for
ReplaceExtension

* System.Web.Extensions_test.dll.sources: added
System.Web.UI/ScriptReferenceBaseTest.cs

svn path=/trunk/mcs/; revision=134757

mcs/class/System.Web.Extensions/ChangeLog
mcs/class/System.Web.Extensions/System.Web.Extensions_test.dll.sources
mcs/class/System.Web.Extensions/System.Web.UI/ScriptReferenceBase.cs
mcs/class/System.Web.Extensions/Test/System.Web.UI/ScriptReferenceBaseTest.cs [new file with mode: 0644]

index 1abdcfdf707d60df37086e984e35974830b91e72..7c4a1277635fa8a50a45b5f2ae50cbdb0289065f 100644 (file)
@@ -1,5 +1,11 @@
 2009-05-26  Marek Habersack  <mhabersack@novell.com>
 
+       * Test/System.Web.UI/ScriptReferenceBaseTest.cs: added tests for
+       ReplaceExtension
+
+       * System.Web.Extensions_test.dll.sources: added
+       System.Web.UI/ScriptReferenceBaseTest.cs
+
        * System.Web.Extensions.dll.sources: added
        System.Web.UI/ScriptReferenceBase.cs
 
index 69c557511fd7f30c1064e3c03e1cea9a1ea7b4de..0f0f0e6bbbdd006799adfb4f9368b4ad4b08e0fd 100644 (file)
@@ -38,6 +38,7 @@ System.Web.Script.Serialization/JavaScriptSerializerTest.cs
 System.Web.UI/ScriptBehaviorDescriptorTest.cs
 System.Web.UI/ScriptComponentDescriptorTest.cs
 System.Web.UI/ScriptControlDescriptorTest.cs
+System.Web.UI/ScriptReferenceBaseTest.cs
 System.Web.UI/UpdateProgressTest.cs
 System.Web.UI.WebControls/EventRecorder.cs
 System.Web.UI.WebControls/ListViewTest.cs
index e9a76eefbf2155aaed2a21935fecf45c5282c540..bb216aa846679b522e1154cf2ac240d142c98db7 100644 (file)
@@ -67,10 +67,17 @@ namespace System.Web.UI
                protected internal abstract string GetUrl (ScriptManager scriptManager, bool zip);
                protected internal abstract bool IsFromSystemWebExtensions ();
 
+               // This method is an example of particularily bad coding - .NET performs NO checks
+               // on pathOrName!
                protected static string ReplaceExtension (string pathOrName)
                {
-                       return null;
+                       // emulate .NET behavior
+                       if (pathOrName == null)
+                               throw new NullReferenceException ();
+                       
+                       // We should check the length, but since .NET doesn't do that, we won't
+                       // either. Ugh.
+                       return pathOrName.Substring (0, pathOrName.Length - 2) + "debug.js";
                }
-               
        }
 }
diff --git a/mcs/class/System.Web.Extensions/Test/System.Web.UI/ScriptReferenceBaseTest.cs b/mcs/class/System.Web.Extensions/Test/System.Web.UI/ScriptReferenceBaseTest.cs
new file mode 100644 (file)
index 0000000..adb502f
--- /dev/null
@@ -0,0 +1,86 @@
+//
+// ScriptReferenceBaseTest.cs
+//
+// Author:
+//   Marek Habersack <mhabersack@novell.com>
+//
+// (C) 2007 Mainsoft, Inc.  http://www.mainsoft.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.Text;
+using NUnit.Framework;
+using System.Web.UI;
+
+namespace MonoTests.System.Web.UI
+{
+       class MyScriptReference : ScriptReferenceBase
+       {
+               protected override string GetUrl (ScriptManager scriptManager, bool zip)
+               {
+                       return null;
+               }
+       
+               protected override bool IsFromSystemWebExtensions ()
+               {
+                       return false;
+               }
+
+               public static string DoReplaceExtension (string path)
+               {
+                       return ReplaceExtension (path);
+               }
+       }
+       
+       [TestFixture]
+       public class ScriptReferenceBaseTest
+       {
+               [Test (Description="No checks are performed by .NET")]
+               [ExpectedException (typeof (NullReferenceException))]
+               public void ReplaceExtensionNullPath ()
+               {
+                       MyScriptReference.DoReplaceExtension (null);
+               }
+
+               [Test (Description="No checks are performed by .NET")]
+               [ExpectedException (typeof (ArgumentOutOfRangeException))]
+               public void ReplaceExtensionShortPath ()
+               {
+                       MyScriptReference.DoReplaceExtension (String.Empty);
+               }
+
+               [Test]
+               public void ReplaceExtension ()
+               {
+                       string ext = MyScriptReference.DoReplaceExtension ("js");
+                       Assert.AreEqual ("debug.js", ext, "#1");
+
+                       ext = MyScriptReference.DoReplaceExtension ("testjs");
+                       Assert.AreEqual ("testdebug.js", ext, "#2");
+                       
+                       ext = MyScriptReference.DoReplaceExtension ("test.js");
+                       Assert.AreEqual ("test.debug.js", ext, "#3");
+               }
+       }
+}