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); }
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); }
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); }
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); }
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); }
private T ConvertNullable <T>(T origin) { var redisVal = NullableEnumConverter.ConvertTo(origin, typeof(T), null); return((T)NullableEnumConverter.ConvertFrom(redisVal, typeof(T), null)); }