Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        public void ReversableFirstOrDefault_SetToNull_Correct()
        {
            var collection = new NotifyCollection <string>()
            {
                "a", "b", "c"
            };

            SetValue(() => collection.FirstOrDefault(), null);
            Assert.AreEqual(0, collection.Count);
        }
Exemplo n.º 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"));
        }
Exemplo n.º 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"));
        }
Exemplo n.º 7
0
        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"));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 14
0
 public IEnumerable <T> GetSequenceForItem(T item)
 {
     return(Sequences.FirstOrDefault(s => s.Contains(item)));
 }