Browse Source

2010-01-22 Marek Habersack <[email protected]>

	* SubstitutionResponseElement.cs: implemented correct
	(de)serialization of the Callback delegate.

	* OutputCache.cs: implemented Serialize, Deserialize,
	DefaultProviderName and Providers.

2010-01-22  Marek Habersack  <[email protected]>

	* AssertExtensions.cs: added AreEqual method for comparing byte
	arrays.

2010-01-22  Marek Habersack  <[email protected]>

	* OutputCacheTest.cs: added

svn path=/trunk/mcs/; revision=150080
Marek Habersack 16 years ago
parent
commit
bd08ce5b8b

+ 47 - 15
mcs/class/System.Web.DynamicData/Test/Common/AssertExtensions.cs

@@ -5,46 +5,78 @@ using NUnit.Framework;
 
 namespace MonoTests.Common
 {
-	delegate void AssertThrowsDelegate ();
+	delegate void AssertThrowsDelegate();
 
 	static class AssertExtensions
 	{
+		public static void AreEqual (byte[] expected, byte[] data, string message)
+		{
+			if (expected == null) {
+				if (data == null)
+					return;
+				Assert.Fail ("{0}{1}Expected: null{1}Got: byte array with {2} elements and of rank {3}{1}",
+					message, Environment.NewLine, data.Length, data.Rank);
+			}
+
+			if (data == null)
+				Assert.Fail ("{0}{1}Expected: byte array with {2} elements and rank {3}{1}Got: null{1}",
+					message, Environment.NewLine, expected.Length, expected.Rank);
+
+			if (expected.Rank > 1)
+				Assert.Fail ("Only single-dimensional arrays are supported.");
+
+			if (expected.Rank != data.Rank || expected.Length != data.Length)
+				Assert.Fail ("{0}{1}Expected: byte array with {2} elements and rank {3}{1}Got: byte array with {4} elements and rank {5}{1}",
+					message, Environment.NewLine, expected.Length, expected.Rank, data.Length, data.Rank);
+
+			int max = expected.Length;
+			for (int i = 0; i < max; i++) {
+				if (expected[i] != data[i])
+					Assert.Fail ("{0}{1}Arrays differ at index {2}.{1}Expected 0x{3:X} got 0x{4:X}{1}",
+						message, Environment.NewLine, i, expected[i], data[i]);
+			}
+		}
+
 		public static void Throws<ET> (AssertThrowsDelegate code, string message)
 		{
-			Throws (typeof (ET), code, message);
+			Throws(typeof(ET), code, message);
 		}
 
-		public static void Throws (Type exceptionType, AssertThrowsDelegate code, string message)
+		public static void Throws(Type exceptionType, AssertThrowsDelegate code, string message)
 		{
 			if (code == null)
-				Assert.Fail ("No code provided for the test.");
+				Assert.Fail("No code provided for the test.");
 
 			Exception exception = null;
-			try {
-				code ();
-			} catch (Exception ex) {
+			try
+			{
+				code();
+			}
+			catch (Exception ex)
+			{
 				exception = ex;
 			}
 
-			if (exceptionType == null) {
+			if (exceptionType == null)
+			{
 				if (exception == null)
-					Assert.Fail ("{0}{1}Expected: any exception thrown{1}But was: no exception thrown{1}",
+					Assert.Fail("{0}{1}Expected: any exception thrown{1}But was: no exception thrown{1}",
 						message, Environment.NewLine);
 				return;
 			}
 
-			if (exception == null || exception.GetType () != exceptionType)
-				Assert.Fail ("{0}{1}Expected: {2}{1}But was: {3}{1}{4}{1}",
+			if (exception == null || exception.GetType() != exceptionType)
+				Assert.Fail("{0}{1}Expected: {2}{1}But was: {3}{1}{4}{1}",
 				    message,
 				    Environment.NewLine,
 				    exceptionType,
-				    exception == null ? "no exception" : exception.GetType ().ToString (),
-				    exception == null ? "no exception" : exception.ToString ());
+				    exception == null ? "no exception" : exception.GetType().ToString(),
+				    exception == null ? "no exception" : exception.ToString());
 		}
 
-		public static void Throws (AssertThrowsDelegate code, string message)
+		public static void Throws(AssertThrowsDelegate code, string message)
 		{
-			Throws (null, code, message);
+			Throws(null, code, message);
 		}
 	}
 }

+ 5 - 0
mcs/class/System.Web.DynamicData/Test/Common/ChangeLog

@@ -1,3 +1,8 @@
+2010-01-22  Marek Habersack  <[email protected]>
+
+	* AssertExtensions.cs: added AreEqual method for comparing byte
+	arrays.
+
 2009-09-18  Marek Habersack  <[email protected]>
 
 	* TestsBasePage.cs: added an event ItemDataBinding, invoked

+ 8 - 0
mcs/class/System.Web/System.Web.Caching/ChangeLog

@@ -1,3 +1,11 @@
+2010-01-22  Marek Habersack  <[email protected]>
+
+	* SubstitutionResponseElement.cs: implemented correct
+	(de)serialization of the Callback delegate.
+
+	* OutputCache.cs: implemented Serialize, Deserialize,
+	DefaultProviderName and Providers.
+
 2010-01-21  Marek Habersack  <[email protected]>
 
 	* DatabaseNotEnabledForNotificationException.cs, OutputCache.cs,

+ 68 - 8
mcs/class/System.Web/System.Web.Caching/OutputCache.cs

@@ -26,7 +26,9 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Configuration;
 using System.IO;
+using System.Runtime.Serialization.Formatters.Binary;
 using System.Security.Permissions;
 using System.Web;
 using System.Web.Configuration;
@@ -35,12 +37,23 @@ namespace System.Web.Caching
 {
 	public static class OutputCache
 	{
+		static readonly object initLock = new object ();
+		static bool initialized;
+		static string defaultProviderName;
+		static OutputCacheProviderCollection providers;
+		
 		public static string DefaultProviderName {
-			get { throw new NotImplementedException (); }
+			get {
+				Init ();
+				return defaultProviderName;
+			}
 		}
 
 		public static OutputCacheProviderCollection Providers {
-			get { throw new NotImplementedException (); }
+			get {
+				Init ();
+				return providers;
+			}
 		}
 		
 		[SecurityPermission (SecurityAction.Assert, Flags = SecurityPermissionFlag.SerializationFormatter)]
@@ -49,20 +62,67 @@ namespace System.Web.Caching
 			if (stream == null)
 				throw new ArgumentNullException ("stream");
 
-			throw new NotImplementedException ();
-			
+			object o = new BinaryFormatter ().Deserialize (stream);
+			if (o == null || IsInvalidType (o))
+				throw new ArgumentException ("The provided parameter is not of a supported type for serialization and/or deserialization.");
+
+			return o;
 		}
 
 		[SecurityPermission (SecurityAction.Assert, Flags = SecurityPermissionFlag.SerializationFormatter)]
 		public static void Serialize (Stream stream, object data)
 		{
 			if (stream == null)
-				throw new ArgumentNullException ("stream");
+				throw new ArgumentNullException ("stream");			
+
+			// LAMESPEC: data == null doesn't throw ArgumentNullException
+			if (data == null || IsInvalidType (data))
+				throw new ArgumentException ("The provided parameter is not of a supported type for serialization and/or deserialization.");
 			
-			if (data == null)
-				throw new ArgumentNullException ("data");
+			new BinaryFormatter ().Serialize (stream, data);
+		}
+
+		static bool IsInvalidType (object data)
+		{
+			return !(data is MemoryResponseElement) &&
+				!(data is FileResponseElement) &&
+				!(data is SubstitutionResponseElement);
+		}
+
+		static void Init ()
+		{
+			if (initialized)
+				return;
+
+			lock (initLock) {
+				if (initialized)
+					return;
+				
+				var cfg = WebConfigurationManager.GetWebApplicationSection ("system.web/caching/outputCache") as OutputCacheSection;
+				ProviderSettingsCollection cfgProviders = cfg.Providers;
+
+				defaultProviderName = cfg.DefaultProviderName;
+				if (cfgProviders != null && cfgProviders.Count > 0) {
+					var coll = new OutputCacheProviderCollection ();
+
+					foreach (ProviderSettings ps in cfgProviders)
+						coll.Add (LoadProvider (ps));
+
+					coll.SetReadOnly ();
+					providers = coll;
+				}
+
+				initialized = true;
+			}
+		}
+
+		static OutputCacheProvider LoadProvider (ProviderSettings ps)
+		{
+			Type type = HttpApplication.LoadType (ps.Type, true);
+			var ret = Activator.CreateInstance (type) as OutputCacheProvider;
+			ret.Initialize (ps.Name, ps.Parameters);
 
-			throw new NotImplementedException ();
+			return ret;
 		}
 	}
 }

+ 17 - 0
mcs/class/System.Web/System.Web.Caching/SubstitutionResponseElement.cs

@@ -26,6 +26,9 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System;
+using System.Reflection;
+using System.Runtime.Serialization;
 using System.Security.Permissions;
 using System.Web;
 
@@ -35,6 +38,9 @@ namespace System.Web.Caching
 	[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Unrestricted)]
 	public class SubstitutionResponseElement : ResponseElement
 	{
+		string typeName;
+		string methodName;
+		
 		public HttpResponseSubstitutionCallback Callback {
 			get;
 			private set;
@@ -46,6 +52,17 @@ namespace System.Web.Caching
 				throw new ArgumentNullException ("callback");
 
 			this.Callback = callback;
+
+			MethodInfo mi = callback.Method;
+			this.typeName = mi.DeclaringType.AssemblyQualifiedName;
+			this.methodName = mi.Name;
+		}
+
+		[OnDeserialized]
+		void ObjectDeserialized (StreamingContext context)
+		{
+			Type type = Type.GetType (typeName, true);
+			Callback = Delegate.CreateDelegate (typeof (HttpResponseSubstitutionCallback), type, methodName, false, true) as HttpResponseSubstitutionCallback;
 		}
 	}
 }

+ 1 - 0
mcs/class/System.Web/System.Web_test.dll.sources

@@ -338,6 +338,7 @@ System.Web.Caching/CacheDependencyCas.cs
 System.Web.Caching/FileResponseElementTest.cs
 System.Web.Caching/HeaderElementTest.cs
 System.Web.Caching/MemoryResponseElementTest.cs
+System.Web.Caching/OutputCacheTest.cs
 System.Web.Caching/SubstitutionResponseElementTest.cs
 System.Web.Configuration/HttpCapabilitiesBaseCas.cs
 System.Web.Handlers/TraceHandlerCas.cs

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

@@ -1,3 +1,7 @@
+2010-01-22  Marek Habersack  <[email protected]>
+
+	* OutputCacheTest.cs: added
+
 2010-01-21  Marek Habersack  <[email protected]>
 
 	* FileResponseElementTest.cs, HeaderElementTest.cs,

File diff suppressed because it is too large
+ 133 - 0
mcs/class/System.Web/Test/System.Web.Caching/OutputCacheTest.cs


Some files were not shown because too many files changed in this diff