public void ProviderShouldReturnMemberForBindingContext()
        {
            const string path        = AttachedMemberConstants.DataContext;
            var          model       = new BindingSourceModel();
            var          contextMock = new BindingContextMock();

            BindingServiceProvider.ContextManager = new BindingContextManagerMock
            {
                GetBindingContext = o => contextMock
            };
            var provider = CreateMemberProvider();

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

            member.CanRead.ShouldBeTrue();
            member.CanWrite.ShouldBeTrue();
            member.Type.ShouldEqual(typeof(object));
            member.MemberType.ShouldEqual(BindingMemberType.BindingContext);
            member.Path.ShouldEqual(path);
            member.Member.ShouldBeNull();

            member.GetValue(model, null).ShouldBeNull();
            member.SetValue(model, new object[] { model });

            member.GetValue(model, null).ShouldEqual(model);
            contextMock.Value.ShouldEqual(model);

            member.SetSingleValue(model, null);
            member.GetValue(model, null).ShouldBeNull();
        }
Exemple #2
0
        public void ObserverShouldUpdateInformationWhenContextChangedHasStablePathTrueComplexPath()
        {
            var model = new BindingSourceModel {
                NestedModel = new BindingSourceNestedModel {
                    StringProperty = "st"
                }
            };
            var contextMock = new BindingContextMock {
                Value = model, Source = new object()
            };
            var propertyName = GetMemberPath <BindingSourceModel>(sourceModel => sourceModel.NestedModel.StringProperty);
            var observer     = CreateObserver(contextMock, propertyName, false, hasStablePath: true);
            var members      = observer.GetPathMembers(true);

            members.Members.Last().Type.ShouldEqual(typeof(string));
            observer.Path.Path.ShouldEqual(propertyName);
            members.LastMember.GetValue(members.PenultimateValue, null).ShouldEqual(model.NestedModel.StringProperty);

            var model2 = new BindingSourceModel {
                NestedModel = new BindingSourceNestedModel {
                    StringProperty = "st1"
                }
            };

            contextMock.Value = model2;
            members           = observer.GetPathMembers(true);
            members.Members.Last().Type.ShouldEqual(typeof(string));
            observer.Path.Path.ShouldEqual(propertyName);
            members.LastMember.GetValue(members.PenultimateValue, null).ShouldEqual(model2.NestedModel.StringProperty);
        }
Exemple #3
0
        public void ObserverShouldUseBindingContextAsSource()
        {
            var model       = new BindingSourceModel();
            var contextMock = new BindingContextMock {
                Value = model
            };
            var propertyName = GetMemberPath <BindingSourceModel>(sourceModel => sourceModel.StringProperty);
            var observer     = CreateObserver(contextMock, propertyName, false);

            observer.Source.ShouldEqual(contextMock);
            var members = observer.GetPathMembers(true);

            members.AllMembersAvailable.ShouldBeTrue();
            members.Members.Single().Type.ShouldEqual(typeof(string));
            observer.Path.Path.ShouldEqual(propertyName);
        }
Exemple #4
0
        public void ObserverShouldUpdateInformationWhenContextChangedNotValidContext()
        {
            var model       = new BindingSourceModel();
            var contextMock = new BindingContextMock {
                Value = model
            };
            var propertyName = GetMemberPath <BindingSourceModel>(sourceModel => sourceModel.StringProperty);
            var observer     = CreateObserver(contextMock, propertyName, false);
            var members      = observer.GetPathMembers(true);

            members.Members.Single().Type.ShouldEqual(typeof(string));
            observer.Path.Path.ShouldEqual(propertyName);

            contextMock.Value = new object();
            members           = observer.GetPathMembers(false);
            members.Members.ShouldBeEmpty();
            observer.Path.Path.ShouldEqual(propertyName);
        }