public void ShouldReturnByteArray() { var converter = new Int32Converter(); const int data = 0x11223344; var bytes = converter.Convert(data).ToArray(); bytes.Should().HaveCount(4); bytes[0].Should().Be(0x44); bytes[1].Should().Be(0x33); bytes[2].Should().Be(0x22); bytes[3].Should().Be(0x11); }
public void Conversion() { // Arrange IConverter converter = new Int32Converter(); var value = "42"; var expectedValue = 42; // Act var actualValue = converter.Convert(value, converter.TargetType); // Assert Assert.NotNull(actualValue); Assert.IsType <Int32>(actualValue); Assert.Equal(expectedValue, (Int32)actualValue); }
public void BadValueConversion() { // Arrange IConverter converter = new Int32Converter(); var value = "Hello"; var expectedExceptionMessage = Constants.ExceptionMessages.FormatConverterUnableConvert(value, typeof(int)); var expectedInnerExceptionMessage = "Input string was not in a correct format."; // 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); } }