New test.
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / SessionStateSection.cs
index 3053674220a50e1caae2604d102367ff7fd05864..b0d9d2b0958dfaab58ff7cfd4fec1c187d9c1234 100644 (file)
@@ -56,22 +56,35 @@ namespace System.Web.Configuration {
                static ConfigurationProperty useHostingIdentityProp;
                static ConfigurationPropertyCollection properties;
 
+               static ConfigurationElementProperty elementProperty;
+
                static SessionStateSection ()
                {
                        allowCustomSqlDatabaseProp = new ConfigurationProperty ("allowCustomSqlDatabase", typeof (bool), false);
-                       cookielessProp = new ConfigurationProperty ("cookieless", typeof (HttpCookieMode));
+                       cookielessProp = new ConfigurationProperty ("cookieless", typeof (string), null);
                        cookieNameProp = new ConfigurationProperty ("cookieName", typeof (string), "ASP.NET_SessionId");
                        customProviderProp = new ConfigurationProperty ("customProvider", typeof (string), "");
-                       modeProp = new ConfigurationProperty ("mode", typeof (SessionStateMode), SessionStateMode.InProc);
+                       modeProp = new ConfigurationProperty ("mode", typeof (SessionStateMode), SessionStateMode.InProc,
+                                                             new GenericEnumConverter (typeof (SessionStateMode)), null,
+                                                             ConfigurationPropertyOptions.None);
                        partitionResolverTypeProp = new ConfigurationProperty ("partitionResolverType", typeof (string), "");
-                       providersProp = new ConfigurationProperty ("providers", typeof (ProviderSettingsCollection));
+                       providersProp = new ConfigurationProperty ("providers", typeof (ProviderSettingsCollection), null,
+                                                                  null, null, ConfigurationPropertyOptions.None);
                        regenerateExpiredSessionIdProp = new ConfigurationProperty ("regenerateExpiredSessionId", typeof (bool), true);
                        sessionIDManagerTypeProp = new ConfigurationProperty ("sessionIDManagerType", typeof (string), "");
-                       sqlCommandTimeoutProp = new ConfigurationProperty ("sqlCommandTimeout", typeof (TimeSpan), TimeSpan.FromSeconds (30));
+                       sqlCommandTimeoutProp = new ConfigurationProperty ("sqlCommandTimeout", typeof (TimeSpan), TimeSpan.FromSeconds (30),
+                                                                          PropertyHelper.TimeSpanSecondsOrInfiniteConverter, null,
+                                                                          ConfigurationPropertyOptions.None);
                        sqlConnectionStringProp = new ConfigurationProperty ("sqlConnectionString", typeof (string), "data source=localhost;Integrated Security=SSPI");
                        stateConnectionStringProp = new ConfigurationProperty ("stateConnectionString", typeof (string), "tcpip=loopback:42424");
-                       stateNetworkTimeoutProp = new ConfigurationProperty ("stateNetworkTimeout", typeof (TimeSpan), TimeSpan.FromSeconds (10));
-                       timeoutProp = new ConfigurationProperty ("timeout", typeof (TimeSpan), TimeSpan.FromMinutes (20));
+                       stateNetworkTimeoutProp = new ConfigurationProperty ("stateNetworkTimeout", typeof (TimeSpan), TimeSpan.FromSeconds (10),
+                                                                            PropertyHelper.TimeSpanSecondsOrInfiniteConverter,
+                                                                            PropertyHelper.PositiveTimeSpanValidator,
+                                                                            ConfigurationPropertyOptions.None);
+                       timeoutProp = new ConfigurationProperty ("timeout", typeof (TimeSpan), TimeSpan.FromMinutes (20),
+                                                                PropertyHelper.TimeSpanMinutesOrInfiniteConverter,
+                                                                new TimeSpanValidator (new TimeSpan (0,1,0), TimeSpan.MaxValue),
+                                                                ConfigurationPropertyOptions.None);
                        useHostingIdentityProp = new ConfigurationProperty ("useHostingIdentity", typeof (bool), true);
                        properties = new ConfigurationPropertyCollection ();
 
@@ -90,6 +103,8 @@ namespace System.Web.Configuration {
                        properties.Add (stateNetworkTimeoutProp);
                        properties.Add (timeoutProp);
                        properties.Add (useHostingIdentityProp);
+
+                       elementProperty = new ConfigurationElementProperty (new CallbackValidator (typeof (SessionStateSection), ValidateElement));
                }
 
                [MonoTODO]
@@ -106,8 +121,8 @@ namespace System.Web.Configuration {
 
                [ConfigurationProperty ("cookieless")]
                public HttpCookieMode Cookieless {
-                       get { return (HttpCookieMode) base [cookielessProp];}
-                       set { base[cookielessProp] = value; }
+                       get { return ParseCookieMode ((string) base [cookielessProp]); }
+                       set { base[cookielessProp] = value.ToString(); }
                }
 
                [ConfigurationProperty ("cookieName", DefaultValue = "ASP.NET_SessionId")]
@@ -172,6 +187,7 @@ namespace System.Web.Configuration {
 
                [TypeConverter (typeof (TimeSpanSecondsOrInfiniteConverter))]
                [ConfigurationProperty ("stateNetworkTimeout", DefaultValue = "00:00:10")]
+               // LAMESPEC: MS lists no validator here but provides one in Properties.
                public TimeSpan StateNetworkTimeout {
                        get { return (TimeSpan) base [stateNetworkTimeoutProp];}
                        set { base[stateNetworkTimeoutProp] = value; }
@@ -191,16 +207,41 @@ namespace System.Web.Configuration {
                        set { base[useHostingIdentityProp] = value; }
                }
 
-#if notyet
                [MonoTODO]
-               public ConfigurationElementProperty ElementProperty {
-                       get { throw new NotImplementedException (); }
+               static void ValidateElement (object o)
+               {
+                       /* XXX do some sort of element validation here? */
+               }
+
+               protected override ConfigurationElementProperty ElementProperty {
+                       get { return elementProperty; }
                }
-#endif
 
                protected override ConfigurationPropertyCollection Properties {
                        get { return properties; }
                }
+
+               HttpCookieMode ParseCookieMode (string s)
+               {
+                       if (s == "true") return HttpCookieMode.UseUri;
+                       else if (s == "false") return HttpCookieMode.UseCookies;
+                       else {
+                               try {
+                                       return (HttpCookieMode)Enum.Parse (typeof(HttpCookieMode), s);
+                               }
+                               catch {
+                                       return HttpCookieMode.UseCookies;
+                               }
+                       }
+               }
+
+#region CompatabilityCode
+               internal bool CookieLess {
+                       get { return Cookieless != HttpCookieMode.UseCookies; }
+                       set { Cookieless = value ? HttpCookieMode.UseUri : HttpCookieMode.UseCookies; }
+               }
+#endregion
+
        }
 }