Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        public void ReversableFirstOrDefault_SetToNull_Correct()
        {
            var collection = new NotifyCollection <string>()
            {
                "a", "b", "c"
            };

            SetValue(() => collection.FirstOrDefault(), null);
            Assert.AreEqual(0, collection.Count);
        }
Exemple #5
0
        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"));
        }
Exemple #6
0
        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"));
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        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);
        }
Exemple #13
0
        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);
        }
Exemple #14
0
 public IEnumerable <T> GetSequenceForItem(T item)
 {
     return(Sequences.FirstOrDefault(s => s.Contains(item)));
 }