public void ManagerShouldUseOneContextForOneObject()
 {
     var context = new ExplicitDataContext();
     var manager = CreateContextManager();
     var bindingContext = manager.GetBindingContext(context);
     manager.GetBindingContext(context).ShouldEqual(bindingContext);
 }
 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);
 }
 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();
 }
        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();
        }
        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);
        }
 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 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();
 }