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"); }
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)); } } }
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"); }
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())); } }