public void SignalsInitialNested() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake, string> > >(); var item1 = new Fake { Level1 = new Level1 { Name = "1" } }; var item2 = new Fake { Level1 = new Level1 { Name = "2" } }; var collection = new ObservableCollection <Fake> { item1, item2 }; using (collection.ObserveItemPropertyChanged(x => x.Level1.Name, signalInitial: true) .Subscribe(changes.Add)) { Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(item1, item1.Level1, item1.Level1, Maybe.Some("1"), string.Empty, changes[0]); EventPatternAssert.AreEqual(item2, item2.Level1, item2.Level1, Maybe.Some("2"), string.Empty, changes[1]); } Assert.AreEqual(2, changes.Count); }
public void HandlesMoveSimple() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake, string> > >(); var item1 = new Fake { Name = "1" }; var item2 = new Fake { Name = "2" }; var collection = new ObservableCollection <Fake> { item1, item2 }; using (collection.ObserveItemPropertyChanged(x => x.Name, signalInitial: false) .Subscribe(changes.Add)) { CollectionAssert.IsEmpty(changes); collection.Move(0, 1); CollectionAssert.IsEmpty(changes); item1.Name = "new 1"; EventPatternAssert.AreEqual(item1, item1, item1, Maybe.Some("new 1"), "Name", changes.Single()); item2.Name = "new 2"; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(item2, item2, item2, Maybe.Some("new 2"), "Name", changes.Last()); } Assert.AreEqual(2, changes.Count); }
public void DoesNotReactToOtherPropertyNested() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake, string> > >(); var item1 = new Fake { Next = new Level { Name = "1" } }; var item2 = new Fake(); var collection = new ObservableCollection <Fake> { item1, item2 }; using (collection.ObserveItemPropertyChanged(x => x.Next.Name, signalInitial: false) .Subscribe(changes.Add)) { CollectionAssert.IsEmpty(changes); item1.Next.Name = "new1"; EventPatternAssert.AreEqual(item1, item1.Next, item1.Next, Maybe.Some("new1"), "Name", changes.Single()); item1.Next.Value++; EventPatternAssert.AreEqual(item1, item1.Next, item1.Next, Maybe.Some("new1"), "Name", changes.Single()); item2.Next = new Level { Name = "new2" }; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(item2, item2, item2.Next, Maybe.Some("new2"), "Next", changes.Last()); } Assert.AreEqual(2, changes.Count); }
public void HandlesNullItem() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake, string> > >(); var item = new Fake { Name = "1" }; var collection = new ObservableCollection <Fake> { item, null }; using (collection.ObserveItemPropertyChanged(x => x.Name, signalInitial: false) .Subscribe(changes.Add)) { CollectionAssert.IsEmpty(changes); collection.Add(null); Assert.AreEqual(3, collection.Count); Assert.AreEqual(0, changes.Count); item.Name = "new1"; EventPatternAssert.AreEqual(item, item, item, Maybe.Some("new1"), "Name", changes.Single()); var item2 = new Fake { Name = "2" }; collection[1] = item2; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(item2, item2, item2, Maybe.Some("2"), string.Empty, changes.Last()); } Assert.AreEqual(2, changes.Count); }
public void ReactsWhenPropertyChangesSameInstanceTwice() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake, string> > >(); var item = new Fake { Name = "1" }; var collection = new ObservableCollection <Fake> { item }; using (collection.ObserveItemPropertyChanged(x => x.Name, signalInitial: false) .Subscribe(changes.Add)) { CollectionAssert.IsEmpty(changes); item.Name = "new1"; EventPatternAssert.AreEqual(item, item, item, Maybe.Some("new1"), "Name", changes.Single()); collection.Add(item); Assert.AreEqual(1, changes.Count); item.Name = "new2"; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(item, item, item, Maybe.Some("new2"), "Name", changes.Last()); collection.RemoveAt(1); Assert.AreEqual(2, changes.Count); item.Name = "new3"; Assert.AreEqual(3, changes.Count); EventPatternAssert.AreEqual(item, item, item, Maybe.Some("new3"), "Name", changes.Last()); } Assert.AreEqual(3, changes.Count); }
public void ReactsWhenPropertyChangesView() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake, string> > >(); var item1 = new Fake { Name = "1" }; var item2 = new Fake { Name = "2" }; var collection = new ObservableCollection <Fake> { item1, item2 }; using (var view = collection.AsReadOnlyFilteredView(x => true)) { using (view.ObserveItemPropertyChanged(x => x.Name, signalInitial: false) .Subscribe(changes.Add)) { CollectionAssert.IsEmpty(changes); item1.Name = "new1"; EventPatternAssert.AreEqual(item1, item1, item1, Maybe.Some("new1"), "Name", changes.Single()); item2.Name = "new2"; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(item2, item2, item2, Maybe.Some("new2"), "Name", changes.Last()); } } Assert.AreEqual(2, changes.Count); }
public static void ReactsWhenPropertyChangesSimple() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake, string?> > >(); var item1 = new Fake { Name = "1" }; var item2 = new Fake { Name = "2" }; var source = new ObservableCollection <Fake> { item1, item2 }; using (source.ObserveItemPropertyChanged(x => x.Name, signalInitial: false) .Subscribe(changes.Add)) { CollectionAssert.IsEmpty(changes); item1.Name = "new1"; Assert.AreEqual(1, changes.Count); EventPatternAssert.AreEqual(item1, item1, item1, Maybe.Some <string?>("new1"), "Name", changes.Last()); item2.Name = "new2"; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(item2, item2, item2, Maybe.Some <string?>("new2"), "Name", changes.Last()); } Assert.AreEqual(2, changes.Count); }
public void HandlesReplaceWithSameNested() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake, int> > >(); var item1 = new Fake { Level1 = new Level1 { Name = "1" } }; var item2 = new Fake { Level1 = new Level1 { Name = "2" } }; var collection = new ObservableCollection <Fake> { item1, item2 }; using (collection.ObserveItemPropertyChanged(x => x.Level1.Value, signalInitial: false) .Subscribe(changes.Add)) { CollectionAssert.IsEmpty(changes); collection[0] = item1; CollectionAssert.IsEmpty(changes); item1.Level1.Value++; EventPatternAssert.AreEqual(item1, item1.Level1, item1.Level1, Maybe.Some(item1.Level1.Value), "Value", changes.Single()); } Assert.AreEqual(1, changes.Count); }
public static void ReplaceWithSameSimple() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake, int> > >(); var item1 = new Fake { Name = "1" }; var item2 = new Fake { Name = "2" }; var source = new ObservableCollection <Fake> { item1, item2 }; using (source.ObserveItemPropertyChanged(x => x.Value, signalInitial: false) .Subscribe(changes.Add)) { CollectionAssert.IsEmpty(changes); source[0] = item1; CollectionAssert.IsEmpty(changes); item1.Value++; EventPatternAssert.AreEqual(item1, item1, item1, Maybe.Some(item1.Value), "Value", changes.Single()); } Assert.AreEqual(1, changes.Count); }
public static void RemoveNested() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake, string?> > >(); var item1 = new Fake { Level1 = new Level1 { Name = "1" } }; var item2 = new Fake { Level1 = new Level1 { Name = "2" } }; var source = new ObservableCollection <Fake> { item1, item2 }; using (source.ObserveItemPropertyChanged(x => x.Level1.Name, signalInitial: false) .Subscribe(changes.Add)) { CollectionAssert.IsEmpty(changes); source.Remove(item2); EventPatternAssert.AreEqual(null, source, item2.Level1, Maybe.Some <string?>("2"), string.Empty, changes.Single()); item2.Level1.Name = "new"; Assert.AreEqual(1, changes.Count); } Assert.AreEqual(1, changes.Count); }
public static void ReplaceWithNullNested() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake?, string?> > >(); var item1 = new Fake { Level1 = new Level1 { Name = "1" } }; var item2 = new Fake { Level1 = new Level1 { Name = "2" } }; var source = new ObservableCollection <Fake?> { item1, item2 }; using (source.ObserveItemPropertyChanged(x => x.Level1.Name, signalInitial: false) .Subscribe(changes.Add)) { CollectionAssert.IsEmpty(changes); source[0] = null; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(null, source, item1.Level1, Maybe.Some <string?>("1"), string.Empty, changes[0]); EventPatternAssert.AreEqual(null, source, null, Maybe.None <string?>(), string.Empty, changes[1]); item1.Level1.Name = "new1"; Assert.AreEqual(2, changes.Count); } Assert.AreEqual(2, changes.Count); }
public static void AddThenUpdateSimple() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake, string?> > >(); var item1 = new Fake { Name = "1" }; var item2 = new Fake { Name = "2" }; var source = new ObservableCollection <Fake> { item1, item2 }; using (source.ObserveItemPropertyChanged(x => x.Name, signalInitial: false) .Subscribe(changes.Add)) { CollectionAssert.IsEmpty(changes); var item3 = new Fake { Name = "3" }; source.Add(item3); EventPatternAssert.AreEqual(item3, source, item3, Maybe.Some <string?>("3"), string.Empty, changes.Single()); item3.Name = "new"; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(item3, item3, item3, Maybe.Some <string?>("new"), "Name", changes.Last()); } }
public static void AddNullSimple() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake?, string?> > >(); var item1 = new Fake { Name = "1" }; var item2 = new Fake { Name = "2" }; var source = new ObservableCollection <Fake?> { item1, item2 }; using (source.ObserveItemPropertyChanged(x => x.Name, signalInitial: true) .Subscribe(changes.Add)) { Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(item1, source, item1, Maybe.Some <string?>("1"), string.Empty, changes[0]); EventPatternAssert.AreEqual(item2, source, item2, Maybe.Some <string?>("2"), string.Empty, changes[1]); source.Add(null); Assert.AreEqual(3, changes.Count); EventPatternAssert.AreEqual(null, source, null, Maybe.None <string?>(), string.Empty, changes.Last()); } Assert.AreEqual(3, changes.Count); }
public static void ReactsTwoInstancesValue() { var changes = new List <EventPattern <PropertyChangedEventArgs> >(); var source1 = new Fake { Value = 1 }; using (source1.ObservePropertyChanged() .Subscribe(changes.Add)) { var source2 = new Fake { Value = 1 }; using (source2.ObservePropertyChanged() .Subscribe(changes.Add)) { Assert.AreEqual(0, changes.Count); source1.Value++; Assert.AreEqual(1, changes.Count); EventPatternAssert.AreEqual(source1, "Value", changes.Last()); source2.Value++; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(source2, "Value", changes.Last()); } } }
public static void NullItemSimple() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake?, string?> > >(); var item = new Fake { Name = "1" }; var source = new ObservableCollection <Fake?> { item, null }; using (source.ObserveItemPropertyChanged(x => x.Name, signalInitial: false) .Subscribe(changes.Add)) { CollectionAssert.IsEmpty(changes); source.Add(null); EventPatternAssert.AreEqual(null, source, null, Maybe.None <string?>(), string.Empty, changes.Single()); item.Name = "new1"; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(item, item, item, Maybe.Some <string?>("new1"), "Name", changes.Last()); var item2 = new Fake { Name = "2" }; source[1] = item2; Assert.AreEqual(4, changes.Count); EventPatternAssert.AreEqual(null, source, null, Maybe.None <string?>(), string.Empty, changes[2]); EventPatternAssert.AreEqual(item2, source, item2, Maybe.Some <string?>("2"), string.Empty, changes[3]); } Assert.AreEqual(4, changes.Count); }
public void HandlesReplaceSimple() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake, string> > >(); var item1 = new Fake { Name = "1" }; var item2 = new Fake { Name = "2" }; var collection = new ObservableCollection <Fake> { item1, item2 }; using (collection.ObserveItemPropertyChanged(x => x.Name, signalInitial: false) .Subscribe(changes.Add)) { CollectionAssert.IsEmpty(changes); var item3 = new Fake { Name = "3" }; collection[0] = item3; EventPatternAssert.AreEqual(item3, item3, item3, Maybe.Some("3"), string.Empty, changes.Single()); item3.Name = "new"; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(item3, item3, item3, Maybe.Some("new"), "Name", changes.Last()); item1.Name = "new1"; Assert.AreEqual(2, changes.Count); // Stopped subscribing } Assert.AreEqual(2, changes.Count); }
public void HandlesAddNested() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake, string> > >(); var item1 = new Fake { Level1 = new Level1 { Name = "1" } }; var item2 = new Fake { Level1 = new Level1 { Name = "2" } }; var collection = new ObservableCollection <Fake> { item1, item2 }; using (collection.ObserveItemPropertyChanged(x => x.Level1.Name, signalInitial: false) .Subscribe(changes.Add)) { CollectionAssert.IsEmpty(changes); var item3 = new Fake { Level1 = new Level1 { Name = "3" } }; collection.Add(item3); EventPatternAssert.AreEqual(item3, item3.Level1, item3.Level1, Maybe.Some("3"), string.Empty, changes.Single()); item3.Level1.Name = "new"; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(item3, item3.Level1, item3.Level1, Maybe.Some("new"), "Name", changes.Last()); } }
public void TwoSubscriptionsOneObservable() { var changes1 = new List <EventPattern <PropertyChangedEventArgs> >(); var changes2 = new List <EventPattern <PropertyChangedEventArgs> >(); var fake = new Fake { Value = 1 }; var observable = fake.ObservePropertyChanged(x => x.IsTrue, signalInitial: false); using (observable.Subscribe(changes1.Add)) { using (observable.Subscribe(changes2.Add)) { Assert.AreEqual(0, changes1.Count); Assert.AreEqual(0, changes2.Count); fake.IsTrue = !fake.IsTrue; Assert.AreEqual(1, changes1.Count); Assert.AreEqual(1, changes2.Count); EventPatternAssert.AreEqual(fake, "IsTrue", changes1.Last()); EventPatternAssert.AreEqual(fake, "IsTrue", changes2.Last()); fake.IsTrue = !fake.IsTrue; Assert.AreEqual(2, changes1.Count); Assert.AreEqual(2, changes2.Count); EventPatternAssert.AreEqual(fake, "IsTrue", changes1.Last()); EventPatternAssert.AreEqual(fake, "IsTrue", changes2.Last()); } } }
public void SignalInitialWhenValueIsNull(bool signalInitial) { var changes = new List <EventPattern <PropertyChangedAndValueEventArgs <string?> > >(); var fake = new Fake(); using (fake.ObservePropertyChangedWithValue(x => x.Name, signalInitial) .Subscribe(changes.Add)) { if (signalInitial) { EventPatternAssert.AreEqual(fake, string.Empty, Maybe <string?> .Some(null), changes.Single()); fake.Name = "Johan"; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(fake, "Name", Maybe <string?> .Some("Johan"), changes.Last()); using (fake.ObservePropertyChangedWithValue(x => x.Name, signalInitial: true) .Subscribe(changes.Add)) { Assert.AreEqual(3, changes.Count); EventPatternAssert.AreEqual(fake, string.Empty, Maybe <string?> .Some("Johan"), changes.Last()); } } else { CollectionAssert.IsEmpty(changes); } } }
public void ReactsTwoPropertiesSameInstance() { var changes = new List <EventPattern <PropertyChangedEventArgs> >(); var fake = new Fake { Value = 1 }; using (fake.ObservePropertyChanged(x => x.Value, signalInitial: false) .Subscribe(changes.Add)) { using (fake.ObservePropertyChanged(x => x.IsTrue, signalInitial: false) .Subscribe(changes.Add)) { Assert.AreEqual(0, changes.Count); fake.Value++; Assert.AreEqual(1, changes.Count); EventPatternAssert.AreEqual(fake, "Value", changes.Last()); fake.IsTrue = !fake.IsTrue; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(fake, "IsTrue", changes.Last()); } } }
public void ReactsTwoInstances() { var changes = new List <EventPattern <PropertyChangedEventArgs> >(); var fake1 = new Fake { Value = 1 }; using (fake1.ObservePropertyChanged(x => x.Value, signalInitial: false) .Subscribe(changes.Add)) { var fake2 = new Fake { Value = 1 }; using (fake2.ObservePropertyChanged(x => x.Value, signalInitial: false) .Subscribe(changes.Add)) { Assert.AreEqual(0, changes.Count); fake1.Value++; Assert.AreEqual(1, changes.Count); EventPatternAssert.AreEqual(fake1, "Value", changes.Last()); fake2.Value++; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(fake2, "Value", changes.Last()); } } }
public void FourLevelsStartingWithNullAfterFirstThenAddingTwoLevels() { var changes = new List <EventPattern <PropertyChangedEventArgs> >(); var fake = new Fake(); using (fake.ObservePropertyChanged(x => x.Level1.Level2.Level3.Value) .Subscribe(changes.Add)) { EventPatternAssert.AreEqual(fake, string.Empty, changes.Single()); fake.Level1 = new Level1 { Level2 = new Level2 { Level3 = new Level3() } }; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(fake, "Level1", changes.Last()); fake.Level1.Level2.Level3.Value++; Assert.AreEqual(3, changes.Count); EventPatternAssert.AreEqual(fake.Level1.Level2.Level3, "Value", changes.Last()); fake.Level1 = null; Assert.AreEqual(4, changes.Count); EventPatternAssert.AreEqual(fake, "Level1", changes.Last()); } }
public void ThreeLevelsStartingWithFirstNullThenAddingTwoLevels() { var changes = new List <EventPattern <PropertyChangedEventArgs> >(); var fake = new Fake(); using (fake.ObservePropertyChanged(x => x.Level1.Level2.IsTrue) .Subscribe(changes.Add)) { EventPatternAssert.AreEqual(fake, string.Empty, changes.Single()); fake.Level1 = new Level1 { Level2 = new Level2() }; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(fake, "Level1", changes.Last()); fake.Level1.Level2.IsTrue = !fake.Level1.Level2.IsTrue; Assert.AreEqual(3, changes.Count); EventPatternAssert.AreEqual(fake.Level1.Level2, "IsTrue", changes.Last()); fake.Level1 = null; Assert.AreEqual(4, changes.Count); EventPatternAssert.AreEqual(fake, "Level1", changes.Last()); } }
public void ThreeLevelsStartingWithNullGenericGeneric() { var changes = new List <EventPattern <PropertyChangedEventArgs> >(); var fake = new Fake(); using (fake.ObservePropertyChanged(x => x.NextInt.Next.Value) .Subscribe(changes.Add)) { EventPatternAssert.AreEqual(fake, string.Empty, changes.Single()); fake.NextInt = new Level <int> { Next = new Level <int>() }; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(fake, "NextInt", changes.Last()); fake.NextInt.Next.Value++; Assert.AreEqual(3, changes.Count); EventPatternAssert.AreEqual(fake.NextInt.Next, "Value", changes.Last()); fake.NextInt = null; Assert.AreEqual(4, changes.Count); EventPatternAssert.AreEqual(fake, "NextInt", changes.Last()); } }
public void TwoLevelsExisting() { var changes = new List <EventPattern <PropertyChangedEventArgs> >(); var fake = new Fake { Level1 = new Level1 { Level2 = new Level2() } }; using (fake.ObservePropertyChanged(x => x.Level1.Level2, signalInitial: false) .Subscribe(changes.Add)) { CollectionAssert.IsEmpty(changes); fake.Level1.Level2 = new Level2(); EventPatternAssert.AreEqual(fake.Level1, "Level2", changes.Single()); fake.Level1.Level2 = null; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(fake.Level1, "Level2", changes.Last()); fake.Level1 = null; Assert.AreEqual(3, changes.Count); EventPatternAssert.AreEqual(fake, "Level1", changes.Last()); fake.OnPropertyChanged("Level1"); Assert.AreEqual(3, changes.Count); } }
public void Reacts() { var changes = new List <EventPattern <PropertyChangedEventArgs> >(); var fake = new Fake(); using (fake.ObservePropertyChanged(x => x.Next.IsTrue) .Subscribe(changes.Add)) { EventPatternAssert.AreEqual(fake, string.Empty, changes.Single()); fake.Next = new Level { IsTrue = false }; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(fake, "Next", changes.Last()); fake.Next.IsTrue = true; Assert.AreEqual(3, changes.Count); EventPatternAssert.AreEqual(fake.Next, "IsTrue", changes.Last()); var level1 = fake.Next; fake.Next = null; Assert.AreEqual(4, changes.Count); EventPatternAssert.AreEqual(fake, "Next", changes.Last()); level1.IsTrue = !level1.IsTrue; Assert.AreEqual(4, changes.Count); } }
public void SignalInitialWhenHasValue(bool signalInitial) { var changes = new List <EventPattern <PropertyChangedAndValueEventArgs <string> > >(); var fake = new Fake { Level1 = new Level1 { Name = "Johan" } }; using (fake.ObservePropertyChangedWithValue(x => x.Level1.Name, signalInitial) .Subscribe(changes.Add)) { if (signalInitial) { EventPatternAssert.AreEqual(fake.Level1, string.Empty, Maybe.Some("Johan"), changes.Single()); fake.Level1.Name = "Erik"; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(fake.Level1, "Name", Maybe <string> .Some("Erik"), changes.Last()); using (fake.ObservePropertyChangedWithValue(x => x.Level1.Name, signalInitial) .Subscribe(changes.Add)) { Assert.AreEqual(3, changes.Count); EventPatternAssert.AreEqual(fake.Level1, string.Empty, Maybe <string> .Some("Erik"), changes.Last()); } } else { CollectionAssert.IsEmpty(changes); } } }
public static void StopsSubscribing() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake, string?> > >(); var collection1 = new ObservableCollection <Fake> { new Fake { Name = "1" } }; var fake = new FakeWithCollection { Collection = collection1 }; using (fake.ObservePropertyChangedWithValue(x => x.Collection, signalInitial: true) .ItemPropertyChanged(x => x.Name) .Subscribe(changes.Add)) { EventPatternAssert.AreEqual(collection1[0], collection1, collection1[0], Maybe.Some <string?>("1"), string.Empty, changes.Single()); fake.Collection = null; Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(null, collection1, collection1[0], Maybe.Some <string?>("1"), string.Empty, changes.Last()); collection1[0].Name = "new"; Assert.AreEqual(2, changes.Count); var collection2 = new ObservableCollection <Fake> { new Fake { Name = "1" } }; fake.Collection = collection2; Assert.AreEqual(3, changes.Count); EventPatternAssert.AreEqual(collection2[0], collection2, collection2[0], Maybe.Some <string?>("1"), string.Empty, changes.Last()); } }
public void ReplacingCollectionWithNewWithNewItems() { var changes = new List <EventPattern <ItemPropertyChangedEventArgs <Fake, string> > >(); var collection = new ObservableCollection <Fake> { new Fake { Next = new Level { Name = "1" } }, new Fake { Next = new Level { Name = "2" } } }; var fake = new FakeWithCollection { Collection = collection }; using (fake.ObservePropertyChangedWithValue(x => x.Collection, signalInitial: true) .ItemPropertyChanged(x => x.Next.Name) .Subscribe(changes.Add)) { Assert.AreEqual(2, changes.Count); EventPatternAssert.AreEqual(collection[0], collection[0].Next, collection[0].Next, Maybe.Some("1"), string.Empty, changes[0]); EventPatternAssert.AreEqual(collection[1], collection[1].Next, collection[1].Next, Maybe.Some("2"), string.Empty, changes[1]); fake.Collection = new ObservableCollection <Fake> { new Fake { Next = new Level { Name = "3" } }, new Fake { Next = new Level { Name = "4" } } }; Assert.AreEqual(4, changes.Count); EventPatternAssert.AreEqual(fake.Collection[0], fake.Collection[0].Next, fake.Collection[0].Next, Maybe.Some("3"), string.Empty, changes[2]); EventPatternAssert.AreEqual(fake.Collection[1], fake.Collection[1].Next, fake.Collection[1].Next, Maybe.Some("4"), string.Empty, changes[3]); fake.Collection[0].Next.Name = "5"; Assert.AreEqual(5, changes.Count); EventPatternAssert.AreEqual(fake.Collection[0], fake.Collection[0].Next, fake.Collection[0].Next, Maybe.Some("5"), "Name", changes[4]); collection.Add(new Fake()); Assert.AreEqual(5, changes.Count); } Assert.AreEqual(5, changes.Count); }
public void LastInPathInPathSignalsWhenHasValue(string propertyName) { var changes = new List <EventPattern <PropertyChangedEventArgs> >(); var fake = new Fake { Level1 = new Level1() }; using (fake.ObservePropertyChanged(x => x.Level1.IsTrue, signalInitial: false) .Subscribe(changes.Add)) { fake.Level1.OnPropertyChanged(propertyName); EventPatternAssert.AreEqual(fake.Level1, propertyName, changes.Single()); } }