public void ConvertFrom ()
		{
			MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
			object o;

			o = cv.ConvertFrom (null, null, "MD5");
			Assert.AreEqual (typeof (MachineKeyValidation), o.GetType (), "typeof");
			Assert.AreEqual ("MD5", o.ToString (), "MD5");

			o = cv.ConvertFrom (null, null, "SHA1");
			Assert.AreEqual ("SHA1", o.ToString (), "SHA1");

			// 3DES in, TripleDES out
			o = cv.ConvertFrom (null, null, "3DES");
			Assert.AreEqual ("TripleDES", o.ToString (), "3DES");

			o = cv.ConvertFrom (null, null, "AES");
			Assert.AreEqual ("AES", o.ToString (), "AES");
#if NET_4_0
			o = cv.ConvertFrom (null, null, "HMACSHA256");
			Assert.AreEqual ("HMACSHA256", o.ToString (), "HMACSHA256");

			o = cv.ConvertFrom (null, null, "HMACSHA384");
			Assert.AreEqual ("HMACSHA384", o.ToString (), "HMACSHA384");

			o = cv.ConvertFrom (null, null, "HMACSHA512");
			Assert.AreEqual ("HMACSHA512", o.ToString (), "HMACSHA512");
#endif
		}
		public void ConvertFrom_TypeError ()
		{
			MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
			object o;

			o = cv.ConvertFrom (null, null, 6);
			Assert.IsNull (o, "A1");
		}
		public void CanConvertTo ()
		{
			MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();

			Assert.IsTrue (cv.CanConvertTo (null, typeof (string)), "A1");
			Assert.IsFalse (cv.CanConvertTo (null, typeof (TimeSpan)), "A2");
			Assert.IsFalse (cv.CanConvertTo (null, typeof (int)), "A3");
			Assert.IsFalse (cv.CanConvertTo (null, typeof (object)), "A4");
		}
		public void ConvertFrom ()
		{
			MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
			object o;

			o = cv.ConvertFrom (null, null, "MD5");
			Assert.AreEqual (typeof (MachineKeyValidation), o.GetType(), "A1");
			Assert.AreEqual ("MD5", o.ToString(), "A2");
			o = cv.ConvertFrom (null, null, "AES");
			Assert.AreEqual ("AES", o.ToString(), "A3");
		}
示例#5
0
文件: Membership.cs 项目: vargaz/mono
		static Membership ()
		{
			MembershipSection section = (MembershipSection) WebConfigurationManager.GetSection ("system.web/membership");

			providers = new MembershipProviderCollection ();

			ProvidersHelper.InstantiateProviders (section.Providers, providers, typeof (MembershipProvider));

			provider = providers[section.DefaultProvider];

			onlineTimeWindow = (int) section.UserIsOnlineTimeWindow.TotalMinutes;
			hashAlgorithmType = section.HashAlgorithmType;
			if (String.IsNullOrEmpty (hashAlgorithmType)) {
				MachineKeySection mks = WebConfigurationManager.GetSection ("system.web/machineKey") as MachineKeySection;
				MachineKeyValidationConverter cvt = new MachineKeyValidationConverter ();
				hashAlgorithmType = cvt.ConvertTo (null, null, mks.Validation, typeof (string)) as string;
			}
			
			if (String.IsNullOrEmpty (hashAlgorithmType))
				hashAlgorithmType = "SHA1";
		}
		public void ConvertTo_NullError ()
		{
			MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();

			Assert.AreEqual ("", cv.ConvertTo (null, null, null, typeof (string)), "A1");
		}
		public void ConvertTo ()
		{
			MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();

			Assert.AreEqual ("MD5", cv.ConvertTo (null, null, MachineKeyValidation.MD5, typeof (string)), "A1");
			Assert.AreEqual ("SHA1", cv.ConvertTo (null, null, MachineKeyValidation.SHA1, typeof (string)), "A2");
			Assert.AreEqual ("3DES", cv.ConvertTo (null, null, MachineKeyValidation.TripleDES, typeof (string)), "A3");
		}
		public void ConvertTo_TypeError2 ()
		{
			MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();

			Assert.AreEqual ("MD5", cv.ConvertTo (null, null, MachineKeyValidation.MD5, typeof (int)), "A1");
			Assert.AreEqual ("MD5", cv.ConvertTo (null, null, MachineKeyValidation.MD5, null), "A2");
		}
		public void ConvertFrom_Custom ()
		{
			MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
			cv.ConvertFrom (null, null, "Custom");
		}
		public void ConvertTo_TypeError3 ()
		{
			MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
			cv.ConvertTo (null, null, (MachineKeyValidation)Int32.MinValue, typeof (string));
		}
		public void ConvertTo_Custom ()
		{
			MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
			cv.ConvertTo (null, null, MachineKeyValidation.Custom, typeof (string));
		}
		public void ConvertTo ()
		{
			MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();

			Assert.AreEqual ("MD5", cv.ConvertTo (null, null, MachineKeyValidation.MD5, typeof (string)), "A1");
			Assert.AreEqual ("SHA1", cv.ConvertTo (null, null, MachineKeyValidation.SHA1, typeof (string)), "A2");
			Assert.AreEqual ("3DES", cv.ConvertTo (null, null, MachineKeyValidation.TripleDES, typeof (string)), "A3");
#if NET_4_0
			Assert.AreEqual ("HMACSHA256", cv.ConvertTo (null, null, MachineKeyValidation.HMACSHA256, typeof (string)), "HMACSHA256");
			Assert.AreEqual ("HMACSHA384", cv.ConvertTo (null, null, MachineKeyValidation.HMACSHA384, typeof (string)), "HMACSHA384");
			Assert.AreEqual ("HMACSHA512", cv.ConvertTo (null, null, MachineKeyValidation.HMACSHA512, typeof (string)), "HMACSHA512");
#endif
		}
		public void ConvertFrom_CaseSensitive ()
		{
			MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
			cv.ConvertFrom (null, null, "sha1");
		}