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 // Chris Toshok toshok@ximian.com
28 using System.Collections;
29 using System.Windows.Forms;
31 using NUnit.Framework;
33 namespace MonoTests.System.Windows.Forms.DataBinding
36 public class PropertyManagerTest : TestHelper {
49 if (PropertyChanged != null)
50 PropertyChanged (this, EventArgs.Empty);
54 public event EventHandler PropertyChanged;
82 Changed (this, EventArgs.Empty);
86 public event EventHandler Changed;
89 bool currentChangedRaised;
90 bool positionChangedRaised;
92 void OnCurrentChanged (object sender, EventArgs args)
94 currentChangedRaised = true;
97 //void OnPositionChanged (object sender, EventArgs args)
99 // positionChangedRaised = true;
103 public void TestEvent ()
105 TestClass1 test = new TestClass1();
106 BindingContext bc = new BindingContext ();
108 BindingManagerBase bm = bc[test, "Property"];
109 Assert.IsTrue (typeof (PropertyManager).IsAssignableFrom (bm.GetType()), "A1");
111 bm.CurrentChanged += new EventHandler (OnCurrentChanged);
113 currentChangedRaised = positionChangedRaised = false;
115 Assert.IsTrue (currentChangedRaised, "A2");
116 Assert.IsFalse (positionChangedRaised, "A3");
120 public void TestNoEvent ()
122 TestClass2 test = new TestClass2();
123 BindingContext bc = new BindingContext ();
125 BindingManagerBase bm = bc[test, "Property"];
126 Assert.IsTrue (typeof (PropertyManager).IsAssignableFrom (bm.GetType()), "A1");
128 bm.CurrentChanged += new EventHandler (OnCurrentChanged);
130 currentChangedRaised = positionChangedRaised = false;
132 Assert.IsFalse (currentChangedRaised, "A2");
133 Assert.IsFalse (positionChangedRaised, "A3");
137 public void TestMemberEvent ()
139 TestClass1 test = new TestClass1();
140 BindingContext bc = new BindingContext ();
142 BindingManagerBase bm = bc[test];
143 Assert.IsTrue (typeof (PropertyManager).IsAssignableFrom (bm.GetType()), "A1");
145 bm.CurrentChanged += new EventHandler (OnCurrentChanged);
147 currentChangedRaised = positionChangedRaised = false;
149 Assert.IsFalse (currentChangedRaised, "A2");
150 Assert.IsFalse (positionChangedRaised, "A3");
154 public void TestMemberEvent2 ()
156 TestClass3 test = new TestClass3();
157 BindingContext bc = new BindingContext ();
159 BindingManagerBase bm = bc[test];
160 Assert.IsTrue (typeof (PropertyManager).IsAssignableFrom (bm.GetType()), "A1");
162 bm.CurrentChanged += new EventHandler (OnCurrentChanged);
164 currentChangedRaised = positionChangedRaised = false;
166 Assert.IsFalse (currentChangedRaised, "A2");
167 Assert.IsFalse (positionChangedRaised, "A3");
171 public void TestMemberNoEvent ()
173 TestClass2 test = new TestClass2();
174 BindingContext bc = new BindingContext ();
176 BindingManagerBase bm = bc[test];
177 Assert.IsTrue (typeof (PropertyManager).IsAssignableFrom (bm.GetType()), "A1");
179 bm.CurrentChanged += new EventHandler (OnCurrentChanged);
181 currentChangedRaised = positionChangedRaised = false;
183 Assert.IsFalse (currentChangedRaised, "A2");
184 Assert.IsFalse (positionChangedRaised, "A3");