Пример #1
0
        public void TestEnumConversion()
        {
            var converter = new EnumConverter();
            var result    = converter.ConvertFromString("Item2", CULTURE, typeof(SimpleEnum));

            Assert.AreEqual(SimpleEnum.Item2, result);
            result = converter.ConvertFromString("0", CULTURE, typeof(SimpleEnum));
            Assert.AreEqual(SimpleEnum.None, result);
        }
Пример #2
0
        public void TestEmptyEnumConversion()
        {
            var converter = new EnumConverter();

            Assert.Throws <ArgumentException>(() => converter.ConvertFromString("", CULTURE, typeof(FlagEnum)));
            Assert.Null(converter.ConvertFromString("", CULTURE, typeof(FlagEnum?)));

            Assert.Throws <ArgumentException>(() => converter.ConvertFromString("", CULTURE, typeof(SimpleEnum)));
            Assert.Null(converter.ConvertFromString("", CULTURE, typeof(SimpleEnum?)));
        }
Пример #3
0
        public void TestEnumFlagsConversion()
        {
            var converter = new EnumConverter();
            var result    = converter.ConvertFromString("Item3, Item1", CULTURE, typeof(FlagEnum));

            Assert.IsInstanceOf(typeof(FlagEnum), result);
            var flags = (FlagEnum)result;

            Assert.True(flags.HasFlag(FlagEnum.Item1));
            Assert.True(flags.HasFlag(FlagEnum.Item3));
            Assert.False(flags.HasFlag(FlagEnum.Item2));
        }