public BindingResourcesViewModel() { var resourceResolver = BindingServiceProvider.ResourceResolver; _objResource = new BindingResourceObject("String value"); resourceResolver.AddObject("obj", _objResource); resourceResolver.AddMethod("Method", new BindingResourceMethod(Method, typeof(object))); resourceResolver.AddType("CustomType", typeof(BindingResourcesViewModel)); UpdateResourceCommand = new RelayCommand(UpdateResource); }
public void ResolverShouldRegisterAndResolveObject() { const string name = "name"; var source = new BindingResourceObject("test"); var resolver = CreateBindingResourceResolver(); resolver.ResolveObject(name, EmptyContext, false).Value.ShouldBeNull(); resolver.AddObject(name, source, true); resolver.ResolveObject(name, EmptyContext, true).Value.ShouldEqual(source.Value); }
public void ResolverShouldRegisterAndResolveDynamicObject() { const string name = "name"; const string firstValue = "1"; const string secondValue = "2"; var source = new BindingResourceObject(firstValue); var resolver = CreateBindingResourceResolver(); bool isInvoked = false; var value = resolver.ResolveObject(name, EmptyContext, false); value.Value.ShouldBeNull(); value.ValueChanged += (sender, args) => isInvoked = true; resolver.AddObject(name, source, true); value.Value.ShouldEqual(firstValue); isInvoked.ShouldBeTrue(); isInvoked = false; resolver.AddObject(name, new BindingResourceObject(secondValue), true); value.Value.ShouldEqual(secondValue); isInvoked.ShouldBeTrue(); }
public void ResolverShouldNotThrowExceptionIfObjectIsAlreadyRegisteredRewriteTrue() { const string name = "name"; var source = new BindingResourceObject("test1"); var source2 = new BindingResourceObject("test2"); var resolver = CreateBindingResourceResolver(); resolver.AddObject(name, source, false); resolver.AddObject(name, source2, true); resolver.ResolveObject(name, EmptyContext, true).Value.ShouldEqual(source2.Value); }
public void ResolverShouldRegisterAndResolveDynamicObjectTarget() { string name = BindingServiceProvider.ResourceResolver.RootElementResourceName; const string firstValue = "1"; var visualTreeManagerMock = new VisualTreeManagerMock(); BindingServiceProvider.VisualTreeManager = visualTreeManagerMock; var rootMember = AttachedBindingMember.CreateAutoProperty<object, object>("root"); visualTreeManagerMock.GetRootMember = type => rootMember; var target = new object(); rootMember.SetValue(target, target); var dataContext = new DataContext { {BindingBuilderConstants.Target, target} }; var source = new BindingResourceObject(firstValue); var resolver = CreateBindingResourceResolver(); bool isInvoked = false; var value = resolver.ResolveObject(name, dataContext, false); value.Value.ShouldEqual(target); value.ValueChanged += (sender, args) => isInvoked = true; resolver.AddObject(name, source, true); value.Value.ShouldEqual(firstValue); isInvoked.ShouldBeTrue(); }
public void ParserShouldParseMultiExpressionWithCustomObjectValueDynamic1() { const string targetPath = "Text"; const string sourcePath1 = "SourceText1"; const string sourcePath2 = "SourceText2"; const string sourcePath3 = "Item1"; const string objectName = "TestObject"; const string binding = "Text SourceText1 + SourceText2 == $TestObject.Item1"; var target = new object(); var tuple = new Tuple<int>(10); var expressionObject = new BindingResourceObject(tuple); var args = new object[] { 9, 1, tuple.Item1 }; var provider = new BindingProvider(); var resolver = new BindingResourceResolver(); BindingServiceProvider.ResourceResolver = resolver; resolver.AddObject(objectName, expressionObject, true); IBindingParser bindingParser = CreateBindingParser(bindingProvider: provider); var context = new BindingBuilder(bindingParser.Parse(binding, EmptyContext, target, null).Single()); IBindingPath path = context.GetData(BindingBuilderConstants.TargetPath); path.Path.ShouldEqual(targetPath); var expression = context.GetData(BindingBuilderConstants.MultiExpression); expression(context, args).ShouldEqual(true); var sources = context.GetData(BindingBuilderConstants.Sources); BindingSourceShouldBeValidDataContext(target, sources[0].Invoke(context), sourcePath1); BindingSourceShouldBeValidDataContext(target, sources[1].Invoke(context), sourcePath2); BindingSourceShouldBeValid(sources[2].Invoke(context), sourcePath3, tuple); }
public void ResolverShouldThrowExceptionIfObjectIsAlreadyRegisteredRewriteFalse() { const string name = "name"; var source = new BindingResourceObject("test1"); var source2 = new BindingResourceObject("test2"); var resolver = CreateBindingResourceResolver(); resolver.AddObject(name, source, false); ShouldThrow(() => resolver.AddObject(name, source2, false)); }