Ejemplo n.º 1
0
        public void Convert_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.Convert(value, targetType, parameter, culture).ShouldBe(expectedResult);
        }
Ejemplo n.º 2
0
        public void Convert_ConversionIsInvalid_ThrowsException(object value, Type targetType)
        {
            var uut = new BooleanToStringValueConverterAndValidationRule();

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

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

            result.ShouldSatisfyAllConditions(
                () => result.Message.ShouldContain(value?.GetType().Name ?? "null"),
                () => result.Message.ShouldContain(targetType.Name));
        }
Ejemplo n.º 3
0
        public void Convert_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.Convert(value, targetType, parameter, culture);
            });

            result.ParamName.ShouldBe(nameof(targetType));
        }
Ejemplo n.º 4
0
        public void Convert_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.Convert(value, targetType, parameter, culture);
            });

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