public void SourceShouldReturnPathFromObserver()
 {
     var mock = new ObserverMock();
     BindingSource target = CreateBindingSource(mock);
     target.Path.ShouldBeNull();
     mock.Path = BindingPath.Create("test");
     target.Path.ShouldEqual(mock.Path);
 }
 public void SourceShouldThrowExceptionWhenReturnSourceIfObserverHasException()
 {
     var mock = new ObserverMock
     {
         GetActualSource = b => { throw new TestException(); }
     };
     BindingSource target = CreateBindingSource(mock);
     ShouldThrow<TestException>(() => target.GetSource(true));
 }
 public void SourceShouldReturnSourceFromObserver()
 {
     var src = new object();
     var mock = new ObserverMock
     {
         GetActualSource = b => src
     };
     BindingSource target = CreateBindingSource(mock);
     target.GetSource(true).ShouldEqual(src);
 }
        public void SourceShouldReturnMembersFromObserver()
        {
            var mock = new ObserverMock { PathMembers = UnsetBindingPathMembers.Instance };
            BindingSource target = CreateBindingSource(mock);
            IBindingPathMembers pathMembers = target.GetPathMembers(true);
            pathMembers.ShouldEqual(UnsetBindingPathMembers.Instance);
            pathMembers.AllMembersAvailable.ShouldBeFalse();

            mock.PathMembers = new BindingPathMembersMock(this, BindingPath.Empty,
                new BindingMemberInfo(PropertyInfo.Name, PropertyInfo, PropertyInfo.DeclaringType));
            pathMembers = target.GetPathMembers(true);
            pathMembers.ShouldEqual(mock.PathMembers);
            pathMembers.AllMembersAvailable.ShouldBeTrue();
        }
        public void BindingTargetShouldUseDelegateIsEnabledProperty()
        {
            bool isEnabled = false;
            IAttachedBindingMemberInfo<object, bool> member =
                AttachedBindingMember.CreateMember<object, bool>(AttachedMemberConstants.Enabled,
                    (info, o) => isEnabled,
                    (info, o, v) => isEnabled = v);
            var memberProvider = new BindingMemberProvider();
            memberProvider.Register(typeof(object), member, false);
            BindingServiceProvider.MemberProvider = memberProvider;

            var mock = new ObserverMock { PathMembers = new BindingPathMembersMock(new object(), BindingPath.Empty) };
            var bindingTarget = (BindingTarget)CreateBindingSource(mock);

            bindingTarget.IsEnabled.ShouldBeFalse();
            bindingTarget.IsEnabled = true;
            isEnabled.ShouldBeTrue();
            bindingTarget.IsEnabled.ShouldBeTrue();

            bindingTarget.IsEnabled = false;
            isEnabled.ShouldBeFalse();
            bindingTarget.IsEnabled.ShouldBeFalse();
        }
 public void SourceShouldThrowExceptionIfObserverHasException()
 {
     var mock = new ObserverMock
     {
         Validate = b => { throw new TestException(); }
     };
     var target = CreateBindingSource(mock);
     ShouldThrow<TestException>(() => target.Validate(true));
 }
        public void SourceShouldReturnValidateFromObserver()
        {
            bool param = false;
            bool result = false;
            var mock = new ObserverMock
            {
                Validate = b =>
                {
                    b.ShouldEqual(param);
                    return result;
                }
            };
            BindingSource target = CreateBindingSource(mock);

            target.Validate(param).ShouldBeFalse();

            param = true;
            result = true;
            target.Validate(param).ShouldBeTrue();
        }
        public void SourceShouldRaiseValueChangedWhenObserverRaisesValueChanged()
        {
            bool isInvoked = false;
            var mock = new ObserverMock();
            BindingSource target = CreateBindingSource(mock);

            target.ValueChanged += (sender, args) => isInvoked = true;
            isInvoked.ShouldBeFalse();
            mock.RaiseValueChanged();
            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();
 }