예제 #1
0
        public static void Constructor_ExpectedValues()
        {
            // Call
            var converter = new NaNToEmptyValueConverter();

            // Assert
            Assert.That(converter, Is.InstanceOf <IValueConverter>());
        }
예제 #2
0
        public void Convert_WithValidValueAndDutchCultureAndTargetTypeIsObject_ReturnsExpectedString(double value, string expectedValue)
        {
            // Setup
            var converter = new NaNToEmptyValueConverter();

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

            // Assert
            Assert.That(result, Is.EqualTo(expectedValue));
        }
예제 #3
0
        public void ConvertBack_WithNonDoubleValueType_ReturnsNull(object value)
        {
            // Setup
            var converter = new NaNToEmptyValueConverter();

            // Call
            object result = converter.ConvertBack(value, typeof(double), null, null);

            // Assert
            Assert.That(result, Is.Null);
        }
예제 #4
0
        public void ConvertBack_WithDoubleValueType_ReturnsExpectedResult(string value, double expectedResult)
        {
            // Setup
            var converter = new NaNToEmptyValueConverter();

            // Call
            object result = converter.ConvertBack(value, typeof(double), null, null);

            // Assert
            Assert.That(result, Is.EqualTo(expectedResult).Within(1e-5));
        }
예제 #5
0
        public void Convert_WithUnsupportedValue_ThrowsNotSupportedException(object unsupportedValue)
        {
            // Setup
            var converter = new NaNToEmptyValueConverter();

            // 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));
        }
예제 #6
0
        public void ConvertBack_WithUnsupportedType_ThrowsNotSupportedException()
        {
            // Setup
            var converter = new NaNToEmptyValueConverter();

            Type unsupportedType = typeof(object);

            // Call
            TestDelegate call = () => converter.ConvertBack("1", unsupportedType, null, null);

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

            Assert.That(call, Throws.Exception.InstanceOf <NotSupportedException>()
                        .And.Message.EqualTo(expectedMessage));
        }
예제 #7
0
        public void Convert_WithUnsupportedType_ThrowsNotSupportedException()
        {
            // Setup
            var    random         = new Random(21);
            double valueToConvert = random.NextDouble();

            var converter = new NaNToEmptyValueConverter();

            Type unsupportedType = typeof(int);

            // 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));
        }