コード例 #1
0
        public void TestReusableCells()
        {
            MockCellEntry[] cells =
            {
                new MockCellEntry(typeof(TableViewCellMock1), 10),
                new MockCellEntry(typeof(TableViewCellMock2), 10),
                new MockCellEntry(typeof(TableViewCellMock3), 10),
                new MockCellEntry(typeof(TableViewCellMock1), 10),
                new MockCellEntry(typeof(TableViewCellMock2), 10),
                new MockCellEntry(typeof(TableViewCellMock3), 10),
            };

            TableViewAdapter adapter = new TestCellsHeightTableAdapter(cells);

            TableViewMock table = new TableViewMock(320, 25);

            table.DataSource = adapter;
            table.Delegate   = adapter;
            table.ReloadData();

            TableViewCell a1 = table.FirstVisibleCell;
            TableViewCell a2 = a1.NextCell;
            TableViewCell a3 = a2.NextCell;

            Assert.AreEqual(typeof(TableViewCellMock1), a1.GetType());
            Assert.AreEqual(typeof(TableViewCellMock2), a2.GetType());
            Assert.AreEqual(typeof(TableViewCellMock3), a3.GetType());

            table.Scroll(10);

            TableViewCell b1 = table.FirstVisibleCell;
            TableViewCell b2 = b1.NextCell;
            TableViewCell b3 = b2.NextCell;

            Assert.AreSame(a2, b1);
            Assert.AreSame(a3, b2);
            Assert.AreSame(a1, b3);

            table.Scroll(10);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a3, b1);
            Assert.AreSame(a1, b2);
            Assert.AreSame(a2, b3);

            table.Scroll(10);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a1, b1);
            Assert.AreSame(a2, b2);
            Assert.AreSame(a3, b3);

            table.Scroll(5);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a1, b1);
            Assert.AreSame(a2, b2);
            Assert.AreSame(a3, b3);

            table.Scroll(-5);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a1, b1);
            Assert.AreSame(a2, b2);
            Assert.AreSame(a3, b3);

            table.Scroll(-10);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a3, b1);
            Assert.AreSame(a1, b2);
            Assert.AreSame(a2, b3);

            table.Scroll(-10);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a2, b1);
            Assert.AreSame(a3, b2);
            Assert.AreSame(a1, b3);

            table.Scroll(-10);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a1, b1);
            Assert.AreSame(a2, b2);
            Assert.AreSame(a3, b3);

            Assert.AreEqual(1, TableViewCellMock1.instanceCount);
            Assert.AreEqual(1, TableViewCellMock2.instanceCount);
            Assert.AreEqual(1, TableViewCellMock3.instanceCount);
        }