Exemple #1
0
        public void ManagerShouldUseOneContextForOneObject()
        {
            var context        = new ExplicitDataContext();
            var manager        = CreateContextManager();
            var bindingContext = manager.GetBindingContext(context);

            manager.GetBindingContext(context).ShouldEqual(bindingContext);
        }
        public void ProviderShouldUseImplicitBindingContextIfFlagIsFalse()
        {
            var model    = new ExplicitDataContext();
            var path     = GetMemberPath(model, context => context.DataContext);
            var provider = CreateMemberProvider();

            var member = provider.GetBindingMember(typeof(ExplicitDataContext), path, false, true);

            member.MemberType.ShouldEqual(BindingMemberType.BindingContext);
        }
Exemple #3
0
        public void ManagerShouldUseExplicitDataContextGet()
        {
            var o              = new object();
            var context        = new ExplicitDataContext();
            var manager        = CreateContextManager();
            var bindingContext = manager.GetBindingContext(context);

            bindingContext.Value.ShouldBeNull();
            context.DataContext = o;
            bindingContext.Value.ShouldEqual(o);
        }
Exemple #4
0
        public void ManagerShouldRaiseEventWhenDataContextChanged()
        {
            bool isInvoked      = false;
            var  context        = new ExplicitDataContext();
            var  manager        = CreateContextManager();
            var  bindingContext = manager.GetBindingContext(context);

            bindingContext.ValueChanged += (sender, args) => isInvoked = true;
            isInvoked.ShouldBeFalse();
            bindingContext.Value = context;
            isInvoked.ShouldBeTrue();
        }
Exemple #5
0
        public void ManagerShouldUseWeakReferenceForTarget()
        {
            var o       = new object();
            var context = new ExplicitDataContext {
                DataContext = o
            };
            var manager        = CreateContextManager();
            var bindingContext = manager.GetBindingContext(context);

            bindingContext.Value.ShouldEqual(o);

            context = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            bindingContext.Value.ShouldBeNull();
        }
Exemple #6
0
        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();
        }
Exemple #7
0
        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();
        }