public void ManagerShouldObserveExplicitDataContext()
 {
     bool isInvoked = false;
     var o = new object();
     var context = new ExplicitDataContext { DataContext = o };
     var providerMock = new ObserverProviderMock();
     var manager = CreateContextManager(observerProvider: providerMock);
     providerMock.Observe = (o1, path, arg3) =>
     {
         o1.ShouldEqual(context);
         path.Path.ShouldEqual(AttachedMemberConstants.DataContext);
         arg3.ShouldBeTrue();
         isInvoked = true;
         return new ObserverMock();
     };
     manager.GetBindingContext(context);
     isInvoked.ShouldBeTrue();
 }
        public void ParserShouldParseElementSourceExpression3()
        {
            bool isInvoked = false;
            const string targetPath = "Text";
            const string sourcePath = "StringProperty";
            const string sourceName = "type";
            const string binding = "Text $Element(type).StringProperty";

            var target = new BindingSourceModel();
            var relativeObj = new BindingSourceModel();
            IEventListener eventListener = null;
            var memberMock = new BindingMemberInfoMock
            {
                TryObserveMember = (o, listener) =>
                {
                    eventListener = listener;
                    return null;
                }
            };
            var providerMock = new ObserverProviderMock
            {
                Observe = (o, p, arg3) => new MultiPathObserver(o, p, arg3)
            };
            var treeManagerMock = new VisualTreeManagerMock
            {
                FindByName = (o, s) =>
                {
                    o.ShouldEqual(target);
                    s.ShouldEqual(sourceName);
                    isInvoked = true;
                    return relativeObj;
                },
                GetRootMember = type => memberMock
            };

            IBindingParser bindingParser = CreateBindingParser(treeManagerMock, null, providerMock);
            var context = new BindingBuilder(bindingParser.Parse(binding, EmptyContext, target, null).Single());
            IBindingPath path = context.GetData(BindingBuilderConstants.TargetPath);
            path.Path.ShouldEqual(targetPath);

            var sources = context.GetData(BindingBuilderConstants.Sources);
            IBindingSource source = sources.Single().Invoke(context);
            source.Path.Path.ShouldContain(sourcePath);
            isInvoked.ShouldBeTrue();

            isInvoked = false;
            eventListener.ShouldNotBeNull();
            eventListener.Handle(this, EventArgs.Empty);
            isInvoked.ShouldBeTrue();
        }
 public void ManagerShouldRaiseEventWhenObserverValueChanged()
 {
     bool isInvoked = false;
     var o = new object();
     var context = new ExplicitDataContext { DataContext = o };
     var providerMock = new ObserverProviderMock();
     var observerMock = new ObserverMock();
     var manager = CreateContextManager(observerProvider: providerMock);
     providerMock.Observe = (o1, path, arg3) => observerMock;
     var bindingContext = manager.GetBindingContext(context);
     bindingContext.ValueChanged += (sender, args) => isInvoked = true;
     isInvoked.ShouldBeFalse();
     observerMock.RaiseValueChanged();
     isInvoked.ShouldBeTrue();
 }