1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2006 Novell, Inc.
23 // Jackson Harper jackson@ximian.com
28 using System.Collections;
29 using System.Windows.Forms;
31 using NUnit.Framework;
33 namespace MonoTests.System.Windows.Forms {
36 public class BindingTest {
39 protected virtual void SetUp ()
44 protected virtual void TearDown ()
49 public void CtorTest ()
51 string prop = "PROPERTY NAME";
52 object data_source = new object ();
53 string data_member = "DATA MEMBER";
54 Binding b = new Binding (prop, data_source, data_member);
56 Assert.IsNull (b.BindingManagerBase, "ctor1");
57 Console.WriteLine ("MEMBER INFO: " + b.BindingMemberInfo);
58 Assert.IsNotNull (b.BindingMemberInfo, "ctor2");
59 Assert.IsNull (b.Control, "ctor3");
60 Assert.IsFalse (b.IsBinding, "ctor4");
62 Assert.AreSame (b.PropertyName, prop, "ctor5");
63 Assert.AreSame (b.DataSource, data_source, "ctor6");
67 public void CtorNullTest ()
69 Binding b = new Binding (null, null, null);
71 Assert.IsNull (b.PropertyName, "ctornull1");
72 Assert.IsNull (b.DataSource, "ctornull2");
76 /* create control and set binding context */
77 public void BindingContextChangedTest ()
79 Control c = new Control ();
80 // Test BindingContextChanged Event
81 c.BindingContextChanged += new EventHandler (Event_Handler1);
82 BindingContext bcG1 = new BindingContext ();
84 c.BindingContext = bcG1;
85 Assert.AreEqual (1, eventcount, "A1");
89 [Category ("NotWorking")]
90 /* create control and show control */
91 public void BindingContextChangedTest2 ()
94 f.ShowInTaskbar = false;
95 Control c = new Control ();
98 c.BindingContextChanged += new EventHandler (Event_Handler1);
101 Assert.AreEqual (2, eventcount, "A1");
106 /* create control, set binding context, and show control */
107 public void BindingContextChangedTest3 ()
109 Form f = new Form ();
110 f.ShowInTaskbar = false;
112 Control c = new Control ();
115 c.BindingContextChanged += new EventHandler (Event_Handler1);
117 c.BindingContext = new BindingContext ();;
119 Assert.AreEqual (1, eventcount, "A1");
124 public void Event_Handler1 (object sender, EventArgs e)
126 Console.WriteLine (Environment.StackTrace);
131 public void DataBindingCountTest1 ()
133 Control c = new Control ();
134 Assert.AreEqual (0, c.DataBindings.Count, "1");
135 c.DataBindings.Add (new Binding ("Text", c, "Name"));
136 Assert.AreEqual (1, c.DataBindings.Count, "2");
138 Binding b = c.DataBindings[0];
139 Assert.AreEqual (c, b.Control, "3");
140 Assert.AreEqual (c, b.DataSource, "4");
141 Assert.AreEqual ("Text", b.PropertyName, "5");
142 Assert.AreEqual ("Name", b.BindingMemberInfo.BindingField, "6");
146 public void DataBindingCountTest2 ()
148 Control c = new Control ();
149 Control c2 = new Control ();
150 Assert.AreEqual (0, c.DataBindings.Count, "1");
151 c.DataBindings.Add (new Binding ("Text", c2, "Name"));
152 Assert.AreEqual (1, c.DataBindings.Count, "2");
153 Assert.AreEqual (0, c2.DataBindings.Count, "3");
155 Binding b = c.DataBindings[0];
156 Assert.AreEqual (c, b.Control, "4");
157 Assert.AreEqual (c2, b.DataSource, "5");
158 Assert.AreEqual ("Text", b.PropertyName, "6");
159 Assert.AreEqual ("Name", b.BindingMemberInfo.BindingField, "7");