public void FirstOrDefault_ObservableSourceNewFirstItemAdded_Update() { var update = false; var coll = new NotifyCollection <string>() { "23" }; var test = Observable.Expression(() => coll.FirstOrDefault()); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual("42", e.NewValue); Assert.AreEqual("23", e.OldValue); }; Assert.AreEqual("23", test.Value); Assert.IsFalse(update); coll.Insert(0, "42"); Assert.IsTrue(update); Assert.AreEqual("42", test.Value); }
public void PredicateFirstOrDefault_ObservableSourceFirstItemAdded_NoUpdateWhenDetached() { var update = false; var coll = new NotifyCollection <string>() { "1" }; var test = Observable.Expression(() => coll.FirstOrDefault(s => s.Length > 1)); test.ValueChanged += (o, e) => update = true; Assert.IsNull(test.Value); Assert.IsFalse(update); test.Detach(); update = false; coll.Add("42"); Assert.IsFalse(update); test.Attach(); Assert.IsTrue(update); Assert.AreEqual("42", test.Value); update = false; coll.Remove("42"); Assert.IsTrue(update); }
public void PredicateFirstOrDefault_ObservableSourceRemoveNewFirstItem_Update() { var update = false; var coll = new NotifyCollection <string>() { "1", "42", "23" }; var test = Observable.Expression(() => coll.FirstOrDefault(s => s.Length > 1)); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual("42", e.OldValue); Assert.AreEqual("23", e.NewValue); }; Assert.AreEqual("42", test.Value); Assert.IsFalse(update); coll.Remove("42"); Assert.IsTrue(update); Assert.AreEqual("23", test.Value); }
public void ReversableFirstOrDefault_SetToNull_Correct() { var collection = new NotifyCollection <string>() { "a", "b", "c" }; SetValue(() => collection.FirstOrDefault(), null); Assert.AreEqual(0, collection.Count); }
public void ReversableFirstOrDefault_WithPredicate_SetToNull_Correct() { var collection = new NotifyCollection <string>() { "a", "b", "c" }; SetValue(() => collection.FirstOrDefault(s => string.Compare(s, "a") > 0), null); Assert.AreEqual(1, collection.Count); Assert.IsTrue(collection.Contains("a")); }
public void ReversableFirstOrDefault_SetToExistingItem_Correct() { var collection = new NotifyCollection <string>() { "a", "b", "c" }; SetValue(() => collection.FirstOrDefault(), "b"); Assert.AreEqual(3, collection.Count); Assert.IsTrue(collection.Contains("a")); Assert.IsTrue(collection.Contains("b")); Assert.IsTrue(collection.Contains("c")); }
public void ReversableFirstOrDefault_WithPredicate_SetToOtherItem_Correct() { INotifyCollection <string> collection = new NotifyCollection <string>() { "a", "b", "c" }; SetValue(() => collection.FirstOrDefault(s => string.Compare(s, "a") > 0), "d"); Assert.AreEqual(4, collection.Count); Assert.IsTrue(collection.Contains("a")); Assert.IsTrue(collection.Contains("b")); Assert.IsTrue(collection.Contains("c")); Assert.IsTrue(collection.Contains("d")); }
public void FirstOrDefault_ObservableSourceOtherItemAdded_NoUpdate() { var update = false; var coll = new NotifyCollection<string>() { "23" }; var test = Observable.Expression(() => coll.FirstOrDefault()); test.ValueChanged += (o, e) => update = true; Assert.AreEqual("23", test.Value); Assert.IsFalse(update); coll.Add("42"); Assert.IsFalse(update); }
public void FirstOrDefault_ObservableSourceOtherItemAdded_NoUpdate() { var update = false; var coll = new NotifyCollection <string>() { "23" }; var test = Observable.Expression(() => coll.FirstOrDefault()); test.ValueChanged += (o, e) => update = true; Assert.AreEqual("23", test.Value); Assert.IsFalse(update); coll.Add("42"); Assert.IsFalse(update); }
public void FirstOrDefault_ObservableSourceNewFirstItemAdded_Update() { var update = false; var coll = new NotifyCollection<string>() { "23" }; var test = Observable.Expression(() => coll.FirstOrDefault()); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual("42", e.NewValue); Assert.AreEqual("23", e.OldValue); }; Assert.AreEqual("23", test.Value); Assert.IsFalse(update); coll.Insert(0, "42"); Assert.IsTrue(update); Assert.AreEqual("42", test.Value); }
public void PredicateFirstOrDefault_ObservableSourceFirstItemAdded_NoUpdateWhenDetached() { var update = false; var coll = new NotifyCollection<string>() { "1" }; var test = Observable.Expression(() => coll.FirstOrDefault(s => s.Length > 1)); test.ValueChanged += (o, e) => update = true; Assert.IsNull(test.Value); Assert.IsFalse(update); test.Detach(); update = false; coll.Add("42"); Assert.IsFalse(update); test.Attach(); Assert.IsTrue(update); Assert.AreEqual("42", test.Value); update = false; coll.Remove("42"); Assert.IsTrue(update); }
public void PredicateFirstOrDefault_ObservableSourceOtherItemRemoved_NoUpdate() { var update = false; var coll = new NotifyCollection<string>() { "1", "23", "42" }; var test = Observable.Expression(() => coll.FirstOrDefault(s => s.Length > 1)); test.ValueChanged += (o, e) => update = true; Assert.AreEqual("23", test.Value); Assert.IsFalse(update); coll.Remove("42"); Assert.IsFalse(update); }
public void PredicateFirstOrDefault_ObservableSourceFirstItemAdded_Update() { var update = false; var coll = new NotifyCollection<string>() { "1" }; var test = Observable.Expression(() => coll.FirstOrDefault(s => s.Length > 1)); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual("42", e.NewValue); Assert.IsNull(e.OldValue); }; Assert.IsNull(test.Value); Assert.IsFalse(update); coll.Add("42"); Assert.IsTrue(update); Assert.AreEqual("42", test.Value); }
public IEnumerable <T> GetSequenceForItem(T item) { return(Sequences.FirstOrDefault(s => s.Contains(item))); }