public void When_Path_Has_Null_Intermediary_Node_Then_Skips_When_Invalid_Path()
        {
            // Arrange
            var childOne = new TestObservableObject {Age = 5};
            var childTwo = new TestObservableObject {Age = 17};
            var obj = new TestObservableObject {ObservableChild = childOne};
            var scheduler = new TestScheduler();

            var observer = scheduler.CreateObserver<int>();
            var expected = new[]
            {
                OnNext(000, childOne.Age),
                OnNext(000, 20),
                OnNext(300, childTwo.Age),
            };

            var sut = obj.WhenValue(x => x.ObservableChild.Age);

            // Act
            sut.Subscribe(observer);
            obj.ObservableChild.Age = 20;
            scheduler.AdvanceTo(100);
            obj.ObservableChild = null;
            scheduler.AdvanceTo(300);
            obj.ObservableChild = childTwo;

            // Assert
            Assert.AreEqual(expected, observer.Messages);
        }
示例#2
0
        public void When_Subscribed_Then_OnNext_Changes()
        {
            // Arrange
            var obj = new TestObservableObject {ObservableChild = new TestObservableObject {Age = 3}};
            var replacementChild = new TestObservableObject {Age = 5};
            var scheduler = new TestScheduler();
            var observer = scheduler.CreateObserver<TestObservableObject>();
            var expected = new[]
            {
                OnNext(000, obj.ObservableChild),
                OnNext(010, replacementChild),
                OnNext(010, replacementChild),
                OnNext(020, replacementChild),
            };

            var sut = obj.WhenAny(x => x.ObservableChild).ForProperty<TestObservableObject>("Age", "Name");

            // Act
            sut.Subscribe(observer);
            scheduler.AdvanceTo(10);
            obj.ObservableChild = replacementChild;
            obj.ObservableChild.Age = 17;
            scheduler.AdvanceTo(20);
            obj.ObservableChild.Name = "Billy";

            // Assert
            Assert.AreEqual(expected, observer.Messages);
        }
        public void When_Path_Has_Null_Intermediary_Node_Then_Propagates_ProvertyValueChanged_With_HasValue_False()
        {
            // Arrange
            var childOne = new TestObservableObject {Age = 5};
            var childTwo = new TestObservableObject {Age = 17};
            var obj = new TestObservableObject {ObservableChild = childOne};
            var scheduler = new TestScheduler();

            var observer = scheduler.CreateObserver<IPropertyValueChanged<int>>();
            var expected = new[]
            {
                OnNext(000, PropertyValueChanged.CreateWithValue(childOne, "Age", childOne.Age)),
                OnNext(000, PropertyValueChanged.CreateWithValue(childOne, "Age", 20)),
                OnNext(100, PropertyValueChanged.CreateWithoutValue<TestObservableObject, int>(null, "Age")),
                OnNext(300, PropertyValueChanged.CreateWithValue(childTwo, "Age", childTwo.Age)),
            };

            var sut = obj.When(x => x.ObservableChild.Age);

            // Act
            sut.Subscribe(observer);
            obj.ObservableChild.Age = 20;
            scheduler.AdvanceTo(100);
            obj.ObservableChild = null;
            scheduler.AdvanceTo(300);
            obj.ObservableChild = childTwo;

            // Assert
            Assert.AreEqual(expected, observer.Messages);
        }
示例#4
0
        public void When_Subscribe_To_Property_With_Broken_Path_Then_OnNext_Initial_Image_With_Null_Source()
        {
            // Arrange
            var obj = new TestObservableObject();
            var scheduler = new TestScheduler();
            var observer = scheduler.CreateObserver<IPropertyChanged<TestObservableObject>>();
            var expected = new[]
            {
                OnNext(000, PropertyChanged.Create(default(TestObservableObject))),
            };

            var sut = obj.WhenAny(x => x.PocoChild.ObservableChild);

            // Act
            sut.Subscribe(observer);

            // Assert
            Assert.AreEqual(expected, observer.Messages);
        }
示例#5
0
        public void When_Subscribe_With_One_Node_Path_To_Property_Then_OnNext_Initial_Image_And_Changes()
        {
            // Arrange
            var obj = new TestObservableObject {Age = 5};
            var scheduler = new TestScheduler();
            var observer = scheduler.CreateObserver<IPropertyChanged<TestObservableObject>>();
            var expected = new[]
            {
                OnNext(000, PropertyChanged.Create(obj)),
                OnNext(000, PropertyChanged.Create(obj, "Age")),
            };

            var sut = obj.WhenAny();

            // Act
            sut.Subscribe(observer);
            obj.Age = 10;

            // Assert
            Assert.AreEqual(expected, observer.Messages);
        }
        public void When_Subscribe_Via_Interface_To_Poco_Source_Then_OnNext_Initial_Value_Only()
        {
            // Arrange
            var obj = new TestPoco {Age = 3} as ITestObject;
            var scheduler = new TestScheduler();
            var observer = scheduler.CreateObserver<IPropertyValueChanged<int>>();
            var expected = new[]
            {
                OnNext(000, PropertyValueChanged.CreateWithValue(obj, "Age", 3)),
            };

            var sut = obj.When(x => x.Age);

            // Act
            sut.Subscribe(observer);
            scheduler.AdvanceTo(10);
            obj.Age = 5;

            // Assert
            Assert.AreEqual(expected, observer.Messages);
        }
        public void When_Property_Declared_On_Base_Class_Then_OnNext_Changes()
        {
            // Arrange
            var obj = new DerivedTestObservableObject {Age = 100};
            var scheduler = new TestScheduler();
            var observer = scheduler.CreateObserver<int>();
            var expected = new[]
            {
                OnNext(000, 100),
                OnNext(000, 20),
            };

            var sut = obj.WhenValue(x => x.Age);

            // Act
            sut.Subscribe(observer);
            obj.Age = 20;

            // Assert
            Assert.AreEqual(expected, observer.Messages);
        }
        public void When_Property_Declared_On_Base_Class_Then_OnNext_Changes()
        {
            // Arrange
            var obj = new DerivedTestPoco() {Age = 100};
            var scheduler = new TestScheduler();
            var observer = scheduler.CreateObserver<IPropertyValueChanged<int>>();
            var expected = new[]
            {
                // Since reflection is used, the PropertyValueChange is typed to the property declaring class not the derived one.
                // This impacts the test assert as they are IEquatable=false if the TClass types disagree. So make it TestPoco not
                // DerivedTestPoco.
                OnNext(000, PropertyValueChanged.CreateWithValue((TestPoco) obj, "Age", 100)),
            };

            var sut = obj.When(x => x.Age);

            // Act
            sut.Subscribe(observer);
            obj.Age = 20;

            // Assert
            Assert.AreEqual(expected, observer.Messages);
        }
示例#9
0
        public void When_Subscribe_With_Two_Node_Path_To_Property_And_Modify_Node_One_Then_OnNext_Changes()
        {
            // Arrange
            var obj = new TestObservableObject {ObservableChild = new TestObservableObject {Age = 3}};
            var replacementChild = new TestObservableObject {Age = 5};
            var scheduler = new TestScheduler();
            var observer = scheduler.CreateObserver<IPropertyChanged<TestObservableObject>>();
            var expected = new[]
            {
                OnNext(000, PropertyChanged.Create(obj.ObservableChild)),
                OnNext(010, PropertyChanged.Create(replacementChild)),
                OnNext(010, PropertyChanged.Create(replacementChild, "Age")),
            };

            var sut = obj.WhenAny(x => x.ObservableChild);

            // Act
            sut.Subscribe(observer);
            scheduler.AdvanceTo(10);
            obj.ObservableChild = replacementChild;
            obj.ObservableChild.Age = 17;

            // Assert
            Assert.AreEqual(expected, observer.Messages);
        }
        public void When_Subscribe_With_One_Node_Path_To_Property_Then_OnNext_Changes()
        {
            // Arrange
            var obj = new TestPoco() {Age = 5};
            var scheduler = new TestScheduler();
            var observer = scheduler.CreateObserver<IPropertyValueChanged<int>>();
            var expected = new[]
            {
                OnNext(000, PropertyValueChanged.CreateWithValue(obj, "Age", 5)),
            };

            var sut = obj.When(x => x.Age);

            // Act
            sut.Subscribe(observer);
            obj.Age = 3; // This should not fire through.

            // Assert
            Assert.AreEqual(expected, observer.Messages);
        }
        public void When_Subscribe_With_Two_Node_Path_To_Property_And_Modify_Node_One_Then_OnNext_Changes()
        {
            // Arrange
            var childOne = new TestPoco {Age = 3};
            var childTwo = new TestPoco() {Age = 5};
            var obj = new TestObservableObject {PocoChild = childOne};
            var scheduler = new TestScheduler();
            var observer = scheduler.CreateObserver<IPropertyValueChanged<int>>();
            var expected = new[]
            {
                OnNext(000, PropertyValueChanged.CreateWithValue(childOne, "Age", 3)),
                OnNext(010, PropertyValueChanged.CreateWithValue(childTwo, "Age", 5)),
            };

            var sut = obj.When(x => x.PocoChild.Age);

            // Act
            sut.Subscribe(observer);
            scheduler.AdvanceTo(10);
            obj.PocoChild = childTwo;

            // Assert
            Assert.AreEqual(expected, observer.Messages);
        }
        public void When_Subscribe_With_One_Node_Path_To_Property_Then_OnNext_Changes()
        {
            // Arrange
            var obj = new TestObservableObject {Age = 5};
            var scheduler = new TestScheduler();
            var observer = scheduler.CreateObserver<int>();
            var expected = new[]
            {
                OnNext(000, 5),
            };

            var sut = obj.WhenValue(x => x.Age);

            // Act
            sut.Subscribe(observer);

            // Assert
            Assert.AreEqual(expected, observer.Messages);
        }
        public void When_Subscribe_With_Two_Node_Path_To_Property_And_Modify_Property_Then_OnNext_Changes()
        {
            // Arrange
            var obj = new TestObservableObject {ObservableChild = new TestObservableObject {Age = 3}};
            var scheduler = new TestScheduler();
            var observer = scheduler.CreateObserver<int>();
            var expected = new[]
            {
                OnNext(000, 3),
                OnNext(010, 5),
            };

            var sut = obj.WhenValue(x => x.ObservableChild.Age);

            // Act
            sut.Subscribe(observer);
            scheduler.AdvanceTo(10);
            obj.ObservableChild.Age = 5;

            // Assert
            Assert.AreEqual(expected, observer.Messages);
        }