Esempio n. 1
0
        public void Count_ObservableSourceItemAdded_NoUpdateWhenDetached()
        {
            var update = false;
            var coll = new NotifyCollection<int>() { 1, 2, 3 };

            var test = Observable.Expression(() => coll.WithUpdates().Count());

            test.ValueChanged += (o, e) => update = true;

            Assert.AreEqual(3, test.Value);
            Assert.IsFalse(update);

            test.Detach();

            coll.Add(4);

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual(4, test.Value);
            update = true;

            coll.Add(5);

            Assert.IsTrue(update);
        }
Esempio n. 2
0
        public void NullableIntAverage_ObservableSource_NoUpdatesWhenDetached()
        {
            var update = false;
            var coll   = new NotifyCollection <int?>()
            {
                1, 2, 3, null
            };
            var testColl = coll.WithUpdates();

            var test = Observable.Expression(() => testColl.Average());

            test.ValueChanged += (o, e) => update = true;

            Assert.AreEqual(2, test.Value);
            Assert.AreEqual(2, testColl.Average());
            Assert.IsFalse(update);

            test.Detach();

            coll.Add(4);

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual(2.5, test.Value);
            update = false;

            coll.Add(5);

            Assert.IsTrue(update);
        }
Esempio n. 3
0
        public void Count_ObservableSourceItemAdded_NoUpdateWhenDetached()
        {
            var update = false;
            var coll   = new NotifyCollection <int>()
            {
                1, 2, 3
            };

            var test = Observable.Expression(() => coll.WithUpdates().Count());

            test.ValueChanged += (o, e) => update = true;

            Assert.AreEqual(3, test.Value);
            Assert.IsFalse(update);

            test.Detach();

            coll.Add(4);

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual(4, test.Value);
            update = true;

            coll.Add(5);

            Assert.IsTrue(update);
        }
Esempio n. 4
0
        public void CountPredicate_ObservableSourceReset_Update()
        {
            var update = false;
            var coll   = new NotifyCollection <int>()
            {
                1, 2, 3, -1, -3
            };

            var test = Observable.Expression(() => coll.WithUpdates().Count(i => i > 0));

            test.ValueChanged += (o, e) => update = true;

            coll.Clear();

            Assert.IsTrue(update);
        }
Esempio n. 5
0
        public void GroupBy_ObservableSource_NoUpdatesWhenDetached()
        {
            var update = false;
            ICollection <Dummy <string> > coll = new NotifyCollection <Dummy <string> >();

            var test = coll.WithUpdates().GroupBy(d => d.Item);

            test.CollectionChanged += (o, e) => update = true;

            Assert.IsTrue(!test.Any());
            Assert.IsFalse(update);

            test.Detach();
            update = false;

            var testDummy = new ObservableDummy <string>()
            {
                Item = "42"
            };

            coll.Add(testDummy);

            Assert.IsFalse(update);

            testDummy.Item = "23";

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual("23", test.FirstOrDefault().Key);
            update = false;

            testDummy.Item = "42";

            Assert.IsTrue(update);
            update = false;

            coll.Remove(testDummy);

            Assert.IsTrue(update);
        }
Esempio n. 6
0
        public void LambdaIntAverage_ObservableSourceItemAdded_NoUpdatesWhenDetached()
        {
            var update = false;
            var coll   = new NotifyCollection <Dummy <int> >()
            {
                new Dummy <int>(1), new Dummy <int>(2), new Dummy <int>(3)
            };
            var testColl = coll.WithUpdates();

            var test = Observable.Expression(() => testColl.Average(d => d.Item));

            test.ValueChanged += (o, e) => update = true;

            Assert.AreEqual(2, test.Value);
            Assert.AreEqual(2, testColl.Average(d => d.Item));
            Assert.IsFalse(update);

            test.Detach();

            var testDummy = new ObservableDummy <int>(5);

            coll.Add(testDummy);

            Assert.IsFalse(update);

            testDummy.Item = 4;

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual(2.5, test.Value);
            update = false;

            testDummy.Item = 5;

            Assert.IsTrue(update);
            update = false;

            coll.Remove(testDummy);
        }
Esempio n. 7
0
        public void Distinct_ObservableSourceReset_Update()
        {
            var update = false;

            var coll = new NotifyCollection <int>()
            {
                1, 2, 2, 3
            };

            var test = coll.WithUpdates().Distinct();

            test.CollectionChanged += (o, e) =>
            {
                update = true;
                Assert.AreEqual(NotifyCollectionChangedAction.Reset, e.Action);
            };

            coll.Clear();

            Assert.IsTrue(update);
            Assert.AreEqual(0, test.Count());
        }
Esempio n. 8
0
        public void GroupBy_ObservableSource_NoUpdatesWhenDetached()
        {
            var update = false;
            ICollection<Dummy<string>> coll = new NotifyCollection<Dummy<string>>();

            var test = coll.WithUpdates().GroupBy(d => d.Item);

            test.CollectionChanged += (o, e) => update = true;

            Assert.IsTrue(!test.Any());
            Assert.IsFalse(update);

            test.Detach();
            update = false;

            var testDummy = new ObservableDummy<string>() { Item = "42" };
            coll.Add(testDummy);

            Assert.IsFalse(update);

            testDummy.Item = "23";

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual("23", test.FirstOrDefault().Key);
            update = false;

            testDummy.Item = "42";

            Assert.IsTrue(update);
            update = false;

            coll.Remove(testDummy);

            Assert.IsTrue(update);
        }
Esempio n. 9
0
        public void LambdaIntAverage_ObservableSourceItemAdded_NoUpdatesWhenDetached()
        {
            var update = false;
            var coll = new NotifyCollection<Dummy<int>>() { new Dummy<int>(1), new Dummy<int>(2), new Dummy<int>(3) };
            var testColl = coll.WithUpdates();

            var test = Observable.Expression(() => testColl.Average(d => d.Item));

            test.ValueChanged += (o, e) => update = true;

            Assert.AreEqual(2, test.Value);
            Assert.AreEqual(2, testColl.Average(d => d.Item));
            Assert.IsFalse(update);

            test.Detach();

            var testDummy = new ObservableDummy<int>(5);
            coll.Add(testDummy);

            Assert.IsFalse(update);

            testDummy.Item = 4;

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual(2.5, test.Value);
            update = false;

            testDummy.Item = 5;

            Assert.IsTrue(update);
            update = false;

            coll.Remove(testDummy);
        }
Esempio n. 10
0
        public void Contains_ObservableSourceReset_Update()
        {
            var update = false;
            var coll = new NotifyCollection<int>() { 1, 2, 3 };

            var test = Observable.Expression(() => coll.WithUpdates().Contains(2));

            test.ValueChanged += (o, e) => update = true;

            coll.Clear();

            Assert.IsTrue(update);
        }
Esempio n. 11
0
        public void Distinct_ObservableSourceReset_Update()
        {
            var update = false;

            var coll = new NotifyCollection<int>() { 1, 2, 2, 3 };

            var test = coll.WithUpdates().Distinct();

            test.CollectionChanged += (o, e) =>
            {
                update = true;
                Assert.AreEqual(NotifyCollectionChangedAction.Reset, e.Action);
            };

            coll.Clear();

            Assert.IsTrue(update);
            Assert.AreEqual(0, test.Count());
        }
Esempio n. 12
0
        public void NullableIntAverage_ObservableSource_NoUpdatesWhenDetached()
        {
            var update = false;
            var coll = new NotifyCollection<int?>() { 1, 2, 3, null };
            var testColl = coll.WithUpdates();

            var test = Observable.Expression(() => testColl.Average());

            test.ValueChanged += (o, e) => update = true;

            Assert.AreEqual(2, test.Value);
            Assert.AreEqual(2, testColl.Average());
            Assert.IsFalse(update);

            test.Detach();

            coll.Add(4);

            Assert.IsFalse(update);

            test.Attach();

            Assert.IsTrue(update);
            Assert.AreEqual(2.5, test.Value);
            update = false;

            coll.Add(5);

            Assert.IsTrue(update);
        }