예제 #1
0
        public void FullyTypedTwoWayWithParam() => AssertExperimental(() =>
        {
            var converter = new FuncConverter <bool, Color, double>(
                (isRed, alpha) => (isRed ? Color.Red : Color.Green).MultiplyAlpha(alpha),
                (color, alpha) => color == Color.Red.MultiplyAlpha(alpha)
                ).AssertConvert(true, 0.5, Color.Red.MultiplyAlpha(0.5), twoWay: true)
                            .AssertConvert(false, 0.2, Color.Green.MultiplyAlpha(0.2), twoWay: true);

            Assert.That(converter.Convert(null, typeof(object), null, CultureInfo.InvariantCulture), Is.EqualTo(Color.Green.MultiplyAlpha(default(double))));
            Assert.That(converter.ConvertBack(null, typeof(object), null, CultureInfo.InvariantCulture), Is.EqualTo(default(bool)));
        });
예제 #2
0
        public void FullyTypedTwoWay() => AssertExperimental(() =>
        {
            var converter = new FuncConverter <bool, Color, object>(
                isRed => isRed ? Color.Red : Color.Green,
                color => color == Color.Red
                ).AssertConvert(true, Color.Red, twoWay: true)
                            .AssertConvert(false, Color.Green, twoWay: true);

            Assert.That(converter.Convert(null, typeof(object), null, CultureInfo.InvariantCulture), Is.EqualTo(Color.Green));
            Assert.That(converter.ConvertBack(null, typeof(object), null, CultureInfo.InvariantCulture), Is.EqualTo(default(bool)));
        });
예제 #3
0
        public void FullyTypedTwoWayWithParamAndCulture() => AssertExperimental(() =>
        {
            CultureInfo convertCulture = null, convertBackCulture = null;
            var expectedCulture        = System.Threading.Thread.CurrentThread.CurrentUICulture;

            var converter = new FuncConverter <bool, Color, double>(
                (isRed, alpha, culture) => { convertCulture = culture; return((isRed ? Color.Red : Color.Green).MultiplyAlpha(alpha)); },
                (color, alpha, culture) => { convertBackCulture = culture; return(color == Color.Red.MultiplyAlpha(alpha)); }
                ).AssertConvert(true, 0.5, Color.Red.MultiplyAlpha(0.5), twoWay: true, culture: expectedCulture)
                            .AssertConvert(false, 0.2, Color.Green.MultiplyAlpha(0.2), twoWay: true, culture: expectedCulture);

            Assert.That(convertCulture, Is.EqualTo(expectedCulture));
            Assert.That(convertBackCulture, Is.EqualTo(expectedCulture));

            Assert.That(converter.Convert(null, typeof(object), null, CultureInfo.InvariantCulture), Is.EqualTo(Color.Green.MultiplyAlpha(default(double))));
            Assert.That(converter.ConvertBack(null, typeof(object), null, CultureInfo.InvariantCulture), Is.EqualTo(default(bool)));
        });