Beispiel #1
0
        public void Convert_WithValidValue_ReturnsExpectedString(int?value, string expectedValue)
        {
            // Setup
            var converter = new IntegerValueConverter();

            // Call
            object result = converter.Convert(value, typeof(string), null, null);

            // Assert
            Assert.That(result, Is.EqualTo(expectedValue));
        }
Beispiel #2
0
        public void Convert_WithUnsupportedValue_ThrowsNotSupportedException(object unsupportedValue)
        {
            // Setup
            var converter = new IntegerValueConverter();

            // Call
            TestDelegate call = () => converter.Convert(unsupportedValue, typeof(string), null, null);

            // Assert
            string expectedMessage = $"Conversion from {unsupportedValue?.GetType().Name} is not supported.";

            Assert.That(call, Throws.Exception.InstanceOf <NotSupportedException>()
                        .And.Message.EqualTo(expectedMessage));
        }
Beispiel #3
0
        public void Convert_WithUnsupportedType_ThrowsNotSupportedException()
        {
            // Setup
            var random         = new Random(21);
            int valueToConvert = random.Next();

            var converter = new IntegerValueConverter();

            Type unsupportedType = typeof(object);

            // Call
            TestDelegate call = () => converter.Convert(valueToConvert, unsupportedType, null, null);

            // Assert
            string expectedMessage = $"Conversion to {unsupportedType.Name} is not supported.";

            Assert.That(call, Throws.Exception.InstanceOf <NotSupportedException>()
                        .And.Message.EqualTo(expectedMessage));
        }