Exemplo n.º 1
0
 public void InsertParagraph(int index, ParagraphDemo item)
 {
     m_paragraphs.Insert(index, item);
 }
		public void RaiseChangedTest()
		{
			ModifiedMonitoredList<MockParagraph> modifiedList = new ModifiedMonitoredList<MockParagraph>();
			List<MockParagraph> list = new List<MockParagraph>();
			modifiedList.Changed += RaiseParagraphsChanged;

			MockParagraph para1 = new MockParagraph("Para One");
			MockParagraph para2 = new MockParagraph("Para Two");
			MockParagraph para3 = new MockParagraph("Para Three");
			MockParagraph para4 = new MockParagraph("Para Four");
			MockParagraph para5 = new MockParagraph("Para Five");

			list.Add(para1);
			modifiedList.Add(para1);
			Assert.That(paragraphChangedEvent.FirstChange == 0);
			Assert.That(paragraphChangedEvent.NumberAdded == 1);
			Assert.That(paragraphChangedEvent.NumberDeleted == 0);
			Assert.That(CompareLists(list, modifiedList));

			list.Add(para3);
			modifiedList.Add(para3);
			Assert.That(paragraphChangedEvent.FirstChange == 1);
			Assert.That(paragraphChangedEvent.NumberAdded == 1);
			Assert.That(paragraphChangedEvent.NumberDeleted == 0);
			Assert.That(CompareLists(list, modifiedList));

			list.Add(para5);
			modifiedList.Add(para5);
			Assert.That(paragraphChangedEvent.FirstChange == 2);
			Assert.That(paragraphChangedEvent.NumberAdded == 1);
			Assert.That(paragraphChangedEvent.NumberDeleted == 0);
			Assert.That(CompareLists(list, modifiedList));

			list.Insert(1, para2);
			modifiedList.Insert(1, para2);
			Assert.That(paragraphChangedEvent.FirstChange == 1);
			Assert.That(paragraphChangedEvent.NumberAdded == 1);
			Assert.That(paragraphChangedEvent.NumberDeleted == 0);
			Assert.That(CompareLists(list, modifiedList));

			list.Insert(3, para4);
			modifiedList.Insert(3, para4);
			Assert.That(paragraphChangedEvent.FirstChange == 3);
			Assert.That(paragraphChangedEvent.NumberAdded == 1);
			Assert.That(paragraphChangedEvent.NumberDeleted == 0);
			Assert.That(CompareLists(list, modifiedList));

			list[2] = para2;
			modifiedList[2] = para2;
			Assert.That(paragraphChangedEvent.FirstChange == 2);
			Assert.That(paragraphChangedEvent.NumberAdded == 1);
			Assert.That(paragraphChangedEvent.NumberDeleted == 1);
			Assert.That(CompareLists(list, modifiedList));

			list.Remove(para4);
			modifiedList.Remove(para4);
			Assert.That(paragraphChangedEvent.FirstChange == 3);
			Assert.That(paragraphChangedEvent.NumberAdded == 0);
			Assert.That(paragraphChangedEvent.NumberDeleted == 1);
			Assert.That(CompareLists(list, modifiedList));

			list.RemoveAt(1);
			modifiedList.RemoveAt(1);
			Assert.That(paragraphChangedEvent.FirstChange == 1);
			Assert.That(paragraphChangedEvent.NumberAdded == 0);
			Assert.That(paragraphChangedEvent.NumberDeleted == 1);
			Assert.That(CompareLists(list, modifiedList));

			modifiedList.SimulateChange(0, 2);
			Assert.That(paragraphChangedEvent.FirstChange == 0);
			Assert.That(paragraphChangedEvent.NumberAdded == 2);
			Assert.That(paragraphChangedEvent.NumberDeleted == 2);
			Assert.That(CompareLists(list, modifiedList));

			list.Clear();
			modifiedList.Clear();
			Assert.That(paragraphChangedEvent.FirstChange == 0);
			Assert.That(paragraphChangedEvent.NumberAdded == 0);
			Assert.That(paragraphChangedEvent.NumberDeleted == 3);
			Assert.That(CompareLists(list, modifiedList));

		}
        public void RaiseChangedTest()
        {
            ModifiedMonitoredList <MockParagraph> modifiedList = new ModifiedMonitoredList <MockParagraph>();
            List <MockParagraph> list = new List <MockParagraph>();

            modifiedList.Changed += RaiseParagraphsChanged;

            MockParagraph para1 = new MockParagraph("Para One");
            MockParagraph para2 = new MockParagraph("Para Two");
            MockParagraph para3 = new MockParagraph("Para Three");
            MockParagraph para4 = new MockParagraph("Para Four");
            MockParagraph para5 = new MockParagraph("Para Five");

            list.Add(para1);
            modifiedList.Add(para1);
            Assert.That(paragraphChangedEvent.FirstChange == 0);
            Assert.That(paragraphChangedEvent.NumberAdded == 1);
            Assert.That(paragraphChangedEvent.NumberDeleted == 0);
            Assert.That(CompareLists(list, modifiedList));

            list.Add(para3);
            modifiedList.Add(para3);
            Assert.That(paragraphChangedEvent.FirstChange == 1);
            Assert.That(paragraphChangedEvent.NumberAdded == 1);
            Assert.That(paragraphChangedEvent.NumberDeleted == 0);
            Assert.That(CompareLists(list, modifiedList));

            list.Add(para5);
            modifiedList.Add(para5);
            Assert.That(paragraphChangedEvent.FirstChange == 2);
            Assert.That(paragraphChangedEvent.NumberAdded == 1);
            Assert.That(paragraphChangedEvent.NumberDeleted == 0);
            Assert.That(CompareLists(list, modifiedList));

            list.Insert(1, para2);
            modifiedList.Insert(1, para2);
            Assert.That(paragraphChangedEvent.FirstChange == 1);
            Assert.That(paragraphChangedEvent.NumberAdded == 1);
            Assert.That(paragraphChangedEvent.NumberDeleted == 0);
            Assert.That(CompareLists(list, modifiedList));

            list.Insert(3, para4);
            modifiedList.Insert(3, para4);
            Assert.That(paragraphChangedEvent.FirstChange == 3);
            Assert.That(paragraphChangedEvent.NumberAdded == 1);
            Assert.That(paragraphChangedEvent.NumberDeleted == 0);
            Assert.That(CompareLists(list, modifiedList));

            list[2]         = para2;
            modifiedList[2] = para2;
            Assert.That(paragraphChangedEvent.FirstChange == 2);
            Assert.That(paragraphChangedEvent.NumberAdded == 1);
            Assert.That(paragraphChangedEvent.NumberDeleted == 1);
            Assert.That(CompareLists(list, modifiedList));

            list.Remove(para4);
            modifiedList.Remove(para4);
            Assert.That(paragraphChangedEvent.FirstChange == 3);
            Assert.That(paragraphChangedEvent.NumberAdded == 0);
            Assert.That(paragraphChangedEvent.NumberDeleted == 1);
            Assert.That(CompareLists(list, modifiedList));

            list.RemoveAt(1);
            modifiedList.RemoveAt(1);
            Assert.That(paragraphChangedEvent.FirstChange == 1);
            Assert.That(paragraphChangedEvent.NumberAdded == 0);
            Assert.That(paragraphChangedEvent.NumberDeleted == 1);
            Assert.That(CompareLists(list, modifiedList));

            modifiedList.SimulateChange(0, 2);
            Assert.That(paragraphChangedEvent.FirstChange == 0);
            Assert.That(paragraphChangedEvent.NumberAdded == 2);
            Assert.That(paragraphChangedEvent.NumberDeleted == 2);
            Assert.That(CompareLists(list, modifiedList));

            list.Clear();
            modifiedList.Clear();
            Assert.That(paragraphChangedEvent.FirstChange == 0);
            Assert.That(paragraphChangedEvent.NumberAdded == 0);
            Assert.That(paragraphChangedEvent.NumberDeleted == 3);
            Assert.That(CompareLists(list, modifiedList));
        }