Пример #1
0
        public void ValueMember_HandleNotCreated()
        {
            MockItem itemA = new MockItem("A", 1);
            MockItem itemB = new MockItem("B", 2);
            MockItem itemC = new MockItem("C", 3);
            MockItem itemD = new MockItem("D", 4);
            MockItem itemE = new MockItem("E", 5);

            CheckedListBox clb = new CheckedListBox();

            clb.Items.Add(itemA, true);
            clb.Items.Add(itemC, false);
            clb.Items.Add(itemB, true);
            clb.SelectedIndex = 1;

            Assert.AreEqual(string.Empty, clb.ValueMember, "#A1");
            Assert.AreEqual(itemC.GetType().FullName, clb.Text, "#A2");
            Assert.IsNull(clb.SelectedValue, "#A3");

            clb.ValueMember = "Value";
            Assert.AreEqual("Value", clb.ValueMember, "#B1");
            Assert.AreEqual("3", clb.Text, "#B2");
            Assert.IsNull(clb.SelectedValue, "#B3");

            clb.DisplayMember = "Text";
            Assert.AreEqual("Value", clb.ValueMember, "#C1");
            Assert.AreEqual("C", clb.Text, "#C2");
            Assert.IsNull(clb.SelectedValue, "#C3");

            ArrayList itemList = new ArrayList();

            itemList.Add(itemD);
            itemList.Add(itemE);

            clb.DataSource    = itemList;
            clb.ValueMember   = string.Empty;
            clb.DisplayMember = string.Empty;
            clb.SelectedIndex = 1;

            Assert.AreEqual(string.Empty, clb.ValueMember, "#D1");
            Assert.AreEqual(itemC.GetType().FullName, clb.Text, "#D2");
            Assert.IsNull(clb.SelectedValue, "#D3");

            clb.ValueMember = "Value";
            Assert.AreEqual("Value", clb.ValueMember, "#E1");
            Assert.AreEqual("3", clb.Text, "#E2");
            Assert.IsNull(clb.SelectedValue, "#E3");

            clb.DisplayMember = "Text";
            Assert.AreEqual("Value", clb.ValueMember, "#F1");
            Assert.AreEqual("C", clb.Text, "#F2");
            Assert.IsNull(clb.SelectedValue, "#F3");
        }
Пример #2
0
        public void DisplayMember_HandleNotCreated()
        {
            MockItem itemA = new MockItem("A1", 1);
            MockItem itemB = new MockItem("B2", 2);
            MockItem itemC = new MockItem("C3", 3);
            MockItem itemD = new MockItem("D4", 4);
            MockItem itemE = new MockItem("E5", 5);
            MockItem itemF = new MockItem("F6", 6);

            CheckedListBox clb = new CheckedListBox();

            clb.Items.Add(itemA, true);
            clb.Items.Add(itemC, false);
            clb.Items.Add(itemB, true);

            Assert.AreEqual(string.Empty, clb.Text, "#A1");
            clb.SelectedIndex = 1;
            Assert.AreEqual(itemC.GetType().FullName, clb.Text, "#A2");
            clb.DisplayMember = "Text";
            Assert.AreEqual("C3", clb.Text, "#A3");
            clb.SelectedIndex = 2;
            Assert.AreEqual("B2", clb.Text, "#A4");

            clb.Text = "C3";
            Assert.AreEqual(1, clb.SelectedIndex, "#B1");
            Assert.AreEqual("C3", clb.Text, "#B2");
            clb.Text = "C";
            Assert.AreEqual(1, clb.SelectedIndex, "#B3");
            Assert.AreEqual("C3", clb.Text, "#B4");

            ArrayList itemList = new ArrayList();

            itemList.Add(itemD);
            itemList.Add(itemE);
            itemList.Add(itemF);

            clb.DataSource    = itemList;
            clb.DisplayMember = string.Empty;
            clb.SelectedIndex = 1;

            Assert.AreEqual(itemC.GetType().FullName, clb.Text, "#C1");
            clb.DisplayMember = "Text";
            Assert.AreEqual("C3", clb.Text, "#C2");
            clb.SelectedIndex = 2;
            Assert.AreEqual("B2", clb.Text, "#C3");
        }
Пример #3
0
		public void DisplayMember_HandleCreated ()
		{
			MockItem itemA = new MockItem ("A1", 1);
			MockItem itemB = new MockItem ("B2", 2);
			MockItem itemC = new MockItem ("C3", 3);
			MockItem itemD = new MockItem ("D4", 4);
			MockItem itemE = new MockItem ("E5", 5);
			MockItem itemF = new MockItem ("F6", 6);

			CheckedListBox clb = new CheckedListBox ();
			clb.Items.Add (itemA, true);
			clb.Items.Add (itemC, false);
			clb.Items.Add (itemB, true);

			Form form = new Form ();
			form.ShowInTaskbar = false;
			form.Controls.Add (clb);
			form.Show ();

			Assert.AreEqual (string.Empty, clb.Text, "#A1");
			clb.SelectedIndex = 1;
			Assert.AreEqual (itemC.GetType ().FullName, clb.Text, "#A2");
			clb.DisplayMember = "Text";
			Assert.AreEqual ("C3", clb.Text, "#A3");
			clb.SelectedIndex = 2;
			Assert.AreEqual ("B2", clb.Text, "#A4");

			clb.Text = "C3";
			Assert.AreEqual (1, clb.SelectedIndex, "#B1");
			Assert.AreEqual ("C3", clb.Text, "#B2");
			clb.Text = "B";
			Assert.AreEqual (1, clb.SelectedIndex, "#B3");
			Assert.AreEqual ("C3", clb.Text, "#B4");

			ArrayList itemList = new ArrayList ();
			itemList.Add (itemD);
			itemList.Add (itemE);
			itemList.Add (itemF);

			clb.DataSource = itemList;
			clb.DisplayMember = string.Empty;
			clb.SelectedIndex = 1;

			Assert.AreEqual (itemC.GetType ().FullName, clb.Text, "#C1");
			clb.DisplayMember = "Text";
			Assert.AreEqual ("E5", clb.Text, "#C2");
			clb.SelectedIndex = 2;
			Assert.AreEqual ("F6", clb.Text, "#C3");

			clb.Text = "E5";
			Assert.AreEqual (1, clb.SelectedIndex, "#D1");
			Assert.AreEqual ("E5", clb.Text, "#D2");
			clb.Text = "D";
			Assert.AreEqual (1, clb.SelectedIndex, "#D3");
			Assert.AreEqual ("E5", clb.Text, "#D4");

			form.Dispose ();
		}
Пример #4
0
        public void GetItemText()
        {
            MockItem itemA = new MockItem("A", 1);
            MockItem itemB = new MockItem("B", 2);
            object   itemC = new object();

            ListControlChild lc = new ListControlChild();

            lc.DisplayMember = "Text";

            // No DataSource available
            Assert.AreEqual("A", lc.GetItemText(itemA), "#A1");
            Assert.AreEqual("B", lc.GetItemText(itemB), "#A2");
            Assert.AreEqual(itemC.GetType().FullName, lc.GetItemText(itemC), "#A3");

            lc.DisplayMember = String.Empty;

            Assert.AreEqual(itemA.GetType().FullName, lc.GetItemText(itemA), "#B1");
            Assert.AreEqual(itemB.GetType().FullName, lc.GetItemText(itemB), "#B2");
            Assert.AreEqual(itemC.GetType().FullName, lc.GetItemText(itemC), "#B3");

            // DataSource available
            object [] objects = new object [] { itemA, itemB, itemC };
            lc.DisplayMember = "Text";
            lc.DataSource    = objects;

            Assert.AreEqual("A", lc.GetItemText(itemA), "#C1");
            Assert.AreEqual("B", lc.GetItemText(itemB), "#C2");
            Assert.AreEqual(itemC.GetType().FullName, lc.GetItemText(itemC), "#C3");

            lc.DisplayMember = String.Empty;

            Assert.AreEqual(itemA.GetType().FullName, lc.GetItemText(itemA), "#D1");
            Assert.AreEqual(itemB.GetType().FullName, lc.GetItemText(itemB), "#D2");
            Assert.AreEqual(itemC.GetType().FullName, lc.GetItemText(itemC), "#D3");
        }
		public void GetItemText ()
		{
			MockItem itemA = new MockItem ("A", 1);
			MockItem itemB = new MockItem ("B", 2);
			object itemC = new object ();

			ListControlChild lc = new ListControlChild ();
			lc.DisplayMember = "Text";

			// No DataSource available
			Assert.AreEqual ("A", lc.GetItemText (itemA), "#A1");
			Assert.AreEqual ("B", lc.GetItemText (itemB), "#A2");
			Assert.AreEqual (itemC.GetType ().FullName, lc.GetItemText (itemC), "#A3");

			lc.DisplayMember = String.Empty;

			Assert.AreEqual (itemA.GetType ().FullName, lc.GetItemText (itemA), "#B1");
			Assert.AreEqual (itemB.GetType ().FullName, lc.GetItemText (itemB), "#B2");
			Assert.AreEqual (itemC.GetType ().FullName, lc.GetItemText (itemC), "#B3");

			// DataSource available
			object [] objects = new object [] {itemA, itemB, itemC};
			lc.DisplayMember = "Text";
			lc.DataSource = objects;

			Assert.AreEqual ("A", lc.GetItemText (itemA), "#C1");
			Assert.AreEqual ("B", lc.GetItemText (itemB), "#C2");
			Assert.AreEqual (itemC.GetType ().FullName, lc.GetItemText (itemC), "#C3");

			lc.DisplayMember = String.Empty;

			Assert.AreEqual (itemA.GetType ().FullName, lc.GetItemText (itemA), "#D1");
			Assert.AreEqual (itemB.GetType ().FullName, lc.GetItemText (itemB), "#D2");
			Assert.AreEqual (itemC.GetType ().FullName, lc.GetItemText (itemC), "#D3");
		}
Пример #6
0
		public void ValueMember_HandleNotCreated ()
		{
			MockItem itemA = new MockItem ("A", 1);
			MockItem itemB = new MockItem ("B", 2);
			MockItem itemC = new MockItem ("C", 3);
			MockItem itemD = new MockItem ("D", 4);
			MockItem itemE = new MockItem ("E", 5);

			CheckedListBox clb = new CheckedListBox ();
			clb.Items.Add (itemA, true);
			clb.Items.Add (itemC, false);
			clb.Items.Add (itemB, true);
			clb.SelectedIndex = 1;

			Assert.AreEqual (string.Empty, clb.ValueMember, "#A1");
			Assert.AreEqual (itemC.GetType ().FullName, clb.Text, "#A2");
			Assert.IsNull (clb.SelectedValue, "#A3");

			clb.ValueMember = "Value";
			Assert.AreEqual ("Value", clb.ValueMember, "#B1");
			Assert.AreEqual ("3", clb.Text, "#B2");
			Assert.IsNull (clb.SelectedValue, "#B3");

			clb.DisplayMember = "Text";
			Assert.AreEqual ("Value", clb.ValueMember, "#C1");
			Assert.AreEqual ("C", clb.Text, "#C2");
			Assert.IsNull (clb.SelectedValue, "#C3");

			ArrayList itemList = new ArrayList ();
			itemList.Add (itemD);
			itemList.Add (itemE);

			clb.DataSource = itemList;
			clb.ValueMember = string.Empty;
			clb.DisplayMember = string.Empty;
			clb.SelectedIndex = 1;

			Assert.AreEqual (string.Empty, clb.ValueMember, "#D1");
			Assert.AreEqual (itemC.GetType ().FullName, clb.Text, "#D2");
			Assert.IsNull (clb.SelectedValue, "#D3");

			clb.ValueMember = "Value";
			Assert.AreEqual ("Value", clb.ValueMember, "#E1");
			Assert.AreEqual ("3", clb.Text, "#E2");
			Assert.IsNull (clb.SelectedValue, "#E3");

			clb.DisplayMember = "Text";
			Assert.AreEqual ("Value", clb.ValueMember, "#F1");
			Assert.AreEqual ("C", clb.Text, "#F2");
			Assert.IsNull (clb.SelectedValue, "#F3");	
		}