public void HexConverter_ConvertBack() { IValueConverter converter; object actualValue; Type expectedType; converter = new HexConverter(); expectedType = typeof(int); // // Test with null. // try { converter.ConvertBack(null); Assert.Fail("Expected ArgumentNullException to be thrown."); } catch (ArgumentNullException) { } // // Test with incorrect value. // try { converter.ConvertBack("true"); Assert.Fail("Expected FormatException to be thrown."); } catch (FormatException) { } try { converter.ConvertBack("FFFFFFFFFFFFF"); Assert.Fail("Expected OverflowException to be thrown."); } catch (OverflowException) { } // // Test with 0. // actualValue = converter.ConvertBack("0"); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual(0, actualValue, "Converted value is incorrect."); // // Test with lower case value. // actualValue = converter.ConvertBack("abc"); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual(0xABC, actualValue, "Converted value is incorrect."); // // Test with upper case value. // actualValue = converter.ConvertBack("F00D"); Assert.IsNotNull(actualValue, "Converted value is null."); Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect."); Assert.AreEqual(0xF00D, actualValue, "Converted value is incorrect."); }