public void TestEquals() {
		Enum e1 = new TestingEnum();
		Enum e2 = new TestingEnum();
		Enum e3 = new TestingEnum2();

		Assert("An enum should equal itself", e1.Equals(e1));
		Assert("An enum should equal a copy", e1.Equals(e2));

		Assert("Shouldn't match", !e1.Equals(e3));
		Assert("Shouldn't match null", !e1.Equals(null));
	}
Example #2
0
		public void TestEquals ()
		{
			Enum e1 = new TestingEnum ();
			Enum e2 = new TestingEnum ();
			Enum e3 = new TestingEnum2 ();

			Assert.IsTrue (e1.Equals (e1), "#1");
			Assert.IsTrue (e1.Equals (e2), "#2");
			Assert.IsFalse (e1.Equals (e3), "#3");
			Assert.IsFalse (e1.Equals (null), "#4");
		}
Example #3
0
		public void TestCompareTo ()
		{
			Enum e1 = new TestingEnum ();
			Enum e2 = new TestingEnum ();
			Enum e3 = new TestingEnum2 ();

			Assert.AreEqual (0, e1.CompareTo (e1), "#A1");
			Assert.AreEqual (0, e1.CompareTo (e2), "#A2");

			TestingEnum x = TestingEnum.This;
			TestingEnum y = TestingEnum.Is;
			Assert.AreEqual (0, x.CompareTo (x), "#B1");
			Assert.AreEqual (-1, x.CompareTo (y), "#B2");
			Assert.AreEqual (1, y.CompareTo (x), "#B3");

			try {
				e1.CompareTo (e3);
				Assert.Fail ("#C1");
			} catch (ArgumentException ex) {
				// Object must be the same type as the enum.
				// The type passed in was MonoTests.System.EnumTest+TestingEnum2;
				// the enum type was MonoTests.System.EnumTest+TestingEnum
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
				Assert.IsNull (ex.InnerException, "#A3");
				Assert.IsNotNull (ex.Message, "#A4");
				Assert.IsTrue (ex.Message.IndexOf (typeof (TestingEnum).FullName) != -1, "#A5");
				Assert.IsTrue (ex.Message.IndexOf (typeof (TestingEnum2).FullName) != -1, "#A6");
				Assert.IsNull (ex.ParamName, "#A7");
			}

			try {
				((Enum) e1).CompareTo ((Enum) e3);
				Assert.Fail ("#D1");
			} catch (ArgumentException ex) {
				// Object must be the same type as the enum.
				// The type passed in was MonoTests.System.EnumTest+TestingEnum2;
				// the enum type was MonoTests.System.EnumTest+TestingEnum
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
				Assert.IsNull (ex.InnerException, "#D3");
				Assert.IsNotNull (ex.Message, "#D4");
				Assert.IsTrue (ex.Message.IndexOf (typeof (TestingEnum).FullName) != -1, "#D5");
				Assert.IsTrue (ex.Message.IndexOf (typeof (TestingEnum2).FullName) != -1, "#D6");
				Assert.IsNull (ex.ParamName, "#D7");
			}
		}
Example #4
0
	public static int Main () {
		int num = 0;
		
		Enum e1 = new TestingEnum();
		Enum e2 = new TestingEnum();
		Enum e3 = new TestingEnum2();

		++num;
		if (!e1.Equals(e2))
			return num;
		
		++num;
		if (e1.Equals(e3))
			return num;
		
		++num;
		if (TestingEnum.Test.Equals(TestingEnum2.Test))
			return num;
		
		return 0;
	}
	public void TestCompareTo() {
		Enum e1 = new TestingEnum();
		Enum e2 = new TestingEnum();
		Enum e3 = new TestingEnum2();

		AssertEquals("An enum should equal itself", 
			     0, e1.CompareTo(e1));
		AssertEquals("An enum should equal a copy", 
			     0, e1.CompareTo(e2));

		TestingEnum x = TestingEnum.This;
		TestingEnum y = TestingEnum.Is;
		AssertEquals("should equal", 0, x.CompareTo(x));
		AssertEquals("less than", -1, x.CompareTo(y));
		AssertEquals("greater than", 1, y.CompareTo(x));

		{
			bool errorThrown = false;
			try {
				e1.CompareTo(e3);
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("1) Compare type mismatch not caught.", 
			       errorThrown);
		}
		{
			bool errorThrown = false;
			try {
				((Enum)e1).CompareTo((Enum)e3);
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("2) Compare type mismatch not caught.", 
			       errorThrown);
		}
	}
Example #6
0
		public void TestGetValues ()
		{
			try {
				Enum.GetValues (null);
				Assert.Fail ("#A1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
				Assert.IsNull (ex.InnerException, "#A3");
				Assert.IsNotNull (ex.Message, "#A4");
				Assert.IsNotNull (ex.ParamName, "#A5");
				Assert.AreEqual ("enumType", ex.ParamName, "#A6");
			}

			try {
				String bad = "huh?";
				Enum.GetValues (bad.GetType ());
				Assert.Fail ("#B1");
			} catch (ArgumentException ex) {
				// Type provided must be an Enum
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
				Assert.IsNull (ex.InnerException, "#B3");
				Assert.IsNotNull (ex.Message, "#B4");
				Assert.IsNotNull (ex.ParamName, "#B5");
				Assert.AreEqual ("enumType", ex.ParamName, "#B6");
			}

			Enum t1 = new TestingEnum ();
			Array a1 = Enum.GetValues (t1.GetType ());
			for (int i = 0; i < a1.Length; i++)
				Assert.AreEqual ((TestingEnum) i, a1.GetValue (i), "#C1");

			Enum t2 = new TestShortEnum ();
			Array a2 = Enum.GetValues (t2.GetType ());
			for (short i = 0; i < a1.Length; i++)
				Assert.AreEqual ((TestShortEnum) i, a2.GetValue (i), "#C2");
		}
Example #7
0
		public void TestGetUnderlyingType ()
		{
			try {
				Enum.GetUnderlyingType (null);
				Assert.Fail ("#A1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
				Assert.IsNull (ex.InnerException, "#A3");
				Assert.IsNotNull (ex.Message, "#A4");
				Assert.IsNotNull (ex.ParamName, "#A5");
				Assert.AreEqual ("enumType", ex.ParamName, "#A6");
			}

			try {
				String bad = "huh?";
				Enum.GetUnderlyingType (bad.GetType ());
				Assert.Fail ("#B1");
			} catch (ArgumentException ex) {
				// Type provided must be an Enum
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
				Assert.IsNull (ex.InnerException, "#B3");
				Assert.IsNotNull (ex.Message, "#B4");
				Assert.IsNotNull (ex.ParamName, "#B5");
				Assert.AreEqual ("enumType", ex.ParamName, "#B6");
			}

			short sh = 5;
			int i = 5;
			Enum t1 = new TestingEnum ();
			Enum t2 = new TestShortEnum ();
			Assert.AreEqual (i.GetType (), Enum.GetUnderlyingType (t1.GetType ()), "#C1");
			Assert.AreEqual (sh.GetType (), Enum.GetUnderlyingType (t2.GetType ()), "#C2");
		}
Example #8
0
		public void TestGetTypeCode ()
		{
			TestingEnum x = TestingEnum.This;
			TestingEnum y = new TestingEnum ();
			Assert.AreEqual (TypeCode.Int32, x.GetTypeCode (), "#1");
			Assert.AreEqual (TypeCode.Int32, y.GetTypeCode (), "#2");
		}
Example #9
0
		public void TestGetHashCode ()
		{
			Enum e1 = new TestingEnum ();
			Enum e2 = new TestingEnum2 ();

			Assert.AreEqual (e1.GetHashCode (), e1.GetHashCode ());
		}
        private void SaveSettings_CallsUpdatePortalSetting_WithRightParameters(string stringValue, int integerValue, double doubleValue,
                                                                               bool booleanValue, DateTime datetimeValue, TimeSpan timeSpanValue, TestingEnum enumValue, ComplexType complexValue)
        {
            // Arrange
            var moduleInfo = GetModuleInfo;
            var settings   = new MyPortalSettings
            {
                StringProperty   = stringValue,
                IntegerProperty  = integerValue,
                DoubleProperty   = doubleValue,
                BooleanProperty  = booleanValue,
                DateTimeProperty = datetimeValue,
                TimeSpanProperty = timeSpanValue,
                EnumProperty     = enumValue,
                ComplexProperty  = complexValue,
            };

            this.MockPortalController.Setup(pc => pc.UpdatePortalSetting(PortalId, SettingNamePrefix + "StringProperty", stringValue, true, Null.NullString, false));
            this.MockPortalController.Setup(pc => pc.UpdatePortalSetting(PortalId, SettingNamePrefix + "IntegerProperty", integerValue.ToString(), true, Null.NullString, false));
            this.MockPortalController.Setup(pc => pc.UpdatePortalSetting(PortalId, SettingNamePrefix + "DoubleProperty", doubleValue.ToString(CultureInfo.InvariantCulture), true, Null.NullString, false));
            this.MockPortalController.Setup(pc => pc.UpdatePortalSetting(PortalId, SettingNamePrefix + "BooleanProperty", booleanValue.ToString(), true, Null.NullString, false));
            this.MockPortalController.Setup(pc => pc.UpdatePortalSetting(PortalId, SettingNamePrefix + "DateTimeProperty", datetimeValue.ToString("o", CultureInfo.InvariantCulture), true, Null.NullString, false));
            this.MockPortalController.Setup(pc => pc.UpdatePortalSetting(PortalId, SettingNamePrefix + "TimeSpanProperty", timeSpanValue.ToString("c", CultureInfo.InvariantCulture), true, Null.NullString, false));
            this.MockPortalController.Setup(pc => pc.UpdatePortalSetting(PortalId, SettingNamePrefix + "EnumProperty", enumValue.ToString(), true, Null.NullString, false));
            this.MockPortalController.Setup(pc => pc.UpdatePortalSetting(PortalId, SettingNamePrefix + "ComplexProperty", $"{complexValue.X} | {complexValue.Y}", true, Null.NullString, false));

            var settingsRepository = new MyPortalSettingsRepository();

            // Act
            settingsRepository.SaveSettings(moduleInfo, settings);

            // Assert
            this.MockRepository.VerifyAll();
        }
 public void GetSettings_GetsValuesFrom_ModuleSettingsCollection_fr_FR(string stringValue, int integerValue, double doubleValue, bool booleanValue, DateTime datetimeValue, TimeSpan timeSpanValue, TestingEnum enumValue, ComplexType complexValue)
 {
     this.GetSettings_GetsValuesFrom_ModuleSettingsCollection(stringValue, integerValue, doubleValue, booleanValue, datetimeValue, timeSpanValue, enumValue, complexValue);
 }
Example #12
0
		public void TestParse2 ()
		{
			try {
				String name = "huh?";
				Enum.Parse (null, name, true);
				Assert.Fail ("#A1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
				Assert.IsNull (ex.InnerException, "#A3");
				Assert.IsNotNull (ex.Message, "#A4");
				Assert.IsNotNull (ex.ParamName, "#A5");
				Assert.AreEqual ("enumType", ex.ParamName, "#A6");
			}

			try {
				TestingEnum x = TestingEnum.Test;
				Enum.Parse (x.GetType (), null, true);
				Assert.Fail ("#B1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
				Assert.IsNull (ex.InnerException, "#B3");
				Assert.IsNotNull (ex.Message, "#B4");
				Assert.IsNotNull (ex.ParamName, "#B5");
				Assert.AreEqual ("value", ex.ParamName, "#B6");
			}

			try {
				String bad = "huh?";
				Enum.Parse (bad.GetType (), bad, true);
				Assert.Fail ("#C1");
			} catch (ArgumentException ex) {
				// Type provided must be an Enum
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
				Assert.IsNull (ex.InnerException, "#D3");
				Assert.IsNotNull (ex.Message, "#D4");
				Assert.IsNotNull (ex.ParamName, "#D5");
				Assert.AreEqual ("enumType", ex.ParamName, "#D6");
			}

			try {
				TestingEnum x = TestingEnum.Test;
				String bad = "";
				Enum.Parse (x.GetType (), bad, true);
				Assert.Fail ("#E1");
			} catch (ArgumentException ex) {
				// Must specify valid information for parsing
				// in the string
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#E2");
				Assert.IsNull (ex.InnerException, "#E3");
				Assert.IsNotNull (ex.Message, "#E4");
				Assert.IsNull (ex.ParamName, "#E5");
			}

			try {
				TestingEnum x = TestingEnum.Test;
				String bad = " ";
				Enum.Parse (x.GetType (), bad, true);
				Assert.Fail ("#F1");
			} catch (ArgumentException ex) {
				// Must specify valid information for parsing
				// in the string
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#F2");
				Assert.IsNull (ex.InnerException, "#F3");
				Assert.IsNotNull (ex.Message, "#F4");
				Assert.IsFalse (ex.Message.IndexOf ("' '") != -1, "#F5");
				Assert.IsNull (ex.ParamName, "#F6");
			}

			try {
				String bad = "huh?";
				TestingEnum x = TestingEnum.Test;
				Enum.Parse (x.GetType (), bad, true);
				Assert.Fail ("#G1");
			} catch (ArgumentException ex) {
				// Requested value 'huh?' was not found
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#G2");
				Assert.IsNull (ex.InnerException, "#G3");
				Assert.IsNotNull (ex.Message, "#G4");
				Assert.IsTrue (ex.Message.IndexOf ("'huh?'") != -1, "#G5");
				Assert.IsNull (ex.ParamName, "#G6");
			}

			try {
				String bad = "test";
				TestingEnum x = TestingEnum.Test;
				Enum.Parse (x.GetType (), bad, false);
				Assert.Fail ("#H1");
			} catch (ArgumentException ex) {
				// Requested value 'test' was not found
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#H2");
				Assert.IsNull (ex.InnerException, "#H3");
				Assert.IsNotNull (ex.Message, "#H4");
				Assert.IsTrue (ex.Message.IndexOf ("'test'") != -1, "#H5");
				Assert.IsNull (ex.ParamName, "#H6");
			}

			TestingEnum t1 = new TestingEnum ();
			Assert.AreEqual (TestingEnum.This, Enum.Parse (t1.GetType (), "this", true), "#I1");
			Assert.AreEqual (TestingEnum.Is, Enum.Parse (t1.GetType (), "is", true), "#I2");
			Assert.AreEqual (TestingEnum.A, Enum.Parse (t1.GetType (), "a", true), "#I3");
			Assert.AreEqual (TestingEnum.Test, Enum.Parse (t1.GetType (), "test", true), "#I4");
			Assert.AreEqual (TestingEnum.Test, Enum.Parse (t1.GetType (), "    \n\ntest\t", true), "#I5");

			Assert.AreEqual (TestingEnum.Is, Enum.Parse (t1.GetType (), "This,is", true), "#J1");
			Assert.AreEqual (TestingEnum.Test, Enum.Parse (t1.GetType (), "This,test", true), "#J2");
			Assert.AreEqual (TestingEnum.Test, Enum.Parse (t1.GetType (), "This,is,A", true), "#J3");
			Assert.AreEqual (TestingEnum.Test, Enum.Parse (t1.GetType (), "   \n\tThis \t\n,    is,a \n", true), "#J4");
		}
 public void GetSettings_GetsValuesFrom_PortalSettings_tr_TR(string stringValue, int integerValue, double doubleValue, bool booleanValue, DateTime datetimeValue, TimeSpan timeSpanValue, TestingEnum enumValue, ComplexType complexValue)
 {
     this.GetSettings_GetsValuesFrom_PortalSettings(stringValue, integerValue, doubleValue, booleanValue, datetimeValue, timeSpanValue, enumValue, complexValue);
 }
Example #14
0
	public void TestIsDefined() {
		{
			bool errorThrown = false;
			try {
				Enum.IsDefined(null, 1);
			} catch (ArgumentNullException) {
				errorThrown = true;
			}
			Assert("null first arg not caught.", 
			       errorThrown);
		}
		{
			bool errorThrown = false;
			try {
				TestingEnum x = TestingEnum.Test;
				Enum.IsDefined(x.GetType(), null);
			} catch (ArgumentNullException) {
				errorThrown = true;
			}
			Assert("null second arg not caught.", 
			       errorThrown);
		}
		{
			bool errorThrown = false;
			try {
				String bad = "huh?";
				int i = 4;
				Enum.IsDefined(bad.GetType(), i);
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("non-enum type not caught.", 
			       errorThrown);
		}

		try {
			TestingEnum x = TestingEnum.Test;
			short i = 4;
			Enum.IsDefined(x.GetType(), i);
			Fail("wrong underlying type not caught.");
		} catch (ArgumentException) {
		} catch (Exception e) {
			Fail("wrong Exception thrown ("+e.ToString()+")for underlying type not caught.");
		}

		// spec says yes, MS impl says no.
		//{
		//bool errorThrown = false;
		//try {
		//String bad = "huh?";
		//TestingEnum x = TestingEnum.Test;
		//Enum.IsDefined(x.GetType(), bad);
		//} catch (ExecutionEngineException) {
		//errorThrown = true;
		//}
		//Assert("non-enum object not caught.", 
		//errorThrown);
		//}
		{
			Enum t1 = new TestingEnum();
			int i = 0;
			for (i = 0; 
			     i < Enum.GetValues(t1.GetType()).Length; i++) {
				Assert("should have value for i=" + i,
				       Enum.IsDefined(t1.GetType(), i));
			}
			Assert("Shouldn't have value",
			       !Enum.IsDefined(t1.GetType(), i));
		}
	}
Example #15
0
	public void TestGetValues() {
		{
			bool errorThrown = false;
			try {
				Enum.GetValues(null);
			} catch (ArgumentNullException) {
				errorThrown = true;
			}
			Assert("null type not caught.", 
			       errorThrown);
		}
		{
			bool errorThrown = false;
			try {
				String bad = "huh?";
				Enum.GetValues(bad.GetType());
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("non-enum type not caught.", 
			       errorThrown);
		}
		{
			Enum t1 = new TestingEnum();
			Array a1 = Enum.GetValues(t1.GetType());
			for (int i= 0; i < a1.Length; i++) {
				AssertEquals("wrong enum value",
					     (TestingEnum)i,
					     a1.GetValue(i));
			}
		}
		{
			Enum t1 = new TestShortEnum();
			Array a1 = Enum.GetValues(t1.GetType());
			for (short i= 0; i < a1.Length; i++) {
				AssertEquals("wrong short enum value",
					     (TestShortEnum)i,
					     a1.GetValue(i));
			}
		}
	}
Example #16
0
	public void TestGetUnderlyingType() {
		{
			bool errorThrown = false;
			try {
				Enum.GetUnderlyingType(null);
			} catch (ArgumentNullException) {
				errorThrown = true;
			}
			Assert("null type not caught.", 
			       errorThrown);
		}
		{
			bool errorThrown = false;
			try {
				String bad = "huh?";
				Enum.GetUnderlyingType(bad.GetType());
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("non-enum type not caught.", 
			       errorThrown);
		}
		{
			short sh = 5;
			int i = 5;
			Enum t1 = new TestingEnum();
			Enum t2 = new TestShortEnum();
			AssertEquals("Wrong default underlying type",
				     i.GetType(), 
				     Enum.GetUnderlyingType(t1.GetType()));
			AssertEquals("Not short underlying type",
				     sh.GetType(), 
				     Enum.GetUnderlyingType(t2.GetType()));
		}
	}
Example #17
0
	public void TestGetTypeCode() {
		TestingEnum x = TestingEnum.This;
		TestingEnum y = new TestingEnum();
		AssertEquals("01 bad type code", 
			     TypeCode.Int32, x.GetTypeCode());
		AssertEquals("02 bad type code", 
			     TypeCode.Int32, y.GetTypeCode());
	}
Example #18
0
	public void TestGetHashCode() {
		Enum e1 = new TestingEnum();
		Enum e2 = new TestingEnum2();

		AssertEquals("hash code is deterministic", 
			     e1.GetHashCode(), e1.GetHashCode());
	}
Example #19
0
		public void TestIsDefined ()
		{
			try {
				Enum.IsDefined (null, 1);
				Assert.Fail ("#A1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
				Assert.IsNull (ex.InnerException, "#A3");
				Assert.IsNotNull (ex.Message, "#A4");
				Assert.IsNotNull (ex.ParamName, "#A5");
				Assert.AreEqual ("enumType", ex.ParamName, "#A6");
			}

			try {
				TestingEnum x = TestingEnum.Test;
				Enum.IsDefined (x.GetType (), null);
				Assert.Fail ("#B1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
				Assert.IsNull (ex.InnerException, "#B3");
				Assert.IsNotNull (ex.Message, "#B4");
				Assert.IsNotNull (ex.ParamName, "#B5");
				Assert.AreEqual ("value", ex.ParamName, "#B6");
			}

			try {
				String bad = "huh?";
				int i = 4;
				Enum.IsDefined (bad.GetType (), i);
				Assert.Fail ("#C1");
			} catch (ArgumentException ex) {
				// Type provided must be an Enum
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
				Assert.IsNull (ex.InnerException, "#C3");
				Assert.IsNotNull (ex.Message, "#C4");
				Assert.IsNotNull (ex.ParamName, "#C5");
				Assert.AreEqual ("enumType", ex.ParamName, "#C6");
			}

			try {
				TestingEnum x = TestingEnum.Test;
				short i = 4;
				Enum.IsDefined (x.GetType (), i);
				Assert.Fail ("#D1");
			} catch (ArgumentException ex) {
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
				Assert.IsNull (ex.InnerException, "#D3");
				Assert.IsNotNull (ex.Message, "#D4");
				Assert.IsNull (ex.ParamName, "#D5");
			}

			Enum t1 = new TestingEnum ();
			int valCount = Enum.GetValues (t1.GetType ()).Length;
			for (int i = 0; i < valCount; i++)
				Assert.IsTrue (Enum.IsDefined (t1.GetType (), i), "#F1:" + i);
			Assert.IsFalse (Enum.IsDefined (t1.GetType (), valCount), "#F2");
			Assert.IsFalse (Enum.IsDefined (typeof (TestingEnum), "huh?"), "#F3");
		}
Example #20
0
	public void TestToObject() {
		{
			bool errorThrown = false;
			try {
				Enum.ToObject(null, 1);
			} catch (ArgumentNullException) {
				errorThrown = true;
			}
			Assert("null type not caught.", 
			       errorThrown);
		}
		{
			bool errorThrown = false;
			try {
				Enum.ToObject("huh?".GetType(), 1);
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("null type not caught.", 
			       errorThrown);
		}
		{
			TestingEnum t1 = new TestingEnum();
			AssertEquals("Should get object",
				     TestingEnum.This,
				     Enum.ToObject(t1.GetType(), 0));
		}
		// TODO - should probably test all the different underlying types
	}
Example #21
0
		public void TestParse1 ()
		{
			try {
				String name = "huh?";
				Enum.Parse (null, name);
				Assert.Fail ("#A1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
				Assert.IsNull (ex.InnerException, "#A3");
				Assert.IsNotNull (ex.Message, "#A4");
				Assert.IsNotNull (ex.ParamName, "#A5");
				Assert.AreEqual ("enumType", ex.ParamName, "#A6");
			}

			try {
				TestingEnum x = TestingEnum.Test;
				Enum.Parse (x.GetType (), null);
				Assert.Fail ("#B1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
				Assert.IsNull (ex.InnerException, "#B3");
				Assert.IsNotNull (ex.Message, "#B4");
				Assert.IsNotNull (ex.ParamName, "#B5");
				Assert.AreEqual ("value", ex.ParamName, "#B6");
			}

			try {
				String bad = "huh?";
				Enum.Parse (bad.GetType (), bad);
				Assert.Fail ("#C1");
			} catch (ArgumentException ex) {
				// Type provided must be an Enum
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
				Assert.IsNull (ex.InnerException, "#C3");
				Assert.IsNotNull (ex.Message, "#C4");
				Assert.IsNotNull (ex.ParamName, "#C5");
				Assert.AreEqual ("enumType", ex.ParamName, "#C6");
			}

			try {
				TestingEnum x = TestingEnum.Test;
				String bad = "";
				Enum.Parse (x.GetType (), bad);
				Assert.Fail ("#D1");
			} catch (ArgumentException ex) {
				// Must specify valid information for parsing
				// in the string
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
				Assert.IsNull (ex.InnerException, "#D3");
				Assert.IsNotNull (ex.Message, "#D4");
				Assert.IsNull (ex.ParamName, "#D5");
			}

			try {
				TestingEnum x = TestingEnum.Test;
				String bad = " ";
				Enum.Parse (x.GetType (), bad);
				Assert.Fail ("#E1");
			} catch (ArgumentException ex) {
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#E2");
				Assert.IsNull (ex.InnerException, "#E3");
				Assert.IsNotNull (ex.Message, "#E4");
				Assert.IsNull (ex.ParamName, "#E5");
			}

			try {
				String bad = "huh?";
				TestingEnum x = TestingEnum.Test;
				Enum.Parse (x.GetType (), bad);
				Assert.Fail ("#F1");
			} catch (ArgumentException ex) {
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#F2");
				Assert.IsNull (ex.InnerException, "#F3");
				Assert.IsNotNull (ex.Message, "#F4");
				Assert.IsNull (ex.ParamName, "#F5");
			}

			TestingEnum t1 = new TestingEnum ();
			Assert.AreEqual (TestingEnum.This, Enum.Parse (t1.GetType (), "This"), "#G1");
			Assert.AreEqual (TestingEnum.Is, Enum.Parse (t1.GetType (), "Is"), "#G2");
			Assert.AreEqual (TestingEnum.A, Enum.Parse (t1.GetType (), "A"), "#G3");
			Assert.AreEqual (TestingEnum.Test, Enum.Parse (t1.GetType (), "Test"), "#G4");
			Assert.AreEqual (TestingEnum.Test, Enum.Parse (t1.GetType (), "    \n\nTest\t"), "#G5");
			Assert.AreEqual (TestingEnum.Is, Enum.Parse (t1.GetType (), "This,Is"), "#G6");
			Assert.AreEqual (TestingEnum.Test, Enum.Parse (t1.GetType (), "This,Test"), "#G7");
			Assert.AreEqual (TestingEnum.Test, Enum.Parse (t1.GetType (), "This,Is,A"), "#G8");
			Assert.AreEqual (TestingEnum.Test, Enum.Parse (t1.GetType (), "   \n\tThis \t\n,    Is,A \n"), "#G9");
		}
        private void GetSettings_GetsValuesFrom_PortalSettings(string stringValue, int integerValue, double doubleValue, bool booleanValue, DateTime datetimeValue, TimeSpan timeSpanValue, TestingEnum enumValue, ComplexType complexValue)
        {
            // Arrange
            var moduleInfo     = GetModuleInfo;
            var portalSettings = new Dictionary <string, string>
            {
                { SettingNamePrefix + "StringProperty", stringValue },
                { SettingNamePrefix + "IntegerProperty", integerValue.ToString() },
                { SettingNamePrefix + "DoubleProperty", doubleValue.ToString(CultureInfo.InvariantCulture) },
                { SettingNamePrefix + "BooleanProperty", booleanValue.ToString() },
                { SettingNamePrefix + "DateTimeProperty", datetimeValue.ToString("o", CultureInfo.InvariantCulture) },
                { SettingNamePrefix + "TimeSpanProperty", timeSpanValue.ToString("c", CultureInfo.InvariantCulture) },
                { SettingNamePrefix + "EnumProperty", enumValue.ToString() },
                { SettingNamePrefix + "ComplexProperty", $"{complexValue.X} | {complexValue.Y}" },
            };

            this.MockPortalSettings(moduleInfo, portalSettings);

            var settingsRepository = new MyPortalSettingsRepository();

            // Act
            var settings = settingsRepository.GetSettings(moduleInfo);

            // Assert
            Assert.AreEqual(stringValue, settings.StringProperty, "The retrieved string property value is not equal to the stored one");
            Assert.AreEqual(integerValue, settings.IntegerProperty, "The retrieved integer property value is not equal to the stored one");
            Assert.AreEqual(doubleValue, settings.DoubleProperty, "The retrieved double property value is not equal to the stored one");
            Assert.AreEqual(booleanValue, settings.BooleanProperty, "The retrieved boolean property value is not equal to the stored one");
            Assert.AreEqual(datetimeValue, settings.DateTimeProperty, "The retrieved datetime property value is not equal to the stored one");
            Assert.AreEqual(timeSpanValue, settings.TimeSpanProperty, "The retrieved timespan property value is not equal to the stored one");
            Assert.AreEqual(enumValue, settings.EnumProperty, "The retrieved enum property value is not equal to the stored one");
            Assert.AreEqual(complexValue, settings.ComplexProperty, "The retrieved complex property value is not equal to the stored one");
            this.MockRepository.VerifyAll();
        }
Example #23
0
	public void TestParse2() {
		{
			bool errorThrown = true;
			try {
				String name = "huh?";
				Enum.Parse(null, name, true);
			} catch (ArgumentNullException) {
				errorThrown = true;
			}
			Assert("null first arg not caught.", 
			       errorThrown);
		}
		{
			bool errorThrown = true;
			try {
				TestingEnum x = TestingEnum.Test;
				Enum.Parse(x.GetType(), null, true);
			} catch (ArgumentNullException) {
				errorThrown = true;
			}
			Assert("null second arg not caught.", 
			       errorThrown);
		}
		{
			bool errorThrown = true;
			try {
				String bad = "huh?";
				Enum.Parse(bad.GetType(), bad, true);
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("non-enum type not caught.", 
			       errorThrown);
		}
		{
			bool errorThrown = true;
			try {
				TestingEnum x = TestingEnum.Test;
				String bad = "";
				Enum.Parse(x.GetType(), bad, true);
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("empty string not caught.", 
			       errorThrown);
		}
		{
			bool errorThrown = true;
			try {
				TestingEnum x = TestingEnum.Test;
				String bad = " ";
				Enum.Parse(x.GetType(), bad, true);
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("space-only string not caught.", 
			       errorThrown);
		}
		{
			bool errorThrown = true;
			try {
				String bad = "huh?";
				TestingEnum x = TestingEnum.Test;
				Enum.Parse(x.GetType(), bad, true);
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("not-in-enum error not caught.", 
			       errorThrown);
		}
		{
			bool errorThrown = true;
			try {
				String bad = "test";
				TestingEnum x = TestingEnum.Test;
				Enum.Parse(x.GetType(), bad, false);
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("not-in-enum error not caught.", 
			       errorThrown);
		}
		{
			TestingEnum t1 = new TestingEnum();
			AssertEquals("parse first enum",
				     TestingEnum.This, 
				     Enum.Parse(t1.GetType(), "this", true));
			AssertEquals("parse second enum",
				     TestingEnum.Is, 
				     Enum.Parse(t1.GetType(), "is", true));
			AssertEquals("parse third enum",
				     TestingEnum.A, 
				     Enum.Parse(t1.GetType(), "a", true));
			AssertEquals("parse last enum",
				     TestingEnum.Test, 
				     Enum.Parse(t1.GetType(), "test", true));

			AssertEquals("parse last enum with whitespace",
				     TestingEnum.Test, 
				     Enum.Parse(t1.GetType(), "    \n\ntest\t", true));

			AssertEquals("parse bitwise-or enum",
				     TestingEnum.Is, 
				     Enum.Parse(t1.GetType(), "This,is", true));
			AssertEquals("parse bitwise-or enum",
				     TestingEnum.Test, 
				     Enum.Parse(t1.GetType(), "This,test", true));
			AssertEquals("parse bitwise-or enum",
				     TestingEnum.Test, 
				     Enum.Parse(t1.GetType(), "This,is,A", true));

			AssertEquals("parse bitwise-or enum with whitespace",
				     TestingEnum.Test, 
					 Enum.Parse(t1.GetType(), "   \n\tThis \t\n,    is,a \n",
						        true));
		}
	}
 public void SaveSettings_CallsUpdateModuleSetting_WithRightParameters_tr_TR(string stringValue, int integerValue, double doubleValue, bool booleanValue, DateTime datetimeValue, TimeSpan timeSpanValue, TestingEnum enumValue, ComplexType complexValue)
 {
     this.SaveSettings_CallsUpdateModuleSetting_WithRightParameters(stringValue, integerValue, doubleValue, booleanValue, datetimeValue, timeSpanValue, enumValue, complexValue);
 }