public void Convert(object value, bool expected)
        {
            var sut    = new BooleanConverter();
            var actual = sut.Convert(value);

            Assert.Equal(expected, actual);
        }
        private Boolean Evaluate(Object value)
        {
            var sut    = new BooleanConverter();
            var result = (Boolean)sut.Convert(value, typeof(Boolean), null, null);

            return(result);
        }
        public void TestBooleanConverterTrue()
        {
            BooleanConverter booleanConverter = new BooleanConverter();
            string           a = (string)booleanConverter.Convert(true, typeof(Boolean), null, default);

            Assert.AreEqual(a, "Yes");
        }
        public void TestBooleanConverterFalse()
        {
            BooleanConverter booleanConverter = new BooleanConverter();
            string           a = (string)booleanConverter.Convert(false, typeof(Boolean), null, default);

            Assert.AreEqual(a, "No");
        }
예제 #5
0
        public void UpperFalseConversion()
        {
            // Arrange
            IConverter converter = new BooleanConverter();
            var        value     = "False";

            // Act
            var actual = converter.Convert(value, converter.TargetType);

            // Assert
            Assert.NotNull(actual);
            Assert.IsType <bool>(actual);
            Assert.False((bool)actual);
        }
예제 #6
0
        public void StringEmptyConversion()
        {
            // Arrange
            IConverter converter = new BooleanConverter();
            var        value     = string.Empty;

            // Act
            var actual = converter.Convert(value, converter.TargetType);

            // Assert
            Assert.NotNull(actual);
            Assert.IsType <bool>(actual);
            Assert.True((bool)actual);
        }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     return(BooleanConverter.Convert(value, Visibility.Visible, Visibility.Collapsed));
 }
예제 #8
0
        public void BadValueConversion()
        {
            // Arrange
            IConverter converter = new BooleanConverter();
            var        value     = "Hello";
            var        expectedExceptionMessage      = Constants.ExceptionMessages.FormatConverterUnableConvert(value, typeof(bool));
            var        expectedInnerExceptionMessage = "String was not recognized as a valid Boolean.";

            // 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);
            }
        }
예제 #9
0
        public void TestConvertTrueObject()
        {
            var convertedObject = _converter.Convert(true, null, null, null);

            Assert.Same(convertedObject, _trueObject);
        }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     return(BooleanConverter.Convert(value, trueValue, falseValue));
 }
        public void TestBooleanConverter()
        {
            BooleanConverter booleanConverter = new BooleanConverter();

            Assert.True(booleanConverter.CanConvertTo(typeof(bool)));
            Assert.True(booleanConverter.CanConvertTo(typeof(Boolean)));

            Assert.False(booleanConverter.CanConvertTo(typeof(string)));
            Assert.False(booleanConverter.CanConvertTo(typeof(float)));
            Assert.False(booleanConverter.CanConvertTo(typeof(double)));
            Assert.False(booleanConverter.CanConvertTo(typeof(int)));

            Assert.True(booleanConverter.CanConvertFrom(" oN   "));
            Assert.True(booleanConverter.CanConvertFrom("OFF  "));
            Assert.True(booleanConverter.CanConvertFrom(" YeS"));
            Assert.True(booleanConverter.CanConvertFrom("No"));
            Assert.True(booleanConverter.CanConvertFrom("true"));
            Assert.True(booleanConverter.CanConvertFrom("FALSE"));
            Assert.True(booleanConverter.CanConvertFrom("10"));

            Assert.False(booleanConverter.CanConvertFrom("abc"));
            Assert.False(booleanConverter.CanConvertFrom("No!"));

            Assert.Equal(true, booleanConverter.Convert(typeof(bool), "TRUE"));
            Assert.Equal(false, booleanConverter.Convert(typeof(object), "fAlSe"));
            Assert.Equal(true, booleanConverter.Convert(typeof(bool), "on"));
            Assert.Equal(false, booleanConverter.Convert(typeof(object), "oFF"));
            Assert.Equal(true, booleanConverter.Convert(typeof(bool), "yeS"));
            Assert.Equal(false, booleanConverter.Convert(typeof(object), "No"));
            Assert.Equal(true, booleanConverter.Convert(typeof(bool), "-10"));
            Assert.Equal(true, booleanConverter.Convert(typeof(bool), "123"));
            Assert.Equal(false, booleanConverter.Convert(typeof(object), "0"));

            Assert.Throws <InvalidOperationException>(() => booleanConverter.Convert(typeof(object), "0.0"));
            Assert.Throws <InvalidOperationException>(() => booleanConverter.Convert(typeof(object), "XYZ"));
        }