Esempio n. 1
0
        public IMvxUpdateableBinding BindSingle(object source, object target, string targetPropertyName,
                                                string partialBindingDescription)
        {
            var bindingDescription = this.GetService<IMvxBindingDescriptionParser>().ParseSingle(partialBindingDescription);
            if (bindingDescription == null)
                return null;

            bindingDescription.TargetName = targetPropertyName;
            var request = new MvxBindingRequest(source, target, bindingDescription);
            return BindSingle(request);
        }
Esempio n. 2
0
 public MvxFullBinding(MvxBindingRequest bindingRequest)
 {
     _bindingDescription = bindingRequest.Description;
     CreateTargetBinding(bindingRequest.Target);
     CreateSourceBinding(bindingRequest.Source);
 }
Esempio n. 3
0
        // TODO: need to test other things like:
        // - event subscription (hard to do through Moq)
        // - use of valueConverter
        // - one time subscription
        // - fallback values
        // - setup again on DataContext change
        // - dispose mechanism

        private void TestCommon(MvxBindingMode bindingMode, bool expectSourceBinding, bool expectTargetBinding)
        {
            var mockSourceBindingFactory = new Mock<IMvxSourceBindingFactory>();
            Ioc.RegisterServiceInstance<IMvxSourceBindingFactory>(mockSourceBindingFactory.Object);

            var mockTargetBindingFactory = new Mock<IMvxTargetBindingFactory>();
            Ioc.RegisterServiceInstance<IMvxTargetBindingFactory>(mockTargetBindingFactory.Object);

            var sourceText = "sourceText";
            var targetName = "targetName";
            var source = new {Value = 1};
            var target = new {Value = 2};
            var converterParameter = new {Value = 3};
            var fallbackValue = new {Value = 4};
            var converter = new Mock<IMvxValueConverter>();
            var bindingDescription = new MvxBindingDescription()
                {
                    Converter = converter.Object,
                    ConverterParameter = converterParameter,
                    FallbackValue = fallbackValue,
                    Mode = bindingMode,
                    SourcePropertyPath = sourceText,
                    TargetName = targetName
                };

            var mockSourceBinding = new Mock<IMvxSourceBinding>();
            var mockTargetBinding = new Mock<IMvxTargetBinding>();

            mockSourceBindingFactory
                .Setup(x => x.CreateBinding(It.Is<object>(s => s == source), It.Is<string>(s => s == sourceText)))
                .Returns((object a, string b) => mockSourceBinding.Object);
            mockTargetBindingFactory
                .Setup(x => x.CreateBinding(It.Is<object>(s => s == target), It.Is<string>(s => s == targetName)))
                .Returns((object a, string b) => mockTargetBinding.Object);

            var request = new MvxBindingRequest(source, target, bindingDescription);

            var toTest = new MvxFullBinding(request);

            //var sourceBindingTimes = expectSourceBinding ? Times.Once() : Times.Never();
            //mockSourceBinding.Verify(x => x.Changed += It.IsAny<EventHandler<MvxSourcePropertyBindingEventArgs>>(), sourceBindingTimes);
            mockSourceBindingFactory
                .Verify(x => x.CreateBinding(It.Is<object>(s => s == source), It.Is<string>(s => s == sourceText)), Times.Once());

            //var targetBindingTimes = expectSourceBinding ? Times.Once() : Times.Never();
            //mockTargetBinding.Verify(x => x.ValueChanged += It.IsAny<EventHandler<MvxTargetChangedEventArgs>>(), targetBindingTimes);
            mockTargetBindingFactory
                .Verify(x => x.CreateBinding(It.Is<object>(s => s == target), It.Is<string>(s => s == targetName)), Times.Once());
        }
Esempio n. 4
0
 public MyBinding(MvxBindingRequest bindingRequest)
     : base(bindingRequest)
 {
 }
Esempio n. 5
0
 public IMvxUpdateableBinding BindSingle(MvxBindingRequest bindingRequest)
 {
     return new MvxFullBinding(bindingRequest);
 }