Exemplo n.º 1
0
        public void Insert_Owned()
        {
            ToolStrip toolStrip           = CreateToolStrip();
            ToolStripItemCollection items = toolStrip.Items;

            MockToolStripButton buttonA = new MockToolStripButton("A");

            items.Insert(0, buttonA);
            Assert.AreEqual(1, items.Count, "#A1");
            Assert.AreEqual(1, itemsAdded.Count, "#A2");
            Assert.AreSame(buttonA, items [0], "#A3");
            Assert.AreSame(toolStrip, buttonA.Owner, "#A4");
            Assert.IsNull(buttonA.ParentToolStrip, "#A5");

            MockToolStripButton buttonB = new MockToolStripButton("B");

            items.Insert(0, buttonB);
            Assert.AreEqual(2, items.Count, "#B1");
            Assert.AreEqual(2, itemsAdded.Count, "#B2");
            Assert.AreSame(buttonB, items [0], "#B3");
            Assert.AreSame(buttonA, items [1], "#B4");
            Assert.AreSame(toolStrip, buttonB.Owner, "#B5");
            Assert.IsNull(buttonB.ParentToolStrip, "#B6");

            MockToolStripButton buttonC = new MockToolStripButton("C");

            items.Insert(1, buttonC);
            Assert.AreEqual(3, items.Count, "#C1");
            Assert.AreEqual(3, itemsAdded.Count, "#C2");
            Assert.AreSame(buttonB, items [0], "#C3");
            Assert.AreSame(buttonC, items [1], "#C4");
            Assert.AreSame(buttonA, items [2], "#C5");
            Assert.AreSame(toolStrip, buttonC.Owner, "#C6");
            Assert.IsNull(buttonC.ParentToolStrip, "#C7");
        }
Exemplo n.º 2
0
        public void Remove_StandAlone()
        {
            ToolStrip toolStrip           = CreateToolStrip();
            ToolStripItemCollection items = new ToolStripItemCollection(
                toolStrip, new ToolStripItem [0]);

            MockToolStripButton buttonA = new MockToolStripButton("A");
            MockToolStripButton buttonB = new MockToolStripButton("B");
            MockToolStripButton buttonC = new MockToolStripButton("B");

            items.Insert(0, buttonA);
            items.Insert(0, buttonB);

            items.Remove(buttonB);
            Assert.AreEqual(1, items.Count, "#A1");
            Assert.AreEqual(0, itemsRemoved.Count, "#A2");
            Assert.AreSame(buttonA, items [0], "#A3");

            items.Remove((ToolStripItem)null);
            Assert.AreEqual(1, items.Count, "#B1");
            Assert.AreEqual(0, itemsRemoved.Count, "#B2");
            Assert.AreSame(buttonA, items [0], "#B3");

            items.Remove(buttonC);
            Assert.AreEqual(1, items.Count, "#C1");
            Assert.AreEqual(0, itemsRemoved.Count, "#C2");
            Assert.AreSame(buttonA, items [0], "#C3");

            items.Remove(buttonA);
            Assert.AreEqual(0, items.Count, "#D1");
            Assert.AreEqual(0, itemsRemoved.Count, "#D2");

            items.Remove(buttonA);
            Assert.AreEqual(0, items.Count, "#E1");
            Assert.AreEqual(0, itemsRemoved.Count, "#E2");

            // remove item owned by other toolstrip
            ToolStrip           otherToolStrip = new ToolStrip();
            MockToolStripButton buttonD        = new MockToolStripButton("B");

            otherToolStrip.Items.Add(buttonD);
            Assert.AreSame(otherToolStrip, buttonD.Owner, "#F1");
            Assert.IsNull(buttonD.ParentToolStrip, "#F2");
            items.Remove(buttonD);
            Assert.AreEqual(0, items.Count, "#F3");
            Assert.AreEqual(0, itemsRemoved.Count, "#F4");
            Assert.AreSame(otherToolStrip, buttonD.Owner, "#F5");
            Assert.IsNull(buttonD.ParentToolStrip, "#F6");
        }
        public void Constructor()
        {
            ToolStrip toolStrip           = CreateToolStrip();
            ToolStripItemCollection items = null;

            items = new ToolStripItemCollection(toolStrip, new ToolStripItem [0]);
            Assert.AreEqual(0, items.Count, "#A1");
            Assert.IsFalse(items.IsReadOnly, "#A2");
            Assert.AreEqual(0, itemsAdded.Count, "#A3");

            MockToolStripButton buttonA = new MockToolStripButton("A");
            MockToolStripButton buttonB = new MockToolStripButton("B");

            items = new ToolStripItemCollection(toolStrip, new ToolStripItem []
            {
                buttonA, buttonB
            });
            Assert.AreEqual(2, items.Count, "#B1");
            Assert.IsFalse(items.IsReadOnly, "#B2");
            Assert.AreEqual(0, itemsAdded.Count, "#B3");
            Assert.AreSame(buttonA, items [0], "#B4");
            Assert.AreSame(buttonB, items [1], "#B5");
            Assert.IsNull(buttonA.Owner, "#B6");
            Assert.IsNull(buttonA.ParentToolStrip, "#B7");
            Assert.IsNull(buttonB.Owner, "#B8");
            Assert.IsNull(buttonB.ParentToolStrip, "#B9");

            // null item
            try
            {
                new ToolStripItemCollection(toolStrip, new ToolStripItem []
                {
                    buttonA, null, buttonB
                });
                Assert.Fail("#C1");
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual(typeof(ArgumentNullException), ex.GetType(), "#C2");
                Assert.IsNull(ex.InnerException, "#C3");
                Assert.IsNotNull(ex.Message, "#C4");
                Assert.AreEqual("value", ex.ParamName, "#C5");
            }
        }
		public void Constructor ()
		{
			ToolStrip toolStrip = CreateToolStrip ();
			ToolStripItemCollection items = null;

			items = new ToolStripItemCollection (toolStrip, new ToolStripItem [0]);
			Assert.AreEqual (0, items.Count, "#A1");
			Assert.IsFalse (items.IsReadOnly, "#A2");
			Assert.AreEqual (0, itemsAdded.Count, "#A3");

			MockToolStripButton buttonA = new MockToolStripButton ("A");
			MockToolStripButton buttonB = new MockToolStripButton ("B");
			items = new ToolStripItemCollection (toolStrip, new ToolStripItem [] {
				buttonA, buttonB });
			Assert.AreEqual (2, items.Count, "#B1");
			Assert.IsFalse (items.IsReadOnly, "#B2");
			Assert.AreEqual (0, itemsAdded.Count, "#B3");
			Assert.AreSame (buttonA, items [0], "#B4");
			Assert.AreSame (buttonB, items [1], "#B5");
			Assert.IsNull (buttonA.Owner, "#B6");
			Assert.IsNull (buttonA.ParentToolStrip, "#B7");
			Assert.IsNull (buttonB.Owner, "#B8");
			Assert.IsNull (buttonB.ParentToolStrip, "#B9");

			// null item
			try {
				new ToolStripItemCollection (toolStrip, new ToolStripItem [] {
					buttonA, null, buttonB });
				Assert.Fail ("#C1");
			} catch (ArgumentNullException ex) {
				Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#C2");
				Assert.IsNull (ex.InnerException, "#C3");
				Assert.IsNotNull (ex.Message, "#C4");
				Assert.AreEqual ("value", ex.ParamName, "#C5");
			}
		}
Exemplo n.º 5
0
        public void Remove_Owned()
        {
            ToolStrip toolStrip           = CreateToolStrip();
            ToolStripItemCollection items = toolStrip.Items;

            MockToolStripButton buttonA = new MockToolStripButton("A");
            MockToolStripButton buttonB = new MockToolStripButton("B");
            MockToolStripButton buttonC = new MockToolStripButton("B");

            items.Insert(0, buttonA);
            items.Insert(0, buttonB);

            items.Remove(buttonB);
            Assert.AreEqual(1, items.Count, "#A1");
            Assert.AreEqual(1, itemsRemoved.Count, "#A2");
            Assert.AreSame(buttonA, items [0], "#A3");
            Assert.AreSame(buttonB, itemsRemoved [0], "#A4");
            Assert.IsNull(buttonB.Owner, "#A5");
            Assert.IsNull(buttonB.ParentToolStrip, "#A6");

            // remove null item
            items.Remove((ToolStripItem)null);
            Assert.AreEqual(1, items.Count, "#B1");
            Assert.AreEqual(2, itemsRemoved.Count, "#B2");
            Assert.AreSame(buttonA, items [0], "#B3");
            Assert.IsNull(itemsRemoved [1], "#B4");

            // remove item not owner by toolstrip
            items.Remove(buttonC);
            Assert.AreEqual(1, items.Count, "#C1");
            Assert.AreEqual(3, itemsRemoved.Count, "#C2");
            Assert.AreSame(buttonA, items [0], "#C3");
            Assert.AreSame(buttonC, itemsRemoved [2], "#C4");
            Assert.IsNull(buttonC.Owner, "#C5");
            Assert.IsNull(buttonC.ParentToolStrip, "#C6");

            items.Remove(buttonA);
            Assert.AreEqual(0, items.Count, "#D1");
            Assert.AreEqual(4, itemsRemoved.Count, "#D2");
            Assert.AreSame(buttonA, itemsRemoved [3], "#D3");
            Assert.IsNull(buttonC.Owner, "#D4");
            Assert.IsNull(buttonC.ParentToolStrip, "#D5");

            // remove item which is no longer in the collection
            items.Remove(buttonA);
            Assert.AreEqual(0, items.Count, "#E1");
            Assert.AreEqual(5, itemsRemoved.Count, "#E2");
            Assert.AreSame(buttonA, itemsRemoved [4], "#E3");

            // remove item owned by other toolstrip
            ToolStrip           otherToolStrip = new ToolStrip();
            MockToolStripButton buttonD        = new MockToolStripButton("B");

            otherToolStrip.Items.Add(buttonD);
            Assert.AreSame(otherToolStrip, buttonD.Owner, "#F1");
            Assert.IsNull(buttonD.ParentToolStrip, "#F2");
            items.Remove(buttonD);
            Assert.AreEqual(0, items.Count, "#F3");
            Assert.AreEqual(6, itemsRemoved.Count, "#F4");
            Assert.IsNull(buttonD.Owner, "#F5");
            Assert.IsNull(buttonD.ParentToolStrip, "#F6");
        }
		public void Remove_StandAlone ()
		{
			ToolStrip toolStrip = CreateToolStrip ();
			ToolStripItemCollection items = new ToolStripItemCollection (
				toolStrip, new ToolStripItem [0]);

			MockToolStripButton buttonA = new MockToolStripButton ("A");
			MockToolStripButton buttonB = new MockToolStripButton ("B");
			MockToolStripButton buttonC = new MockToolStripButton ("B");
			items.Insert (0, buttonA);
			items.Insert (0, buttonB);

			items.Remove (buttonB);
			Assert.AreEqual (1, items.Count, "#A1");
			Assert.AreEqual (0, itemsRemoved.Count, "#A2");
			Assert.AreSame (buttonA, items [0], "#A3");

			items.Remove ((ToolStripItem) null);
			Assert.AreEqual (1, items.Count, "#B1");
			Assert.AreEqual (0, itemsRemoved.Count, "#B2");
			Assert.AreSame (buttonA, items [0], "#B3");

			items.Remove (buttonC);
			Assert.AreEqual (1, items.Count, "#C1");
			Assert.AreEqual (0, itemsRemoved.Count, "#C2");
			Assert.AreSame (buttonA, items [0], "#C3");

			items.Remove (buttonA);
			Assert.AreEqual (0, items.Count, "#D1");
			Assert.AreEqual (0, itemsRemoved.Count, "#D2");

			items.Remove (buttonA);
			Assert.AreEqual (0, items.Count, "#E1");
			Assert.AreEqual (0, itemsRemoved.Count, "#E2");

			// remove item owned by other toolstrip
			ToolStrip otherToolStrip = new ToolStrip ();
			MockToolStripButton buttonD = new MockToolStripButton ("B");
			otherToolStrip.Items.Add (buttonD);
			Assert.AreSame (otherToolStrip, buttonD.Owner, "#F1");
			Assert.IsNull (buttonD.ParentToolStrip, "#F2");
			items.Remove (buttonD);
			Assert.AreEqual (0, items.Count, "#F3");
			Assert.AreEqual (0, itemsRemoved.Count, "#F4");
			Assert.AreSame (otherToolStrip, buttonD.Owner, "#F5");
			Assert.IsNull (buttonD.ParentToolStrip, "#F6");
		}
		public void Remove_Owned ()
		{
			ToolStrip toolStrip = CreateToolStrip ();
			ToolStripItemCollection items = toolStrip.Items;

			MockToolStripButton buttonA = new MockToolStripButton ("A");
			MockToolStripButton buttonB = new MockToolStripButton ("B");
			MockToolStripButton buttonC = new MockToolStripButton ("B");
			items.Insert (0, buttonA);
			items.Insert (0, buttonB);

			items.Remove (buttonB);
			Assert.AreEqual (1, items.Count, "#A1");
			Assert.AreEqual (1, itemsRemoved.Count, "#A2");
			Assert.AreSame (buttonA, items [0], "#A3");
			Assert.AreSame (buttonB, itemsRemoved [0], "#A4");
			Assert.IsNull (buttonB.Owner, "#A5");
			Assert.IsNull (buttonB.ParentToolStrip, "#A6");

			// remove null item
			items.Remove ((ToolStripItem) null);
			Assert.AreEqual (1, items.Count, "#B1");
			Assert.AreEqual (2, itemsRemoved.Count, "#B2");
			Assert.AreSame (buttonA, items [0], "#B3");
			Assert.IsNull (itemsRemoved [1], "#B4");

			// remove item not owner by toolstrip
			items.Remove (buttonC);
			Assert.AreEqual (1, items.Count, "#C1");
			Assert.AreEqual (3, itemsRemoved.Count, "#C2");
			Assert.AreSame (buttonA, items [0], "#C3");
			Assert.AreSame(buttonC, itemsRemoved [2], "#C4");
			Assert.IsNull (buttonC.Owner, "#C5");
			Assert.IsNull (buttonC.ParentToolStrip, "#C6");

			items.Remove (buttonA);
			Assert.AreEqual (0, items.Count, "#D1");
			Assert.AreEqual (4, itemsRemoved.Count, "#D2");
			Assert.AreSame(buttonA, itemsRemoved [3], "#D3");
			Assert.IsNull (buttonC.Owner, "#D4");
			Assert.IsNull (buttonC.ParentToolStrip, "#D5");

			// remove item which is no longer in the collection
			items.Remove (buttonA);
			Assert.AreEqual (0, items.Count, "#E1");
			Assert.AreEqual (5, itemsRemoved.Count, "#E2");
			Assert.AreSame(buttonA, itemsRemoved [4], "#E3");

			// remove item owned by other toolstrip
			ToolStrip otherToolStrip = new ToolStrip ();
			MockToolStripButton buttonD = new MockToolStripButton ("B");
			otherToolStrip.Items.Add (buttonD);
			Assert.AreSame (otherToolStrip, buttonD.Owner, "#F1");
			Assert.IsNull (buttonD.ParentToolStrip, "#F2");
			items.Remove (buttonD);
			Assert.AreEqual (0, items.Count, "#F3");
			Assert.AreEqual (6, itemsRemoved.Count, "#F4");
			Assert.IsNull (buttonD.Owner, "#F5");
			Assert.IsNull (buttonD.ParentToolStrip, "#F6");
		}
		public void Insert_StandAlone ()
		{
			ToolStrip toolStrip = CreateToolStrip ();
			ToolStripItemCollection items = new ToolStripItemCollection (
				toolStrip, new ToolStripItem [0]);

			MockToolStripButton buttonA = new MockToolStripButton ("A");
			items.Insert (0, buttonA);
			Assert.AreEqual (1, items.Count, "#A1");
			Assert.AreEqual (0, itemsAdded.Count, "#A2");
			Assert.AreSame (buttonA, items [0], "#A3");
			Assert.IsNull (buttonA.Owner, "#A4");
			Assert.IsNull (buttonA.ParentToolStrip, "#A5");

			MockToolStripButton buttonB = new MockToolStripButton ("B");
			items.Insert (0, buttonB);
			Assert.AreEqual (2, items.Count, "#B1");
			Assert.AreEqual (0, itemsAdded.Count, "#B2");
			Assert.AreSame (buttonB, items [0], "#B3");
			Assert.AreSame (buttonA, items [1], "#B4");
			Assert.IsNull (buttonB.Owner, "#B5");
			Assert.IsNull (buttonB.ParentToolStrip, "#B6");

			MockToolStripButton buttonC = new MockToolStripButton ("C");
			items.Insert (1, buttonC);
			Assert.AreEqual (3, items.Count, "#C1");
			Assert.AreEqual (0, itemsAdded.Count, "#C2");
			Assert.AreSame (buttonB, items [0], "#C3");
			Assert.AreSame (buttonC, items [1], "#C4");
			Assert.AreSame (buttonA, items [2], "#C5");
			Assert.IsNull (buttonC.Owner, "#C6");
			Assert.IsNull (buttonC.ParentToolStrip, "#C7");
		}