public void AddRemoveTest() { StatusBar bar = new StatusBar(); StatusBar.StatusBarPanelCollection collection = new StatusBar.StatusBarPanelCollection(bar); StatusBarPanel panel = new StatusBarPanel(); StatusBarPanel panel2 = new StatusBarPanel(); collection.Add(panel); Assert.AreEqual(1, collection.Count, "#1"); collection.Remove(panel); Assert.AreEqual(0, collection.Count, "#2"); collection.Add(panel); collection.RemoveAt(0); Assert.AreEqual(0, collection.Count, "#3"); collection.Add(panel); Assert.AreEqual(0, collection.IndexOf(panel), "#4"); Assert.AreEqual(-1, collection.IndexOf(panel2), "#5"); collection.Add(panel2); Assert.AreEqual(1, collection.IndexOf(panel2), "#6"); collection.RemoveAt(0); Assert.AreEqual(0, collection.IndexOf(panel2), "#7"); Assert.AreEqual(1, collection.Count, "#8"); Assert.AreEqual(false, collection.Contains(panel), "#9"); Assert.AreEqual(true, collection.Contains(panel2), "#10"); }
public void Insert() { StatusBar bar = new StatusBar(); StatusBar.StatusBarPanelCollection collection = new StatusBar.StatusBarPanelCollection(bar); StatusBarPanel panel = new StatusBarPanel(); StatusBarPanel panel2 = new StatusBarPanel(); collection.Add(panel); Assert.AreEqual(1, collection.Count, "#1"); collection.Insert(0, panel); Assert.AreEqual(2, collection.Count, "#2"); }
// Test the constructors public void TestPanelCollections() { StatusBar bar = new StatusBar(); StatusBar.StatusBarPanelCollection panels = bar.Panels; StatusBarPanel p1 = new StatusBarPanel(); StatusBarPanel p2 = new StatusBarPanel(); StatusBarPanel p3 = new StatusBarPanel(); StatusBarPanel p4 = new StatusBarPanel(); AssertEquals("Count (1)", 0, panels.Count); panels.Add(p2); AssertEquals("Count (2)", 1, panels.Count); panels[0] = p2; AssertEquals("Count (3)", 1, panels.Count); AssertEquals("Indexer (1)", p2, panels[0]); panels[0] = p1; AssertEquals("Count (4)", 1, panels.Count); AssertEquals("Indexer (2)", p1, panels[0]); panels.AddRange(new StatusBarPanel[] { p2, p3 }); AssertEquals("Count (5)", 3, panels.Count); AssertEquals("Indexer (3)", p1, panels[0]); AssertEquals("Indexer (4)", p2, panels[1]); AssertEquals("Indexer (5)", p3, panels[2]); AssertEquals("Contains (1)", true, panels.Contains(p1)); AssertEquals("Contains (2)", true, panels.Contains(p2)); AssertEquals("Contains (3)", true, panels.Contains(p3)); AssertEquals("Contains (4)", false, panels.Contains(p4)); AssertEquals("IndexOf (1)", 0, panels.IndexOf(p1)); AssertEquals("IndexOf (2)", 1, panels.IndexOf(p2)); AssertEquals("IndexOf (3)", -1, panels.IndexOf(p4)); panels.Insert(0, p4); AssertEquals("IndexOf (4)", 1, panels.IndexOf(p1)); AssertEquals("IndexOf (5)", 2, panels.IndexOf(p2)); AssertEquals("IndexOf (6)", 0, panels.IndexOf(p4)); panels.Remove(p4); AssertEquals("Count (6)", 3, panels.Count); AssertEquals("IndexOf (7)", 0, panels.IndexOf(p1)); AssertEquals("IndexOf (8)", 1, panels.IndexOf(p2)); AssertEquals("IndexOf (9)", -1, panels.IndexOf(p4)); try { panels.Add(p1); Fail("Add (1)"); } catch (ArgumentException) { // Success - already in collection } try { StatusBarPanel nullPanel = null; panels.Add(nullPanel); Fail("Add (2)"); } catch (ArgumentNullException) { // Success - null argument } try { panels.AddRange(new StatusBarPanel[] { p1, p2 }); Fail("AddRange (1)"); } catch (ArgumentException) { // Success - already in collection } try { panels[1] = p1; Fail("Indexer (6)"); } catch (ArgumentException) { // Success- already in collection } panels.Clear(); AssertEquals("Count (7)", 0, panels.Count); }