public void Convert_WrongDataType_ExceptionThrown()
        {
            var sut = new InverseBooleanConverter();

            sut.Invoking(x => x.Convert(true, typeof(int), 0, CultureInfo.InvariantCulture)).Should()
            .Throw <ArgumentException>();
        }
        public void Convert_AllPossibleInputs_Converted(bool input, bool expected)
        {
            var sut = new InverseBooleanConverter();

            var result = sut.Convert(input, typeof(bool), 0, CultureInfo.InvariantCulture);

            result.Should().Be(expected);
        }
Esempio n. 3
0
        public void ConvertTest()
        {
            InverseBooleanConverter converter = new InverseBooleanConverter();
            bool b     = false;
            var  value = (bool)converter.Convert(b, typeof(bool), null, CultureInfo.CurrentCulture);

            Assert.IsTrue(value);
        }
        public void WhenConvertingFalseThenResultIsTrue()
        {
            var inverseBooleanConverter = new InverseBooleanConverter();

            object result = inverseBooleanConverter.Convert(false, typeof(bool), null, new CultureInfo("en-us"));

            Assert.IsInstanceOfType(result, typeof(bool));
            Assert.AreEqual(result, true);
        }
Esempio n. 5
0
        public void ShouldThrowIfTargetIsNotABool()
        {
            var ibc = new InverseBooleanConverter();

            Assert.Throws <InvalidOperationException>(() => ibc.Convert(false, null, null, null));
            Assert.Throws <InvalidOperationException>(() => ibc.ConvertBack(false, null, null, null));
            Assert.Throws <InvalidOperationException>(() => ibc.Convert(false, typeof(string), null, null));
            Assert.Throws <InvalidOperationException>(() => ibc.ConvertBack(false, typeof(string), null, null));
        }
        public void FalseConvertersToTrue()
        {
            var    converter = new InverseBooleanConverter();
            object output    = null;
            var    exception = Record.Exception(() => { output = converter.Convert(false, typeof(bool), null, CurrentCulture); });

            Assert.Null(exception);
            Assert.NotNull(output);
            Assert.IsType <bool>(output);
            Assert.True((bool)output);
        }
Esempio n. 7
0
        private void CheckConvertBack(object value, bool target, InverseBooleanConverter converter)
        {
            var result = converter.ConvertBack(value, null, null, CultureInfo.CurrentCulture);

            if (result is bool boolean)
            {
                Assert.AreEqual(target, boolean);
            }
            else
            {
                Assert.Fail($"The result should be a boolean but actually is '{result?.GetType().Name ?? "[UNKNOWN]"}'.");
            }
        }
        public void VerifyConverterConverts()
        {
            var converter = new InverseBooleanConverter();

            Assert.Throws <InvalidOperationException>(() => converter.Convert(null, typeof(string), null, null));

            var value = converter.Convert(true, typeof(bool), null, null);

            Assert.IsFalse(value is bool b && b);

            value = converter.Convert(false, typeof(bool), null, null);

            Assert.IsTrue(value is bool c && c);
        }
Esempio n. 9
0
        public void ShouldInverseABool()
        {
            var ibc = new InverseBooleanConverter();

            var result = ibc.Convert(false, typeof(bool), null, null);

            Assert.IsType <bool>(result);
            Assert.True((bool)result);

            result = ibc.ConvertBack(result, typeof(bool), null, null);

            Assert.IsType <bool>(result);
            Assert.False((bool)result);
        }
Esempio n. 10
0
        public void WhenConvertingWithChainedConvertersThenResultWasConvertedByEachConverterInTheExpectedOrder()
        {
            var emptyStringToBooleanConverter = new EmptyStringToBooleanConverter();
            var inverseBooleanConverter       = new InverseBooleanConverter();

            var convertersChain = new ConverterChain(new Collection <IValueConverter>()
            {
                emptyStringToBooleanConverter, inverseBooleanConverter
            });

            object result = convertersChain.Convert("just a string", typeof(bool), null, new CultureInfo("en-us"));

            Assert.IsInstanceOfType(result, typeof(bool));
            Assert.AreEqual(result, true);
        }
Esempio n. 11
0
        public void InverseBooleanConverterConstructorTestMethod()
        {
            InverseBooleanConverter target = new InverseBooleanConverter();
            object value  = null;
            object actual = (target as IValueConverter).Convert(value, typeof(bool), null, null);

            Assert.IsNull(value);

            target.NullSource = true;
            actual            = (target as IValueConverter).Convert(value, typeof(bool), null, null);
            Assert.IsNotNull(actual);
            Assert.IsInstanceOfType(actual, typeof(bool));
            Assert.IsTrue((bool)actual);

            value  = false;
            actual = (target as IValueConverter).Convert(value, typeof(bool), null, null);
            Assert.IsNotNull(actual);
            Assert.IsInstanceOfType(actual, typeof(bool));
            Assert.IsTrue((bool)actual);

            target.NullSource = false;
            actual            = (target as IValueConverter).Convert(value, typeof(bool), null, null);
            Assert.IsNotNull(actual);
            Assert.IsInstanceOfType(actual, typeof(bool));
            Assert.IsTrue((bool)actual);

            value  = false;
            actual = (target as IValueConverter).Convert(value, typeof(bool), null, null);
            Assert.IsNotNull(actual);
            Assert.IsInstanceOfType(actual, typeof(bool));
            Assert.IsTrue((bool)actual);

            value             = true;
            target.NullSource = true;
            actual            = (target as IValueConverter).Convert(value, typeof(bool), null, null);
            Assert.IsNotNull(actual);
            Assert.IsInstanceOfType(actual, typeof(bool));
            Assert.IsFalse((bool)actual);
        }
 static InverseBooleanConverter()
 {
     Instance = new InverseBooleanConverter();
 }
Esempio n. 13
0
 private void CheckConvertBack(bool value, bool target, InverseBooleanConverter converter)
 => this.CheckConvertBack((object)value, target, converter);
 static InverseBooleanConverter()
 {
     Instance = new InverseBooleanConverter();
 }
 public void Setup()
 {
     _target = new InverseBooleanConverter();
 }
 public void Setup()
 {
     _target = new InverseBooleanConverter();
 }
Esempio n. 17
0
 public void SetUp()
 {
     _inverseBooleanConverter = new InverseBooleanConverter();
 }
 public void Setup()
 {
     _converter = new InverseBooleanConverter();
 }
        public void VerifyConverterConvertsBackThrows()
        {
            var converter = new InverseBooleanConverter();

            Assert.Throws <NotSupportedException>(() => converter.ConvertBack(null, null, null, null));
        }