Beispiel #1
0
        public void ConvertBack_ValidStringToBoolean_ReturnsExpected(object value, bool expectedResult, string whenTrue, string whenFalse)
        {
            var uut = new BooleanToStringValueConverterAndValidationRule()
            {
                WhenTrue  = whenTrue,
                WhenFalse = whenFalse
            };

            var targetType = typeof(bool);
            var parameter  = (object)null;
            var culture    = (CultureInfo)null;

            uut.ConvertBack(value, targetType, parameter, culture).ShouldBe(expectedResult);
        }
Beispiel #2
0
        public void ConvertBack_ConversionIsInvalid_ThrowsException(object value, Type targetType)
        {
            var uut = new BooleanToStringValueConverterAndValidationRule();

            var parameter = (object)null;
            var culture   = (CultureInfo)null;

            var result = Should.Throw <NotSupportedException>(() =>
            {
                uut.ConvertBack(value, targetType, parameter, culture);
            });

            result.ShouldSatisfyAllConditions(
                () => result.Message.ShouldContain(value?.GetType().Name ?? "null"),
                () => result.Message.ShouldContain(targetType.Name));
        }
Beispiel #3
0
        public void ConvertBack_TargetTypeIsNull_ThrowsException()
        {
            var uut = new BooleanToStringValueConverterAndValidationRule();

            var value      = false;
            var targetType = (Type)null;
            var parameter  = (object)null;
            var culture    = (CultureInfo)null;

            var result = Should.Throw <ArgumentNullException>(() =>
            {
                uut.ConvertBack(value, targetType, parameter, culture);
            });

            result.ParamName.ShouldBe(nameof(targetType));
        }
Beispiel #4
0
        public void ConvertBack_InvalidStringToBoolean_ThrowsException(object value, string whenTrue, string whenFalse)
        {
            var uut = new BooleanToStringValueConverterAndValidationRule()
            {
                WhenTrue  = whenTrue,
                WhenFalse = whenFalse
            };

            var targetType = typeof(bool);
            var parameter  = (object)null;
            var culture    = (CultureInfo)null;

            var result = Should.Throw <ArgumentException>(() =>
            {
                uut.ConvertBack(value, targetType, parameter, culture);
            });

            result.ShouldSatisfyAllConditions(
                () => result.ParamName.ShouldBe(nameof(value)),
                () => result.Message.ShouldContain(whenTrue),
                () => result.Message.ShouldContain(whenFalse));
        }