예제 #1
0
파일: UnitTest1.cs 프로젝트: FrederikP/NMF
        public void SelectManyWithAverage1()
        {
            var updates = 0;
            var coll = new NotifyCollection<TestItem>();

            var query = from item in coll
                        group item by item.Team into team
                        let avg = team.Average(it => it.Items)
                        from item2 in team
                        where item2.Items < avg
                        select item2;


            var testItem1 = new TestItem() { Items = 1, Team = "A" };
            var testItem2 = new TestItem() { Items = 2, Team = "A" };

            query.CollectionChanged += (o, e) =>
            {
                updates++;
                Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action);
                Assert.AreEqual(1, e.NewItems.Count);
                Assert.AreSame(testItem1, e.NewItems[0]);
            };

            coll.Add(testItem1);

            Assert.AreEqual(0, updates);

            coll.Add(testItem2);

            Assert.AreEqual(1, updates);
            Assert.AreEqual(1, query.Count());
            Assert.IsTrue(query.Contains(testItem1));
        }
예제 #2
0
        public void SelectManyWithAverage1()
        {
            var updates = 0;
            INotifyCollection <TestItem> coll = new NotifyCollection <TestItem>();

            var query = from item in coll
                        group item by item.Team into team
                        let avg = team.Average(it => it.Items)
                                  from item2 in team
                                  where item2.Items < avg
                                  select item2;


            var testItem1 = new TestItem()
            {
                Items = 1, Team = "A"
            };
            var testItem2 = new TestItem()
            {
                Items = 2, Team = "A"
            };

            query.CollectionChanged += (o, e) =>
            {
                updates++;
                Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action);
                Assert.AreEqual(1, e.NewItems.Count);
                Assert.AreSame(testItem1, e.NewItems[0]);
            };

            coll.Add(testItem1);

            Assert.AreEqual(0, updates);

            coll.Add(testItem2);

            Assert.AreEqual(1, updates);
            Assert.AreEqual(1, query.Count());
            Assert.IsTrue(query.Contains(testItem1));
        }
예제 #3
0
        public void SelectWithAverage2()
        {
            var updates = 0;
            var coll    = new ObservableCollection <TestItem>();

            var query = from item in coll.WithUpdates()
                        where item.Items < coll.WithUpdates().Average(t => t.Items)
                        select item;


            var testItem1 = new TestItem()
            {
                Items = 1, Team = "A"
            };
            var testItem2 = new TestItem()
            {
                Items = 2, Team = "A"
            };

            query.CollectionChanged += (o, e) =>
            {
                updates++;
                Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action);
                Assert.AreEqual(1, e.NewItems.Count);
                Assert.AreSame(testItem1, e.NewItems[0]);
            };

            coll.Add(testItem2);

            Assert.AreEqual(0, updates);

            coll.Add(testItem1);

            Assert.AreEqual(1, updates);
            Assert.AreEqual(1, query.Count());
            Assert.IsTrue(query.Contains(testItem1));
        }
예제 #4
0
파일: UnitTest1.cs 프로젝트: FrederikP/NMF
        public void SelectWithAverage2()
        {
            var updates = 0;
            var coll = new NotifyCollection<TestItem>();

            var query = from item in coll
                        where item.Items < coll.Average(t => t.Items)
                        select item;


            var testItem1 = new TestItem() { Items = 1, Team = "A" };
            var testItem2 = new TestItem() { Items = 2, Team = "A" };

            query.CollectionChanged += (o, e) =>
            {
                updates++;
                Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action);
                Assert.AreEqual(1, e.NewItems.Count);
                Assert.AreSame(testItem1, e.NewItems[0]);
            };

            coll.Add(testItem2);

            Assert.AreEqual(0, updates);

            coll.Add(testItem1);

            Assert.AreEqual(1, updates);
            Assert.AreEqual(1, query.Count());
            Assert.IsTrue(query.Contains(testItem1));
        }