public void ResolverShouldRegisterAndResolveDynamicObjectTarget() { string name = BindingServiceProvider.ResourceResolver.RootElementResourceName; 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 resolver = CreateBindingResourceResolver(); bool isInvoked = false; var value = resolver.ResolveObject(name, dataContext, false); value.Value.ShouldEqual(target); value.ValueChanged += (sender, args) => isInvoked = true; rootMember.SetValue(target, name); value.Value.ShouldEqual(name); isInvoked.ShouldBeTrue(); }
public void ManagerShouldRaiseEventWhenParentChanged() { bool contextChanged = false; var context = new object(); IEventListener eventListener = null; var memberMock = new BindingMemberInfoMock { TryObserveMember = (o, listener) => { eventListener = listener; return(null); } }; var managerMock = new VisualTreeManagerMock { FindParent = o => null, GetParentMember = type => { type.ShouldEqual(context.GetType()); return(memberMock); } }; var manager = CreateContextManager(managerMock); var bindingContext = manager.GetBindingContext(context); bindingContext.ValueChanged += (sender, args) => contextChanged = true; eventListener.ShouldNotBeNull(); eventListener.Handle(this, EventArgs.Empty); contextChanged.ShouldBeTrue(); }
public void ManagerShouldRaiseEventWhenDataContextChangedNotExplicit() { bool contextChanged = false; var context = new object(); var managerMock = new VisualTreeManagerMock { FindParent = o => null, GetParentMember = type => null }; var manager = CreateContextManager(managerMock); var bindingContext = manager.GetBindingContext(context); bindingContext.ValueChanged += (sender, args) => contextChanged = true; bindingContext.Value = context; contextChanged.ShouldBeTrue(); }
public void ManagerShouldNotUpdateContextWhenParentChangedIfHasValue() { bool isFindParentInvoked = false; var context = new object(); IEventListener eventListener = null; var memberMock = new BindingMemberInfoMock { TryObserveMember = (o, listener) => { eventListener = listener; return(null); } }; var managerMock = new VisualTreeManagerMock { FindParent = o => { o.ShouldEqual(context); isFindParentInvoked = true; return(null); }, GetParentMember = type => { type.ShouldEqual(context.GetType()); return(memberMock); } }; var manager = CreateContextManager(managerMock); var bindingContext = manager.GetBindingContext(context); isFindParentInvoked.ShouldBeTrue(); bindingContext.Value.ShouldBeNull(); isFindParentInvoked = false; bindingContext.Value = context; eventListener.ShouldNotBeNull(); eventListener.Handle(this, EventArgs.Empty); isFindParentInvoked.ShouldBeFalse(); }
public void ManagerShouldUseParentBindingContextIfItHasNotExplicit() { bool isFindParentInvoked = false; bool isObserveParentInvoked = false; var context = new object(); var memberMock = new BindingMemberInfoMock { TryObserveMember = (o, listener) => { o.ShouldEqual(context); isObserveParentInvoked = true; return(null); } }; var managerMock = new VisualTreeManagerMock { FindParent = o => { o.ShouldEqual(context); isFindParentInvoked = true; return(null); }, GetParentMember = type => { type.ShouldEqual(context.GetType()); return(memberMock); } }; var manager = CreateContextManager(managerMock); var bindingContext = manager.GetBindingContext(context); isFindParentInvoked.ShouldBeTrue(); isObserveParentInvoked.ShouldBeTrue(); bindingContext.Value.ShouldBeNull(); }
public void ResolverShouldResolveRootMember() { string name = BindingServiceProvider.ResourceResolver.RootElementResourceName; var visualTreeManagerMock = new VisualTreeManagerMock(); BindingServiceProvider.VisualTreeManager = visualTreeManagerMock; var rootMember = AttachedBindingMember.CreateAutoProperty <object, object>(name); visualTreeManagerMock.GetRootMember = type => rootMember; var target = new object(); var dataContext = new DataContext { { BindingBuilderConstants.Target, target } }; var resolver = CreateBindingResourceResolver(); var value = resolver.ResolveObject(name, dataContext, false); value.Value.ShouldBeNull(); rootMember.SetValue(target, target); value.Value.ShouldEqual(target); }