public void FindByIdTest()
        {
            testTable = new RandomAccessTable <TestEntity>();

            testTable.CollectionChanged += testTable_CollectionChanged;

            sampleList = new List <TestEntity>()
            {
                new TestEntity(1),
                new TestEntity(2),
                new TestEntity(3),
                new TestEntity(4),
                new TestEntity(5),
                new TestEntity(6),
                new TestEntity(7)
            };

            foreach (TestEntity item in sampleList)
            {
                testTable.Add(item);
            }

            for (int i = 0; i < testTable.Count; ++i)
            {
                Assert.AreEqual(i + 1, testTable.FindById(i + 1).Id);
            }

            Assert.AreEqual(null, testTable.FindById(100));
        }
        public void AddRemoveTest()
        {
            testTable = new RandomAccessTable <TestEntity>();

            testTable.CollectionChanged += testTable_CollectionChanged;

            sampleList = new List <TestEntity>()
            {
                new TestEntity(1),
                new TestEntity(2),
                new TestEntity(3),
                new TestEntity(4),
                new TestEntity(5),
                new TestEntity(6),
                new TestEntity(7)
            };

            foreach (TestEntity item in sampleList)
            {
                testTable.Add(item);
            }

            Compare();

            {
                TestEntity item = sampleList[3];

                Assert.AreEqual(testTable.IndexOf(item), sampleList.IndexOf(item));

                testTable.Remove(item);
                sampleList.Remove(item);

                Compare();
            }

            {
                TestEntity item = new TestEntity(8);

                testTable.Add(item);
                sampleList.Add(item);

                Compare();
            }

            {
                testTable.Clear();
                sampleList.Clear();

                Compare();
            }
        }
示例#3
0
        private void TestButton_Click(object sender, RoutedEventArgs e)
        {
            targetsGrid.ItemsSource = null;
            targetsGrid.DataContext = null;

            //ObservableCollection<Target> coll = new ObservableCollection<Target>();

            RandomAccessTable <Target> coll = new RandomAccessTable <Target>();

            for (long id = 1; id <= 3; ++id)
            {
                coll.Add(
                    new Target(id)
                {
                    Name = String.Format("new-target-{0}", id)
                });
            }

            targetsGrid.ItemsSource = coll;

            testColl = coll;
        }