Пример #1
0
        public void ConvertTo_ValueIsOfInvalidType_ThrowsNotSupportedException()
        {
            // Setup
            var notSupportedValue = new NotSupportedType();
            var converter         = new NullableEnumConverter(typeof(SimpleEnum?));

            // Call
            TestDelegate test = () => converter.ConvertTo(notSupportedValue, typeof(SimpleEnum));

            // Assert
            Assert.Throws <NotSupportedException>(test);
        }
Пример #2
0
        public void ConvertTo_DestinationTypeIsInvalid_ThrowsNotSupportedException()
        {
            // Setup
            const SimpleEnum enumValue = SimpleEnum.FirstValue;
            var converter = new NullableEnumConverter(typeof(SimpleEnum?));

            // Call
            TestDelegate test = () => converter.ConvertTo(enumValue, typeof(NotSupportedType));

            // Assert
            Assert.Throws <NotSupportedException>(test);
        }
Пример #3
0
        public void ConvertTo_DestinationTypeIsNull_ThrowsArgumentNullException()
        {
            // Setup
            const SimpleEnum enumValue = SimpleEnum.FirstValue;
            var converter = new NullableEnumConverter(typeof(SimpleEnum?));

            // Call
            TestDelegate test = () => converter.ConvertTo(enumValue, null);

            // Assert
            Assert.Throws <ArgumentNullException>(test);
        }
Пример #4
0
        public void ConvertTo_ValueIsNull_DoesNotThrowException()
        {
            // Setup
            var converter = new NullableEnumConverter(typeof(SimpleEnum?));

            // Call
            var          result = new object();
            TestDelegate test   = () => result = converter.ConvertTo(null, typeof(string));

            // Assert
            Assert.DoesNotThrow(test);
            Assert.AreEqual(string.Empty, result);
        }
Пример #5
0
        public void ConvertTo_DestinationTypeIsString_ReturnsExpectedEnumDisplayName()
        {
            // Setup
            const SimpleEnum enumValue = SimpleEnum.FirstValue;
            var converter = new NullableEnumConverter(typeof(SimpleEnum?));

            // Call
            object result = converter.ConvertTo(enumValue, typeof(string));

            // Assert
            const string expectedText = "<first>";

            Assert.AreEqual(expectedText, result);
        }
Пример #6
0
        private T ConvertNullable <T>(T origin)
        {
            var redisVal = NullableEnumConverter.ConvertTo(origin, typeof(T), null);

            return((T)NullableEnumConverter.ConvertFrom(redisVal, typeof(T), null));
        }