Пример #1
0
        public void DependencyObjectObservableForPropertySmokeTest()
        {
            var fixture = new DepObjFixture();
            var binder  = new DependencyObjectObservableForProperty();

            Assert.NotEqual(0, binder.GetAffinityForObject(typeof(DepObjFixture), "TestString"));
            Assert.Equal(0, binder.GetAffinityForObject(typeof(DepObjFixture), "DoesntExist"));

            var results = new List <IObservedChange <object, object?> >();
            Expression <Func <DepObjFixture, object> > expression = x => x.TestString;
            var propertyName = expression.Body.GetMemberInfo()?.Name;

            if (propertyName is null)
            {
                throw new InvalidOperationException("There is no valid property name");
            }

            var disp1 = binder.GetNotificationForProperty(fixture, expression.Body, propertyName).WhereNotNull().Subscribe(results.Add);
            var disp2 = binder.GetNotificationForProperty(fixture, expression.Body, propertyName).WhereNotNull().Subscribe(results.Add);

            fixture.TestString = "Foo";
            fixture.TestString = "Bar";

            Assert.Equal(4, results.Count);

            disp1.Dispose();
            disp2.Dispose();
        }
Пример #2
0
        public void WhenAnyWithDependencyObjectTest()
        {
            var inputs  = new[] { "Foo", "Bar", "Baz" };
            var fixture = new DepObjFixture();

            fixture.WhenAnyValue(x => x.TestString).ToObservableChangeSet().Bind(out var outputs).Subscribe();
            inputs.ForEach(x => fixture.TestString = x);

            Assert.Null(outputs.First());
            Assert.Equal(4, outputs.Count);
            Assert.True(inputs.Zip(outputs.Skip(1), (expected, actual) => expected == actual).All(x => x));
        }