コード例 #1
0
        public void InverseBoolConverter_ReturnsInverseBool()
        {
            inverseBoolConverter = new InverseBoolConverter();

            bool testConvertFalse     = (bool)inverseBoolConverter.Convert(valueFalse, typeof(bool), null, CultureInfo.CurrentCulture);
            bool testConvertTrue      = (bool)inverseBoolConverter.Convert(valueTrue, typeof(bool), null, CultureInfo.CurrentCulture);
            bool testConvertBackFalse = (bool)inverseBoolConverter.ConvertBack(valueFalse, typeof(bool), null, CultureInfo.CurrentCulture);
            bool testConvertBackTrue  = (bool)inverseBoolConverter.ConvertBack(valueTrue, typeof(bool), null, CultureInfo.CurrentCulture);


            Assert.IsTrue(testConvertFalse);
            Assert.IsFalse(testConvertTrue);
            Assert.IsTrue(testConvertBackFalse);
            Assert.IsFalse(testConvertBackTrue);
        }
コード例 #2
0
        public void ShouldInvertBack(bool value)
        {
            var converter = new InverseBoolConverter();
            var result    = converter.ConvertBack(value, null, null, null);

            Assert.AreEqual(!value, result);
        }
コード例 #3
0
        public void ConvertBack_NotBool()
        {
            // Arrange
            var converter = new InverseBoolConverter();

            // Act
            var result = (bool)converter.ConvertBack(new object(), null, null, null);

            // Assert
            Assert.IsFalse(result);
        }
コード例 #4
0
        public void ConvertBack_False()
        {
            // Arrange
            var converter = new InverseBoolConverter();

            // Act
            var result = (bool)converter.ConvertBack(false, null, null, null);

            // Assert
            Assert.IsTrue(result);
        }
コード例 #5
0
        public void InverseBoolConverter_HandlesNullInput_ExpectedNullReferenceExcpetion()
        {
            inverseBoolConverter = new InverseBoolConverter();
            object testConvertNull;

            try
            {
                testConvertNull = inverseBoolConverter.Convert(valueNull, typeof(bool), null, CultureInfo.CurrentCulture);
            }
            catch (Exception ex)
            {
                Assert.AreEqual(typeof(NullReferenceException), ex.GetType());
            }

            try
            {
                testConvertNull = inverseBoolConverter.ConvertBack(valueNull, typeof(bool), null, CultureInfo.CurrentCulture);
            }
            catch (Exception ex)
            {
                Assert.AreEqual(typeof(NullReferenceException), ex.GetType());
            }
        }
コード例 #6
0
        public void ShouldFailToConvertBackNonBool()
        {
            var converter = new InverseBoolConverter();

            converter.ConvertBack(new object(), null, null, null);
        }
コード例 #7
0
        public void ConvertBackTest(object value, object correctValue)
        {
            var resultValue = _converter.ConvertBack(value, value.GetType(), null, CultureInfo.CurrentCulture);

            Assert.AreEqual(correctValue, resultValue);
        }