public void StopsSubscribing() { var collection1 = new ObservableCollection <Fake> { new Fake { Name = "Johan" } }; var fake = new FakeWithCollection { Collection = collection1 }; fake.ObservePropertyChangedWithValue(x => x.Collection, true) .ItemPropertyChanged(x => x.Name) .Subscribe(_changes.Add); Assert.AreEqual(1, _changes.Count); AssertRx.AreEqual(collection1[0], "Name", collection1[0], "Johan", _changes.Last()); fake.Collection = null; Assert.AreEqual(1, _changes.Count); collection1[0].Name = "new"; Assert.AreEqual(1, _changes.Count); var collection2 = new ObservableCollection <Fake> { new Fake { Name = "Kurt" } }; fake.Collection = collection2; Assert.AreEqual(2, _changes.Count); AssertRx.AreEqual(collection2[0], "Name", collection2[0], "Kurt", _changes.Last()); }
public void ReactsToReplace() { var item1 = new Fake { Name = "1" }; var item2 = new Fake { Name = "2" }; var collection = new ObservableCollection <Fake> { item1, item2 }; var subscription = collection.ObserveItemPropertyChanged(x => x.Name, false) .Subscribe(_changes.Add); CollectionAssert.IsEmpty(_changes); var item3 = new Fake() { Name = "3" }; collection[0] = item3; Assert.AreEqual(1, _changes.Count); AssertRx.AreEqual(item3, "Name", item3, "3", _changes.Last()); item1.Name = "new"; Assert.AreEqual(1, _changes.Count); // Stopped subscribing }
public void ReactsNested() { var item1 = new Fake { Next = new Level { Name = "1" } }; var item2 = new Fake(); var collection = new ObservableCollection <Fake> { item1, item2 }; var subscription = collection.ObserveItemPropertyChanged(x => x.Next.Name, false) .Subscribe(_changes.Add); CollectionAssert.IsEmpty(_changes); item1.Next.Name = "new1"; Assert.AreEqual(1, _changes.Count); AssertRx.AreEqual(item1.Next, "Name", item1, "new1", _changes.Last()); item2.Next = new Level { Name = "new2" }; Assert.AreEqual(2, _changes.Count); AssertRx.AreEqual(item2.Next, "Name", item2, "new2", _changes.Last()); }
public void HandlesNullItem() { var item = new Fake { Name = "1" }; var collection = new ObservableCollection <Fake> { item, null }; var subscription = collection.ObserveItemPropertyChanged(x => x.Name, false) .Subscribe(_changes.Add); CollectionAssert.IsEmpty(_changes); collection.Add(null); Assert.AreEqual(3, collection.Count); Assert.AreEqual(0, _changes.Count); item.Name = "new"; Assert.AreEqual(1, _changes.Count); AssertRx.AreEqual(item, "Name", item, "new", _changes.Last()); var item2 = new Fake { Name = "2" }; collection[1] = item2; Assert.AreEqual(2, _changes.Count); AssertRx.AreEqual(item2, "Name", item2, "2", _changes.Last()); }
public void ReactsValue() { var fake = new Fake { Value = 1 }; fake.ObservePropertyChanged() .Subscribe(_changes.Add); Assert.AreEqual(0, _changes.Count); fake.Value++; Assert.AreEqual(1, _changes.Count); AssertRx.AreEqual(fake, "Value", _changes.Last()); }
public void ReactsOnEventDerived() { var fake = new DerivedFake { Value = 1 }; fake.ObservePropertyChanged() .Subscribe(_changes.Add); Assert.AreEqual(0, _changes.Count); fake.OnPropertyChanged("SomeProp"); Assert.AreEqual(1, _changes.Count); AssertRx.AreEqual(fake, "SomeProp", _changes.Last()); }
public void ReactsOnceWhenSameItemIsTwoElementsInCollection() { var item = new Fake { Name = "1" }; var collection = new ObservableCollection <Fake> { item, item }; var subscription = collection.ObserveItemPropertyChanged(x => x.Name, false) .Subscribe(_changes.Add); CollectionAssert.IsEmpty(_changes); item.Name = "new"; Assert.AreEqual(1, _changes.Count); AssertRx.AreEqual(item, "Name", item, "new", _changes.Last()); }
public void SignalsOnSubscribe() { var collection = new ObservableCollection <Fake> { new Fake { Name = "Johan" } }; var fake = new FakeWithCollection { Collection = collection }; fake.ObservePropertyChangedWithValue(x => x.Collection, true) .ItemPropertyChanged(x => x.Name) .Subscribe(_changes.Add); Assert.AreEqual(1, _changes.Count); AssertRx.AreEqual(collection[0], "Name", collection[0], "Johan", _changes.Last()); }
public void SignalsInitial() { var item1 = new Fake { Name = "1" }; var item2 = new Fake { Name = "2" }; var collection = new ObservableCollection <Fake> { item1, item2 }; var subscription = collection.ObserveItemPropertyChanged(x => x.Name, true) .Subscribe(_changes.Add); Assert.AreEqual(2, _changes.Count); AssertRx.AreEqual(item1, "Name", item1, "1", _changes[0]); AssertRx.AreEqual(item2, "Name", item2, "2", _changes[1]); }
public void ReactsNullable() { var fake = new Fake { IsTrueOrNull = null }; var observable = fake.ObservePropertyChanged(); var disposable = observable.Subscribe(_changes.Add); Assert.AreEqual(0, _changes.Count); fake.IsTrueOrNull = true; Assert.AreEqual(1, _changes.Count); AssertRx.AreEqual(fake, "IsTrueOrNull", _changes.Last()); fake.IsTrueOrNull = null; Assert.AreEqual(2, _changes.Count); AssertRx.AreEqual(fake, "IsTrueOrNull", _changes.Last()); }
public void ReactsWhenPropertyChangesView() { var item1 = new Fake { Name = "1" }; var item2 = new Fake { Name = "2" }; var collection = new ObservableCollection <Fake> { item1, item2 }; var view = collection.AsReadOnlyFilteredView(x => true); view.ObserveItemPropertyChanged(x => x.Name, false) .Subscribe(_changes.Add); CollectionAssert.IsEmpty(_changes); item1.Name = "new1"; Assert.AreEqual(1, _changes.Count); AssertRx.AreEqual(item1, "Name", item1, "new1", _changes.Last()); item2.Name = "new2"; Assert.AreEqual(2, _changes.Count); AssertRx.AreEqual(item2, "Name", item2, "new2", _changes.Last()); }
public void ReactsTwoInstancesValue() { var fake1 = new Fake { Value = 1 }; fake1.ObservePropertyChanged() .Subscribe(_changes.Add); var fake2 = new Fake { Value = 1 }; fake2.ObservePropertyChanged() .Subscribe(_changes.Add); Assert.AreEqual(0, _changes.Count); fake1.Value++; Assert.AreEqual(1, _changes.Count); AssertRx.AreEqual(fake1, "Value", _changes.Last()); fake2.Value++; Assert.AreEqual(2, _changes.Count); AssertRx.AreEqual(fake2, "Value", _changes.Last()); }