예제 #1
0
 protected virtual void RegisterValueConverterProvider()
 {
     var registry = new MvxValueConverterRegistry();
     this.RegisterServiceInstance<IMvxValueConverterRegistry>(registry);
     this.RegisterServiceInstance<IMvxValueConverterProvider>(registry);
     FillValueConverters(registry);
 }
        private void DoTest(
            Action<MockBindingContext> action,
            Func<MockBindingContext, object> findTargetObjectFunc,
            MvxBindingDescription expectedDescription)
        {
            ClearAll();
            MvxBindingSingletonCache.Initialize();

            var dataContext = new TestDataContext();

            var bindingContext = new Mock<IMvxBindingContext>();
            bindingContext.Setup(x => x.RegisterBinding(It.IsAny<object>(), It.IsAny<IMvxUpdateableBinding>()));
            bindingContext.SetupGet(x => x.DataContext).Returns(dataContext);

            var callbacksSeen = new List<Callback>();

            var binder = new Mock<IMvxBinder>();
            binder.Setup(
                b => b.Bind(It.IsAny<object>(), It.IsAny<object>(), It.IsAny<IEnumerable<MvxBindingDescription>>()))
                  .Callback((object source, object target, IEnumerable<MvxBindingDescription> descriptions) =>
                      {
                          if (descriptions.Count() != 1)
                              throw new Exception("Unexpected description count");

                          callbacksSeen.Add(new Callback
                          {
                              Source = source,
                              Target = target,
                              BindingDescription = descriptions.First()
                          });
                      });
            Ioc.RegisterSingleton(binder.Object);

            Ioc.RegisterSingleton<IMvxPropertyExpressionParser>(new MvxPropertyExpressionParser());

            var converterLookup = new MvxValueConverterRegistry();
            converterLookup.AddOrOverwrite("SampleConv", new SampleValueConverter());
            Ioc.RegisterSingleton<IMvxValueConverterLookup>(converterLookup);

            var testTarget = new MockBindingContext
            {
                Target = new TestTarget(),
                BindingContext = bindingContext.Object
            };

            action(testTarget);

            Assert.AreEqual(1, callbacksSeen.Count);
            var callback = callbacksSeen[0];
            var expectedTarget = findTargetObjectFunc(testTarget);
            Assert.AreEqual(expectedTarget, callback.Target);
            Assert.AreEqual(dataContext, callback.Source);

            var desc = callback.BindingDescription;
            Assert.IsTrue(expectedDescription.Source is MvxPathSourceStepDescription);
            var path = desc.Source as MvxPathSourceStepDescription;
            Assert.IsTrue(desc.Source is MvxPathSourceStepDescription);
            var expectedPath = expectedDescription.Source as MvxPathSourceStepDescription;
            Assert.AreEqual(expectedPath.ConverterParameter, path.ConverterParameter);
            Assert.AreEqual(expectedPath.FallbackValue, path.FallbackValue);
            Assert.AreEqual(expectedPath.SourcePropertyPath, path.SourcePropertyPath);
            Assert.AreEqual(expectedDescription.Mode, desc.Mode);
            Assert.AreEqual(expectedDescription.TargetName, desc.TargetName);
            if (expectedPath.Converter == null)
                Assert.IsNull(path.Converter);
            else
                Assert.AreEqual(expectedPath.Converter.GetType(), path.Converter.GetType());
        }
 protected virtual void RegisterValueConverterProvider()
 {
     var registry = new MvxValueConverterRegistry();
     Mvx.RegisterSingleton<IMvxValueConverterLookup>(registry);
     Mvx.RegisterSingleton<IMvxValueConverterRegistry>(registry);
     FillValueConverters(registry);
 }