Author: calberto
Date: 2008-02-08 15:17:45 -0500 (Fri, 08 Feb 2008)
New Revision: 95299

Modified:
   
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/BindingTest.cs
   trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
   
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ListControlTest.cs
Log:
2008_02-08  Carlos Alberto Cortez <[EMAIL PROTECTED]>

        * ListControl.cs: Add setter and events for MockItem members -
        we need them to test data binding.
        * BindingTest.cs: Add tests for 2.0 members (ControlUpdateMode,
        DataSourceUpdateMode, ReadValue), and for IsBinding property.
        Mark as NotWorking IsBindingTest and DataSourceUpdateMode as they are
        failing by now.



Modified: 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/BindingTest.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/BindingTest.cs  
    2008-02-08 20:14:59 UTC (rev 95298)
+++ 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/BindingTest.cs  
    2008-02-08 20:17:45 UTC (rev 95299)
@@ -235,6 +235,121 @@
 
                        Assert.AreEqual (DBNull.Value, c.Tag, "1");
                }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void IsBindingTest ()
+               {
+                       MockItem [] items = new MockItem [] { new MockItem 
("A", 0) };
+                       Binding binding = new Binding ("Text", items, "Text");
+                       Binding binding2 = new Binding ("Text", items [0], 
"Text");
+                       Assert.IsFalse (binding.IsBinding, "#A1");
+                       Assert.IsFalse (binding2.IsBinding, "#A2");
+
+                       Control c = new Control ();
+                       Control c2 = new Control ();
+                       c.DataBindings.Add (binding);
+                       c2.DataBindings.Add (binding2);
+                       Assert.IsFalse (binding.IsBinding, "#B1");
+                       Assert.IsFalse (binding2.IsBinding, "#B2");
+
+                       c.CreateControl ();
+                       c2.CreateControl ();
+                       Assert.IsFalse (binding.IsBinding, "#C1");
+                       Assert.IsFalse (binding2.IsBinding, "#C2");
+
+                       Form form = new Form ();
+                       form.ShowInTaskbar = false;
+                       form.Controls.Add (c);
+                       form.Controls.Add (c2);
+                       Assert.IsTrue (binding.IsBinding, "#D1");
+                       Assert.IsTrue (binding2.IsBinding, "#D2");
+
+                       form.Show ();
+
+                       // Important part -
+                       // IsBinding is true ALWAYS with PropertyManager, even 
when
+                       // ResumeBinding has been called
+                       //
+                       CurrencyManager curr_manager = 
(CurrencyManager)form.BindingContext [items];
+                       PropertyManager prop_manager = 
(PropertyManager)form.BindingContext [items [0]];
+                       curr_manager.SuspendBinding ();
+                       prop_manager.SuspendBinding ();
+                       //Assert.IsFalse (binding.IsBinding, "#E1"); // Comment 
by now
+                       Assert.IsTrue (binding2.IsBinding, "#E2");
+
+                       curr_manager.ResumeBinding ();
+                       prop_manager.ResumeBinding ();
+                       Assert.IsTrue (binding.IsBinding, "#F1");
+                       Assert.IsTrue (binding2.IsBinding, "#F2");
+
+                       form.Dispose ();
+               }
+
+#if NET_2_0
+               [Test]
+               public void ReadValueTest ()
+               {
+                       Control c = new Control ();
+                       c.BindingContext = new BindingContext ();
+                       c.CreateControl ();
+
+                       ChildMockItem item = new ChildMockItem ();
+                       item.ObjectValue = "A";
+                       Binding binding = new Binding ("Tag", item, 
"ObjectValue");
+                       binding.ControlUpdateMode = ControlUpdateMode.Never;
+
+                       c.DataBindings.Add (binding);
+                       Assert.AreEqual (null, c.Tag, "#A1");
+
+                       item.ObjectValue = "B";
+                       Assert.AreEqual (null, c.Tag, "#B1");
+
+                       binding.ReadValue ();
+                       Assert.AreEqual ("B", c.Tag, "#C1");
+
+                       item.ObjectValue = "C";
+                       binding.ReadValue ();
+                       Assert.AreEqual ("C", c.Tag, "#D1");
+               }
+
+               [Test]
+               public void ControlUpdateModeTest ()
+               {
+                       Control c = new Control ();
+                       c.BindingContext = new BindingContext ();
+                       c.CreateControl ();
+
+                       MockItem item = new MockItem ("A", 0);
+                       Binding binding = new Binding ("Text", item, "Text");
+                       binding.ControlUpdateMode = ControlUpdateMode.Never;
+
+                       c.DataBindings.Add (binding);
+                       Assert.AreEqual (String.Empty, c.Text, "#A1");
+
+                       item.Text = "B";
+                       Assert.AreEqual (String.Empty, c.Text, "#B1");
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void DataSourceUpdateModeTest ()
+               {
+                       Control c = new Control ();
+                       c.BindingContext = new BindingContext ();
+                       c.CreateControl ();
+
+                       MockItem item = new MockItem ("A", 0);
+                       Binding binding = new Binding ("Text", item, "Text");
+                       binding.DataSourceUpdateMode = 
DataSourceUpdateMode.Never;
+
+                       c.DataBindings.Add (binding);
+                       Assert.AreEqual ("A", c.Text, "#A1");
+
+                       c.Text = "B";
+                       Assert.AreEqual ("A", item.Text, "#B1");
+               }
+#endif
        }
 
        class ChildMockItem : MockItem

Modified: 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog   
2008-02-08 20:14:59 UTC (rev 95298)
+++ trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ChangeLog   
2008-02-08 20:17:45 UTC (rev 95299)
@@ -1,3 +1,12 @@
+2008_02-08  Carlos Alberto Cortez <[EMAIL PROTECTED]>
+
+       * ListControl.cs: Add setter and events for MockItem members -
+       we need them to test data binding.
+       * BindingTest.cs: Add tests for 2.0 members (ControlUpdateMode,
+       DataSourceUpdateMode, ReadValue), and for IsBinding property.
+       Mark as NotWorking IsBindingTest and DataSourceUpdateMode as they are
+       failing by now.
+
 2008-02-08  Jonathan Pobst  <[EMAIL PROTECTED]>
 
        * FormTest.cs: Commit tests from James Purcell for his new

Modified: 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ListControlTest.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ListControlTest.cs
  2008-02-08 20:14:59 UTC (rev 95298)
+++ 
trunk/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/ListControlTest.cs
  2008-02-08 20:17:45 UTC (rev 95299)
@@ -468,17 +468,48 @@
 
                public MockItem ()
                {
+                       _text = String.Empty;
+                       _value = -1;
                }
 
                public string Text {
                        get { return _text; }
+                       set {
+                               if (_text == value)
+                                       return;
+
+                               _text = value;
+                               OnTextChanged (EventArgs.Empty);
+                       }
                }
 
                public int Value {
                        get { return _value; }
+                       set {
+                               if (_value == value)
+                                       return;
+
+                               _value = value;
+                               OnValueChanged (EventArgs.Empty);
+                       }
                }
 
-               private readonly string _text;
-               private readonly int _value;
+               protected virtual void OnTextChanged (EventArgs args)
+               {
+                       if (TextChanged != null)
+                               TextChanged (this, args);
+               }
+
+               protected virtual void OnValueChanged (EventArgs args)
+               {
+                       if (ValueChanged != null)
+                               ValueChanged (this, args);
+               }
+
+               public event EventHandler TextChanged;
+               public event EventHandler ValueChanged;
+
+               private string _text;
+               private int _value;
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to