Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }