예제 #1
0
        public void BoolConverter_ConvertBack()
        {
            IValueConverter converter;
            object          actualValue;
            Type            expectedType;

            converter    = new BoolConverter();
            expectedType = typeof(bool);

            //
            // Test with null.
            //

            try
            {
                converter.ConvertBack(null);
                Assert.Fail("Expected ArgumentNullException to be thrown.");
            }
            catch (NotSupportedException)
            {
            }

            //
            // Test with incorrect value.
            //

            try
            {
                converter.ConvertBack("true");
                Assert.Fail("Expected ArgumentException to be thrown.");
            }
            catch (NotSupportedException)
            {
            }

            //
            // Test with true.
            //

            actualValue = converter.ConvertBack("yes");
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual(true, actualValue, "Converted value is incorrect.");

            //
            // Test with false.
            //

            actualValue = converter.ConvertBack("no");
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual(false, actualValue, "Converted value is incorrect.");
        }
        public void BoolConverter_ConvertBack()
        {
            IValueConverter converter;
            object actualValue;
            Type expectedType;

            converter = new BoolConverter();
            expectedType = typeof(bool);

            //
            // Test with null.
            //

            try
            {
                converter.ConvertBack(null);
                Assert.Fail("Expected ArgumentNullException to be thrown.");
            }
            catch (NotSupportedException)
            {
            }

            //
            // Test with incorrect value.
            //

            try
            {
                converter.ConvertBack("true");
                Assert.Fail("Expected ArgumentException to be thrown.");
            }
            catch (NotSupportedException)
            {
            }

            //
            // Test with true.
            //

            actualValue = converter.ConvertBack("yes");
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual(true, actualValue, "Converted value is incorrect.");

            //
            // Test with false.
            //

            actualValue = converter.ConvertBack("no");
            Assert.IsNotNull(actualValue, "Converted value is null.");
            Assert.AreEqual(expectedType, actualValue.GetType(), "Type of converted value is incorrect.");
            Assert.AreEqual(false, actualValue, "Converted value is incorrect.");
        }