コード例 #1
0
        public void GetValueShouldReturnValueUsingConverterTarget()
        {
            bool converterInvoked = false;
            var memberMock = new BindingMemberInfoMock
            {
                Type = typeof(int)
            };
            CultureInfo culture = CultureInfo.InvariantCulture;
            var parameter = new object();
            var sourceModel = new BindingSourceModel();
            var converterMock = new ValueConverterCoreMock
            {
                ConvertBack = (o, type, arg3, arg4) =>
                {
                    converterInvoked = true;
                    o.ShouldEqual(sourceModel.IntProperty);
                    type.ShouldEqual(typeof(int));
                    arg3.ShouldEqual(parameter);
                    arg4.ShouldEqual(culture);
                    return int.MaxValue;
                }
            };
            var dataContext = new DataContext
            {
                {BindingBuilderConstants.Converter, d => converterMock},
                {BindingBuilderConstants.ConverterCulture, d => culture},
                {BindingBuilderConstants.ConverterParameter, d => parameter}
            };

            string propertyName = GetMemberPath<BindingSourceModel>(model => model.IntProperty);
            var valueAccessor = GetAccessor(sourceModel, propertyName, dataContext, false);
            valueAccessor.GetValue(memberMock, EmptyContext, true).ShouldEqual(int.MaxValue);
            converterInvoked.ShouldBeTrue();
        }
コード例 #2
0
        public void GetValueShouldReturnValueUsingConverterSourceDoubleSource()
        {
            bool converterInvoked = false;
            var  memberMock       = new BindingMemberInfoMock
            {
                Type = typeof(int)
            };
            CultureInfo culture       = CultureInfo.InvariantCulture;
            var         parameter     = new object();
            var         sourceModel   = new BindingSourceModel();
            var         converterMock = new ValueConverterCoreMock
            {
                Convert = (o, type, arg3, arg4) =>
                {
                    converterInvoked = true;
                    o.ShouldEqual(sourceModel.IntProperty.ToString() + sourceModel.ObjectProperty);
                    type.ShouldEqual(typeof(int));
                    arg3.ShouldEqual(parameter);
                    arg4.ShouldEqual(culture);
                    return(int.MaxValue);
                }
            };
            var dataContext = new DataContext
            {
                { BindingBuilderConstants.Converter, d => converterMock },
                { BindingBuilderConstants.ConverterCulture, d => culture },
                { BindingBuilderConstants.ConverterParameter, d => parameter }
            };

            string propertyName  = GetMemberPath <BindingSourceModel>(model => model.IntProperty);
            var    valueAccessor = new MultiBindingSourceAccessor(new[]
            {
                CreateSource(sourceModel, propertyName),
                CreateSource(sourceModel, GetMemberPath(sourceModel, model => model.ObjectProperty)),
            },
                                                                  (context, list) => list[0].ToString() + list[1], dataContext);

            valueAccessor.GetValue(memberMock, EmptyContext, true).ShouldEqual(int.MaxValue);
            converterInvoked.ShouldBeTrue();
        }