public void TargetType() { // Arrange IConverter converter = new CharConverter(); var expectedType = typeof (Char); // Act var actualType = converter.TargetType; // Assert Assert.Equal(expectedType, actualType); }
public void Conversion() { // Arrange IConverter converter = new CharConverter(); var value = "c"; var expectedValue = 'c'; // Act var actualValue = converter.Convert(value, converter.TargetType); // Assert Assert.NotNull(actualValue); Assert.IsType<char>(actualValue); Assert.Equal(expectedValue, (Char) actualValue); }
public void BadValueConversion() { // Arrange IConverter converter = new CharConverter(); var value = "Hello"; var expectedExceptionMessage = Constants.ExceptionMessages.FormatConverterUnableConvert(value, typeof(char)); var expectedInnerExceptionMessage = "String must be exactly one character long."; // Act using (new LangageSwitcher("en-us")) { var actualException = Assert.Throws<CommandLineParserException>(() => converter.Convert(value, converter.TargetType)); // Assert Assert.Equal(expectedExceptionMessage, actualException.Message); Assert.NotNull(actualException.InnerException); var actualInnerExecption = Assert.IsAssignableFrom<FormatException>(actualException.InnerException); Assert.Equal(expectedInnerExceptionMessage, actualInnerExecption.Message); } }