public void convert_back_returns_mapped_value_if_mapping_exists()
        {
            var converter = new MapConverter();

            converter.Mappings.Add(new Mapping("from", "to"));
            converter.Mappings.Add(new Mapping(null, "NULL"));
            converter.Mappings.Add(new Mapping(123, 123.5d));

            Assert.Same("from", converter.ConvertBack("to", null, null, null));
            Assert.Null(converter.ConvertBack("NULL", null, null, null));
            Assert.Equal(123, converter.ConvertBack(123.5d, null, null, null));
        }
        public void convert_back_honors_fallback_behavior_if_conversion_fails()
        {
            var converter = new MapConverter();
            converter.Mappings.Add(new Mapping("from", "to"));

            Assert.Same(DependencyProperty.UnsetValue, converter.ConvertBack(null, null, null, null));
            Assert.Same(DependencyProperty.UnsetValue, converter.ConvertBack("abc", null, null, null));
            Assert.Same(DependencyProperty.UnsetValue, converter.ConvertBack(123, null, null, null));

            converter.FallbackBehavior = FallbackBehavior.ReturnOriginalValue;

            Assert.Null(converter.ConvertBack(null, null, null, null));
            Assert.Same("abc", converter.ConvertBack("abc", null, null, null));
            Assert.Equal(123, converter.ConvertBack(123, null, null, null));

            converter.FallbackBehavior = FallbackBehavior.ReturnFallbackValue;
            converter.FallbackValue = "my fallback value";

            Assert.Equal("my fallback value", converter.ConvertBack(null, null, null, null));
            Assert.Equal("my fallback value", converter.ConvertBack("abc", null, null, null));
            Assert.Equal("my fallback value", converter.ConvertBack(123, null, null, null));
        }
        public void convert_back_honors_fallback_behavior_if_conversion_fails()
        {
            var converter = new MapConverter();

            converter.Mappings.Add(new Mapping("from", "to"));

            Assert.Same(DependencyProperty.UnsetValue, converter.ConvertBack(null, null, null, null));
            Assert.Same(DependencyProperty.UnsetValue, converter.ConvertBack("abc", null, null, null));
            Assert.Same(DependencyProperty.UnsetValue, converter.ConvertBack(123, null, null, null));

            converter.FallbackBehavior = FallbackBehavior.ReturnOriginalValue;

            Assert.Null(converter.ConvertBack(null, null, null, null));
            Assert.Same("abc", converter.ConvertBack("abc", null, null, null));
            Assert.Equal(123, converter.ConvertBack(123, null, null, null));

            converter.FallbackBehavior = FallbackBehavior.ReturnFallbackValue;
            converter.FallbackValue    = "my fallback value";

            Assert.Equal("my fallback value", converter.ConvertBack(null, null, null, null));
            Assert.Equal("my fallback value", converter.ConvertBack("abc", null, null, null));
            Assert.Equal("my fallback value", converter.ConvertBack(123, null, null, null));
        }
        public void convert_back_returns_default_value_if_no_mapping_exists()
        {
            var converter = new MapConverter();

            converter.Mappings.Add(new Mapping("from", "to"));

            converter.FallbackBehavior = FallbackBehavior.ReturnUnsetValue;

            Assert.Same(DependencyProperty.UnsetValue, converter.ConvertBack(null, null, null, null));
            Assert.Same(DependencyProperty.UnsetValue, converter.ConvertBack("abc", null, null, null));
            Assert.Same(DependencyProperty.UnsetValue, converter.ConvertBack(123, null, null, null));

            converter.FallbackBehavior = FallbackBehavior.ReturnOriginalValue;

            Assert.Null(converter.ConvertBack(null, null, null, null));
            Assert.Same("abc", converter.ConvertBack("abc", null, null, null));
            Assert.Equal(123, converter.ConvertBack(123, null, null, null));
        }
        public void convert_back_returns_mapped_value_if_mapping_exists()
        {
            var converter = new MapConverter();
            converter.Mappings.Add(new Mapping("from", "to"));
            converter.Mappings.Add(new Mapping(null, "NULL"));
            converter.Mappings.Add(new Mapping(123, 123.5d));

            Assert.Same("from", converter.ConvertBack("to", null, null, null));
            Assert.Null(converter.ConvertBack("NULL", null, null, null));
            Assert.Equal(123, converter.ConvertBack(123.5d, null, null, null));
        }
        public void convert_back_returns_default_value_if_no_mapping_exists()
        {
            var converter = new MapConverter();
            converter.Mappings.Add(new Mapping("from", "to"));

            converter.FallbackBehavior = FallbackBehavior.ReturnUnsetValue;

            Assert.Same(DependencyProperty.UnsetValue, converter.ConvertBack(null, null, null, null));
            Assert.Same(DependencyProperty.UnsetValue, converter.ConvertBack("abc", null, null, null));
            Assert.Same(DependencyProperty.UnsetValue, converter.ConvertBack(123, null, null, null));

            converter.FallbackBehavior = FallbackBehavior.ReturnOriginalValue;

            Assert.Null(converter.ConvertBack(null, null, null, null));
            Assert.Same("abc", converter.ConvertBack("abc", null, null, null));
            Assert.Equal(123, converter.ConvertBack(123, null, null, null));
        }