Ejemplo n.º 1
0
        public void Callback_Is_Called_On_Direct_Property_Change()
        {
            bool isCallbackCalled = false;
            var  first            = ObservedPropertyModels.CreateFirst("text");

            Action callback = () => isCallbackCalled = true;

            var property = ObservedProperty.Create(() => first.Second.Third.Value, callback);

            first.Second.Third.Value = "new";

            Assert.True(isCallbackCalled);
        }
Ejemplo n.º 2
0
        public void ObservedProperty_Dispose_Works()
        {
            bool isCallbackCalled = false;
            var  first            = ObservedPropertyModels.CreateFirst("text");

            Action callback = () => isCallbackCalled = true;

            var property = ObservedProperty.Create(() => first.Second.Third.Value, callback);

            property.Dispose();

            first.Second = ObservedPropertyModels.CreateSecond("new1");

            Assert.False(isCallbackCalled);
        }
Ejemplo n.º 3
0
    public void Same_Scoped_Expressions_With_Different_ToStrings_Are_Equal()
    {
        var bindable = ObservedPropertyModels.CreateFirst("");

        MemberAccessor <string> ae1, ae2;

        {
            var item1 = bindable.Second;
            ae1 = MemberAccessor.Create(() => item1.Third.Value);
        }

        {
            var item2 = bindable.Second;
            ae2 = MemberAccessor.Create(() => item2.Third.Value);
        }

        Assert.Equal(ae1, ae2);
    }
Ejemplo n.º 4
0
        public void ObservedProperty_Suppress_Works()
        {
            bool isCallbackCalled = false;
            var  first            = ObservedPropertyModels.CreateFirst("text");

            Action callback = () => isCallbackCalled = true;

            var property = ObservedProperty.Create(() => first.Second.Third.Value, callback);

            using (property.Suppress())
                first.Second = ObservedPropertyModels.CreateSecond("new");

            Assert.False(isCallbackCalled);

            first.Second = ObservedPropertyModels.CreateSecond("new1");

            Assert.True(isCallbackCalled);
        }
Ejemplo n.º 5
0
    public void Different_Scoped_Expressions_With_Similar_ToStrings_Are_Not_Equal()
    {
        var bindable1 = ObservedPropertyModels.CreateFirst("");
        var bindable2 = ObservedPropertyModels.CreateFirst("");

        MemberAccessor <string> ae1, ae2;

        {
            var item = bindable1;
            ae1 = MemberAccessor.Create(() => item.Second.Third.Value);
        }

        {
            var item = bindable2;
            ae2 = MemberAccessor.Create(() => item.Second.Third.Value);
        }

        // ae1.ToString() == ae2.ToString()

        Assert.NotEqual(ae1, ae2);
    }
Ejemplo n.º 6
0
    public void Generated_Root_Reduction_Works()
    {
        var bindable = ObservedPropertyModels.CreateFirst("");

        MemberAccessor <ThirdBindable> ae;

        {
            var item = bindable;
            ae = MemberAccessor.Create(() => item.Second.Third);
        }

        var reduced = ae.Expression;

        if (reduced.Body is not MemberExpression member1)
        {
            throw new XunitException();
        }

        if (member1.Member is not PropertyInfo property1 || property1.Name != nameof(SecondBindable.Third))
        {
            throw new XunitException();
        }

        if (member1.Expression is not MemberExpression member2)
        {
            throw new XunitException();
        }

        if (member2.Member is not PropertyInfo property2 || property2.Name != nameof(FirstBindable.Second))
        {
            throw new XunitException();
        }

        if (member2.Expression is not ConstantExpression constant1 || constant1.Value != bindable)
        {
            throw new XunitException();
        }
    }