public void TestFromStringFlags() { object e = TestEnum.Default; e = PropertyConverter.EnumFromString(typeof(TestFlags), "A"); Assert.AreEqual(e, TestFlags.A, "Normal"); e = PropertyConverter.EnumFromString(typeof(TestFlags), "A, B"); Assert.AreEqual(e, TestFlags.A | TestFlags.B, "Multiple"); e = PropertyConverter.EnumFromString(typeof(TestFlags), "foo"); Assert.AreEqual(e, null, "Bad"); }
public void EnumFromString() { object e = TestEnum.Default; e = PropertyConverter.EnumFromString(typeof(TestEnum), "Normal"); Assert.AreEqual(TestEnum.Normal, e, "Normal"); e = PropertyConverter.EnumFromString(typeof(TestEnum), "lowercase"); Assert.AreEqual(TestEnum.LowerCase, e, "Lower Case"); e = PropertyConverter.EnumFromString(typeof(TestEnum), "UPPERCASE"); Assert.AreEqual(TestEnum.UpperCase, e, "Upper Case"); e = PropertyConverter.EnumFromString(typeof(TestEnum), "DoesntExist"); Assert.AreEqual(null, e, "Doesn't Exist"); e = PropertyConverter.EnumFromString(typeof(TestEnum), "TestEnum.Normal"); Assert.AreEqual(null, e, "Full Name"); }
public void StaticMethods_Deny_Unrestricted() { Assert.AreEqual(SecurityAction.Demand, PropertyConverter.EnumFromString(typeof(SecurityAction), "Demand"), "EnumFromString"); Assert.AreEqual("Demand", PropertyConverter.EnumToString(typeof(SecurityAction), SecurityAction.Demand), "EnumToString"); Assert.AreEqual(String.Empty, PropertyConverter.ObjectFromString(typeof(string), null, String.Empty), "ObjectFromString"); }