예제 #1
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 ConvertBackTest()
        {
            var inverse = testConverter.ConvertBack(!TestValue, null, null, null);

            Assert.IsInstanceOfType(inverse, typeof(bool));
            Assert.AreEqual(inverse, TestValue);
        }
        public void InverseBooleanConverter_ConvertBack_ThrowsNotImplementedException()
        {
            // Action
            Action convertBackAction = () => inverseBooleanConverter.ConvertBack(null, null, null, null);

            // Assert
            convertBackAction.Should().Throw <NotImplementedException>();
        }
예제 #4
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]"}'.");
            }
        }
예제 #5
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);
        }
        public void ConvertBack_ValueIsNotBoolean_ReturnsFalse()
        {
            var result = _target.ConvertBack("hans", typeof(bool), null, CultureInfo.InvariantCulture);

            Assert.IsTrue((bool)result);
        }
예제 #7
0
        public void TestConvertBack(bool value, bool expected)
        {
            var actual = _inverseBooleanConverter.ConvertBack(value, null, null, null);

            Assert.AreEqual(expected, actual);
        }
        public void VerifyConverterConvertsBackThrows()
        {
            var converter = new InverseBooleanConverter();

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