2008-11-24 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / BindingTest.cs
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:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
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.
19 //
20 // Copyright (c) 2006 Novell, Inc.
21 //
22 // Authors:
23 //      Jackson Harper  jackson@ximian.com
24
25
26 using System;
27 using System.Data;
28 using System.Collections;
29 using System.Globalization;
30 using System.Windows.Forms;
31
32 using NUnit.Framework;
33
34 namespace MonoTests.System.Windows.Forms.DataBinding {
35
36         [TestFixture]
37         public class BindingTest : TestHelper {
38                 
39                 [Test]
40                 public void CtorTest ()
41                 {
42                         string prop = "PROPERTY NAME";
43                         object data_source = new object ();
44                         string data_member = "DATA MEMBER";
45                         Binding b = new Binding (prop, data_source, data_member);
46
47                         Assert.IsNull (b.BindingManagerBase, "ctor1");
48                         Console.WriteLine ("MEMBER INFO:  " + b.BindingMemberInfo);
49                         Assert.IsNotNull (b.BindingMemberInfo, "ctor2");
50                         Assert.IsNull (b.Control, "ctor3");
51                         Assert.IsFalse (b.IsBinding, "ctor4");
52
53                         Assert.AreSame (b.PropertyName, prop, "ctor5");
54                         Assert.AreSame (b.DataSource, data_source, "ctor6");
55
56 #if NET_2_0
57                         Assert.AreEqual (false, b.FormattingEnabled, "ctor7");
58                         Assert.AreEqual (String.Empty, b.FormatString, "ctor8");
59                         Assert.IsNull (b.FormatInfo, "ctor9");
60                         Assert.IsNull (b.NullValue, "ctor10");
61                         Assert.AreEqual (Convert.DBNull, b.DataSourceNullValue, "ctor11");
62 #endif
63                 }
64
65                 [Test]
66                 public void CtorNullTest ()
67                 {
68                         Binding b = new Binding (null, null, null);
69
70                         Assert.IsNull (b.PropertyName, "ctornull1");
71                         Assert.IsNull (b.DataSource, "ctornull2");
72                 }
73
74                 [Test]
75                 public void CtorEmptyProperty ()
76                 {
77                         Binding b = new Binding ("Text", 6, String.Empty);
78                         Control c = new Control ();
79                         c.BindingContext = new BindingContext ();
80                         c.CreateControl ();
81
82                         c.DataBindings.Add (b);
83                         Assert.AreEqual ("6", c.Text, "A1");
84                 }
85
86                 [Test]
87                 public void BindingManagerBaseTest ()
88                 {
89                         if (TestHelper.RunningOnUnix) {
90                                 Assert.Ignore ("Fails at the moment");
91                         }
92
93                         Control c1 = new Control ();
94                         Control c2 = new Control ();
95                         Binding binding;
96
97                         c1.BindingContext = new BindingContext ();
98                         c2.BindingContext = c1.BindingContext;
99
100                         binding = c2.DataBindings.Add ("Text", c1, "Text");
101
102                         Assert.IsNull (binding.BindingManagerBase, "1");
103
104                         c1.CreateControl ();
105                         c2.CreateControl ();
106
107                         Assert.IsNull (binding.BindingManagerBase, "2");
108
109                         c2.DataBindings.Remove (binding);
110                         binding = c2.DataBindings.Add ("Text", c1, "Text");
111
112                         Assert.IsTrue (binding.BindingManagerBase != null, "3");
113                 }
114
115                 [Test]
116                 /* create control and set binding context */
117                 public void BindingContextChangedTest ()
118                 {
119                         Control c = new Control ();
120                         // Test BindingContextChanged Event
121                         c.BindingContextChanged += new EventHandler (Event_Handler1);
122                         BindingContext bcG1 = new BindingContext ();
123                         eventcount = 0;
124                         c.BindingContext = bcG1;
125                         Assert.AreEqual (1, eventcount, "A1");
126                 }
127
128                 [Test]
129                 /* create control and show control */
130                 public void BindingContextChangedTest2 ()
131                 {
132                         Form f = new Form ();
133                         f.ShowInTaskbar = false;
134                         Control c = new Control ();
135                         f.Controls.Add (c);
136
137                         c.BindingContextChanged += new EventHandler (Event_Handler1);
138                         eventcount = 0;
139                         f.Show ();
140 #if NET_2_0
141                         Assert.AreEqual (1, eventcount, "A1");
142 #else
143                         Assert.AreEqual (2, eventcount, "A1");
144 #endif
145                         f.Dispose();
146                 }
147
148                 [Test]
149                 /* create control, set binding context, and show control */
150                 public void BindingContextChangedTest3 ()
151                 {
152                         Form f = new Form ();
153                         f.ShowInTaskbar = false;
154
155                         Control c = new Control ();
156                         f.Controls.Add (c);
157
158                         c.BindingContextChanged += new EventHandler (Event_Handler1);
159                         eventcount = 0;
160                         c.BindingContext = new BindingContext ();;
161                         f.Show ();
162                         Assert.AreEqual (1, eventcount, "A1");
163                         f.Dispose ();
164                 }
165
166                 [Test]
167                 public void BindingContextChangedTest4 ()
168                 {
169                         Form f = new Form ();
170                         f.ShowInTaskbar = false;
171
172                         ContainerControl cc = new ContainerControl ();
173
174                         Control c = new Control ();
175                         f.Controls.Add (cc);
176                         cc.Controls.Add (c);
177
178                         c.BindingContextChanged += new EventHandler (Event_Handler1);
179                         cc.BindingContextChanged += new EventHandler (Event_Handler1);
180                         f.BindingContextChanged += new EventHandler (Event_Handler1);
181
182                         eventcount = 0;
183                         f.Show ();
184 #if NET_2_0
185                         Assert.AreEqual (5, eventcount, "A1");
186 #else
187                         Assert.AreEqual (8, eventcount, "A1");
188 #endif
189                         f.Dispose ();
190                 }
191
192                 int eventcount;
193                 public void Event_Handler1 (object sender, EventArgs e)
194                 {
195                         //Console.WriteLine (sender.GetType());
196                         //Console.WriteLine (Environment.StackTrace);
197                         eventcount++;
198                 }
199
200                 [Test]
201                 public void DataBindingCountTest1 ()
202                 {
203                         Control c = new Control ();
204                         Assert.AreEqual (0, c.DataBindings.Count, "1");
205                         c.DataBindings.Add (new Binding ("Text", c, "Name"));
206                         Assert.AreEqual (1, c.DataBindings.Count, "2");
207
208                         Binding b = c.DataBindings[0];
209                         Assert.AreEqual (c, b.Control, "3");
210                         Assert.AreEqual (c, b.DataSource, "4");
211                         Assert.AreEqual ("Text", b.PropertyName, "5");
212                         Assert.AreEqual ("Name", b.BindingMemberInfo.BindingField, "6");
213                 }
214
215                 [Test]
216                 public void DataBindingCountTest2 ()
217                 {
218                         Control c = new Control ();
219                         Control c2 = new Control ();
220                         Assert.AreEqual (0, c.DataBindings.Count, "1");
221                         c.DataBindings.Add (new Binding ("Text", c2, "Name"));
222                         Assert.AreEqual (1, c.DataBindings.Count, "2");
223                         Assert.AreEqual (0, c2.DataBindings.Count, "3");
224
225                         Binding b = c.DataBindings[0];
226                         Assert.AreEqual (c, b.Control, "4");
227                         Assert.AreEqual (c2, b.DataSource, "5");
228                         Assert.AreEqual ("Text", b.PropertyName, "6");
229                         Assert.AreEqual ("Name", b.BindingMemberInfo.BindingField, "7");
230                 }
231
232                 [Test]
233                 public void DataSourceNullTest ()
234                 {
235                         ChildMockItem item = new ChildMockItem ();
236                         Control c = new Control ();
237                         c.Tag = null;
238                         item.ObjectValue = null;
239
240                         c.DataBindings.Add ("Tag", item, "ObjectValue");
241
242                         Form f = new Form ();
243                         f.Controls.Add (c);
244
245                         f.Show (); // Need this to init data binding
246
247                         Assert.AreEqual (DBNull.Value, c.Tag, "1");
248                         
249                         f.Dispose ();
250                         
251                 }
252
253                 // For this case to work, the data source property needs
254                 // to have an associated 'PropertyChanged' event.
255                 [Test]
256                 public void DataSourcePropertyChanged ()
257                 {
258                         Control c = new Control ();
259                         c.BindingContext = new BindingContext ();
260                         c.CreateControl ();
261
262                         MockItem item = new MockItem ("A", 0);
263                         Binding binding = new Binding ("Text", item, "Text");
264
265                         c.DataBindings.Add (binding);
266                         Assert.AreEqual ("A", c.Text, "#A1");
267
268                         item.Text = "B";
269                         Assert.AreEqual ("B", c.Text, "#B1");
270                 }
271
272                 [Test]
273                 public void DataSourcePropertyChanged_Original ()
274                 {
275                         Control c = new Control ();
276                         c.BindingContext = new BindingContext ();
277                         c.CreateControl ();
278
279                         MockItem item = new MockItem ("A", 0);
280                         Binding binding = new Binding ("Text", item, "Text");
281
282                         c.DataBindings.Add (binding);
283                         Assert.AreEqual ("A", c.Text, "#A1");
284
285                         item.Text = "B";
286                         Assert.AreEqual ("B", c.Text, "#B1");
287                 }
288
289                 [Test]
290                 public void DataSourcePropertyChanged_Original_BadName ()
291                 {
292                         Control c = new Control ();
293                         c.BindingContext = new BindingContext ();
294                         c.CreateControl ();
295
296                         MockItem item = new MockItem ("A", 0);
297                         Binding binding = new Binding ("Text", item, "xxxxxxTextXXXXX");
298
299                         try {
300                                 c.DataBindings.Add (binding);
301                                 Assert.Fail ("exc1");
302                         } catch (ArgumentException ex) {
303                                 Assert.AreEqual ("dataMember", ex.ParamName, "ex.ParamName"); // (test is not locale dependent)
304                         }
305                 }
306
307                 [Test]
308                 public void DataSourcePropertyChanged_OneDeep ()
309                 {
310                         Control c = new Control ();
311                         c.BindingContext = new BindingContext ();
312                         c.CreateControl ();
313
314                         MockItem item = new MockItem ("A", 0);
315                         One parent = new One ();
316                         parent.MockItem = item;
317                         Binding binding = new Binding ("Text", parent, "MockItem.Text");
318
319                         c.DataBindings.Add (binding);
320                         Assert.AreEqual ("A", c.Text, "#A1");
321
322                         item.Text = "B";
323                         Assert.AreEqual ("B", c.Text, "#B1");
324                 }
325
326                 [Test]
327                 public void DataSourcePropertyChanged_ThreeDeep ()
328                 {
329                         Control c = new Control ();
330                         c.BindingContext = new BindingContext ();
331                         c.CreateControl ();
332
333                         MockItem item = new MockItem ("A", 0);
334                         One parent = new One ();
335                         parent.Two = new Two ();
336                         parent.Two.Three = new Three ();
337                         parent.Two.Three.MockItem = item;
338                         Binding binding = new Binding ("Text", parent, "Two.Three.MockItem.Text");
339
340                         c.DataBindings.Add (binding);
341                         Console.WriteLine ("c.Text: " + c.Text);
342                         Assert.AreEqual ("A", c.Text, "#A1");
343
344                         item.Text = "B";
345                         Assert.AreEqual ("B", c.Text, "#B1");
346
347                         Assert.AreEqual (1, c.DataBindings.Count, "c.DataBindings.Count");
348                         BindingMemberInfo bmi = c.DataBindings[0].BindingMemberInfo;
349                         Assert.AreEqual ("Two.Three.MockItem", bmi.BindingPath, "bmi.BindingPath");
350                         Assert.AreEqual ("Two.Three.MockItem.Text", bmi.BindingMember, "bmi.BindingMember");
351                         Assert.AreEqual ("Text", bmi.BindingField, "bmi.BindingField");
352                 }
353
354                 [Test]
355                 public void DataSourcePropertyChanged_DataSet ()
356                 {
357                         DataSet ds = new DataSet ();
358
359                         DataTable table1 = new DataTable ("Customers");
360                         table1.Columns.Add ("Id", typeof (int));
361                         table1.Columns.Add ("Name", typeof (string));
362                         table1.Rows.Add (new object[] {3, "customer1"});
363                         table1.Rows.Add (new object[] {7, "customer2"});
364                         ds.Tables.Add (table1);
365
366                         DataTable table2 = new DataTable ("Orders");
367                         table2.Columns.Add ("OrderId", typeof (int));
368                         table2.Columns.Add ("CustomerId", typeof (int));
369                         table2.Rows.Add (new object[] {56, 7});
370                         table2.Rows.Add (new object[] {57, 3});
371                         ds.Tables.Add (table2);
372
373                         DataRelation relation = new DataRelation ("CustomerOrders", table1.Columns ["Id"],
374                                         table2.Columns ["CustomerId"]);
375                         ds.Relations.Add (relation);
376
377                         Control ctrl = new Control ();
378                         ctrl.BindingContext = new BindingContext ();
379                         ctrl.CreateControl ();
380
381                         ctrl.DataBindings.Add ("Text", ds, "Customers.CustomerOrders.OrderId");
382                         Assert.AreEqual ("57", ctrl.Text, "A1");
383                 }
384
385                 [Test]
386                 public void DataSourcePropertyDifferentType ()
387                 {
388                         Exception exc = new Exception (String.Empty, new ArgumentNullException ("PARAM"));
389
390                         // The type of the property is Exception, but we know that the value
391                         // is actually an ArgumentException, thus specify the ParamName property
392                         Control ctrl = new Control ();
393                         ctrl.BindingContext = new BindingContext ();
394                         ctrl.CreateControl ();
395
396                         ctrl.DataBindings.Add ("Text", exc, "InnerException.ParamName");
397                         Assert.AreEqual ("PARAM", ctrl.Text, "A1");
398                 }
399
400                 [Test]
401                 public void IsBindingTest ()
402                 {
403                         MockItem [] items = new MockItem [] { new MockItem ("A", 0) };
404                         Binding binding = new Binding ("Text", items, "Text");
405                         Binding binding2 = new Binding ("Text", items [0], "Text");
406                         Assert.IsFalse (binding.IsBinding, "#A1");
407                         Assert.IsFalse (binding2.IsBinding, "#A2");
408
409                         Control c = new Control ();
410                         Control c2 = new Control ();
411                         c.DataBindings.Add (binding);
412                         c2.DataBindings.Add (binding2);
413                         Assert.IsFalse (binding.IsBinding, "#B1");
414                         Assert.IsFalse (binding2.IsBinding, "#B2");
415
416                         c.CreateControl ();
417                         c2.CreateControl ();
418                         Assert.IsFalse (binding.IsBinding, "#C1");
419                         Assert.IsFalse (binding2.IsBinding, "#C2");
420
421                         Form form = new Form ();
422                         form.ShowInTaskbar = false;
423                         form.Controls.Add (c);
424                         form.Controls.Add (c2);
425                         Assert.IsTrue (binding.IsBinding, "#D1");
426                         Assert.IsTrue (binding2.IsBinding, "#D2");
427
428                         form.Show ();
429
430                         // Important part -
431                         // IsBinding is true ALWAYS with PropertyManager, even when
432                         // ResumeBinding has been called
433                         //
434                         CurrencyManager curr_manager = (CurrencyManager)form.BindingContext [items];
435                         PropertyManager prop_manager = (PropertyManager)form.BindingContext [items [0]];
436                         curr_manager.SuspendBinding ();
437                         prop_manager.SuspendBinding ();
438                         Assert.IsFalse (binding.IsBinding, "#E1"); 
439                         Assert.IsTrue (binding2.IsBinding, "#E2");
440
441                         curr_manager.ResumeBinding ();
442                         prop_manager.ResumeBinding ();
443                         Assert.IsTrue (binding.IsBinding, "#F1");
444                         Assert.IsTrue (binding2.IsBinding, "#F2");
445
446                         form.Dispose ();
447                 }
448
449 #if NET_2_0
450                 [Test]
451                 public void ReadValueTest ()
452                 {
453                         Control c = new Control ();
454                         c.BindingContext = new BindingContext ();
455                         c.CreateControl ();
456
457                         ChildMockItem item = new ChildMockItem ();
458                         item.ObjectValue = "A";
459                         Binding binding = new Binding ("Tag", item, "ObjectValue");
460                         binding.ControlUpdateMode = ControlUpdateMode.Never;
461
462                         c.DataBindings.Add (binding);
463                         Assert.AreEqual (null, c.Tag, "#A1");
464
465                         item.ObjectValue = "B";
466                         Assert.AreEqual (null, c.Tag, "#B1");
467
468                         binding.ReadValue ();
469                         Assert.AreEqual ("B", c.Tag, "#C1");
470
471                         item.ObjectValue = "C";
472                         binding.ReadValue ();
473                         Assert.AreEqual ("C", c.Tag, "#D1");
474                         
475                         c.Dispose();
476                 }
477
478                 [Test]
479                 public void WriteValueTest ()
480                 {
481                         Control c = new Control ();
482                         c.BindingContext = new BindingContext ();
483                         c.CreateControl ();
484
485                         MockItem item = new MockItem ();
486                         item.Text = "A";
487                         Binding binding = new Binding ("Text", item, "Text");
488                         binding.DataSourceUpdateMode = DataSourceUpdateMode.Never;
489
490                         c.DataBindings.Add (binding);
491                         Assert.AreEqual ("A", c.Text, "#A1");
492
493                         c.Text = "B";
494                         Assert.AreEqual ("A", item.Text, "#B1");
495
496                         binding.WriteValue ();
497                         Assert.AreEqual ("B", item.Text, "#C1");
498                 }
499
500                 [Test]
501                 public void BindableComponentTest ()
502                 {
503                         Control c = new Control ();
504
505                         MockItem item = new MockItem (String.Empty, 0);
506                         Binding binding = new Binding ("Text", item, "Text");
507
508                         c.DataBindings.Add (binding);
509                         Assert.AreEqual (c, binding.Control, "#A1");
510                         Assert.AreEqual (c, binding.BindableComponent, "#A2");
511
512                         // 
513                         // Now use IBindableComponent - update binding when property changes
514                         // since ToolStripItem doesn't have validation at all
515                         //
516                         BindableToolStripItem toolstrip_item = new BindableToolStripItem ();
517                         toolstrip_item.BindingContext = new BindingContext ();
518                         Binding binding2 = new Binding ("Text", item, "Text");
519                         binding2.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
520
521                         item.Text = "A";
522                         toolstrip_item.DataBindings.Add (binding2);
523                         Assert.AreEqual (null, binding2.Control, "#B1");
524                         Assert.AreEqual (toolstrip_item, binding2.BindableComponent, "#B2");
525                         Assert.AreEqual (item.Text, toolstrip_item.Text, "#B3");
526
527                         toolstrip_item.Text = "B";
528                         Assert.AreEqual (toolstrip_item.Text, item.Text, "#C1");
529                 }
530
531                 [Test]
532                 public void ControlUpdateModeTest ()
533                 {
534                         Control c = new Control ();
535                         c.BindingContext = new BindingContext ();
536                         c.CreateControl ();
537
538                         MockItem item = new MockItem ("A", 0);
539                         Binding binding = new Binding ("Text", item, "Text");
540                         binding.ControlUpdateMode = ControlUpdateMode.Never;
541
542                         c.DataBindings.Add (binding);
543                         Assert.AreEqual (String.Empty, c.Text, "#A1");
544
545                         item.Text = "B";
546                         Assert.AreEqual (String.Empty, c.Text, "#B1");
547                 }
548
549                 [Test]
550                 public void DataSourceUpdateModeTest ()
551                 {
552                         Control c = new Control ();
553                         c.BindingContext = new BindingContext ();
554                         c.CreateControl ();
555
556                         MockItem item = new MockItem ("A", 0);
557                         Binding binding = new Binding ("Text", item, "Text");
558                         binding.DataSourceUpdateMode = DataSourceUpdateMode.Never;
559
560                         c.DataBindings.Add (binding);
561                         Assert.AreEqual ("A", c.Text, "#A1");
562
563                         c.Text = "B";
564                         Assert.AreEqual ("A", item.Text, "#B1");
565
566                         binding.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
567                         Assert.AreEqual ("A", item.Text, "#C1");
568
569                         c.Text = "C";
570                         Assert.AreEqual ("C", item.Text, "#D1");
571
572                         // This requires a Validation even, which we can't test
573                         // by directly modifying the property
574                         binding.DataSourceUpdateMode = DataSourceUpdateMode.OnValidation;
575
576                         c.Text = "D";
577                         Assert.AreEqual ("C", item.Text, "#E1");
578                 }
579
580                 [Test]
581                 public void DataSourceNullValueTest ()
582                 {
583                         Control c = new Control ();
584                         c.BindingContext = new BindingContext ();
585                         c.CreateControl ();
586
587                         ChildMockItem item = new ChildMockItem ();
588                         item.ObjectValue = "A";
589                         Binding binding = new Binding ("Tag", item, "ObjectValue");
590                         binding.DataSourceNullValue = "NonNull";
591
592                         c.DataBindings.Add (binding);
593                         Assert.AreEqual (c.Tag, "A", "#A1");
594
595                         // Since Tag property doesn't have a 
596                         // TagChanged event, we need to force an update
597                         c.Tag = null;
598                         binding.WriteValue ();
599                         Assert.AreEqual (item.ObjectValue, "NonNull", "#B1");
600                 }
601
602                 [Test]
603                 public void NullValueTest ()
604                 {
605                         Control c = new Control ();
606                         c.BindingContext = new BindingContext ();
607                         c.CreateControl ();
608
609                         DataTable table = new DataTable ();
610                         table.Columns.Add ("Name", typeof (string));
611                         table.Columns.Add ("Id", typeof (int));
612                         table.Rows.Add (null, DBNull.Value);
613
614                         Binding binding = new Binding ("Tag", table, "Name");
615                         Binding binding2 = new Binding ("Width", table, "Id");
616                         binding.FormattingEnabled = true;
617                         binding.NullValue = "non-null";
618                         binding2.FormattingEnabled = true;
619                         binding2.NullValue = 101;
620
621                         c.Width = 99;
622                         c.DataBindings.Add (binding);
623                         c.DataBindings.Add (binding2);
624
625                         Assert.AreEqual ("non-null", c.Tag, "#A1");
626                         Assert.AreEqual (101, c.Width, "#A2");
627                 }
628
629                 [Test]
630                 public void FormattingEnabledTest ()
631                 {
632                         Control c = new Control ();
633                         c.BindingContext = new BindingContext ();
634                         c.CreateControl ();
635
636                         MockItem item = new MockItem ();
637                         item.Value = 666;
638                         Binding binding = new Binding ("Text", item, "Value");
639                         binding.FormattingEnabled = true;
640                         binding.FormatString = "p";
641
642                         c.DataBindings.Add (binding);
643                         Assert.AreEqual ((666).ToString ("p"), c.Text, "#A1");
644
645                         binding.FormatString = "c";
646                         Assert.AreEqual ((666).ToString ("c"), c.Text, "#B1");
647                         Console.WriteLine (c.Text);
648
649                         binding.FormattingEnabled = false;
650                         Assert.AreEqual ((666).ToString (), c.Text, "#C1");
651                 }
652
653                 [Test]
654                 public void FormatStringTest ()
655                 {
656                         Binding binding = new Binding ("Text", null, "Text");
657                         binding.FormatString = null;
658
659                         Assert.AreEqual (String.Empty, binding.FormatString, "#A1");
660                 }
661 #endif
662
663         }
664
665         class ChildMockItem : MockItem
666         {
667                 object value;
668
669                 public ChildMockItem ()
670                         : base (null, 0)
671                 {
672                 }
673
674                 public object ObjectValue
675                 {
676                         get
677                         {
678                                 return value;
679                         }
680                         set
681                         {
682                                 this.value = value;
683                         }
684                 }
685         }
686
687 #if NET_2_0
688         class BindableToolStripItem : ToolStripItem, IBindableComponent
689         {
690                 ControlBindingsCollection data_bindings;
691                 BindingContext binding_context;
692
693                 public ControlBindingsCollection DataBindings {
694                         get {
695                                 if (data_bindings == null)
696                                         data_bindings = new ControlBindingsCollection (this);
697
698                                 return data_bindings;
699                         }
700                 }
701
702                 public BindingContext BindingContext
703                 {
704                         get {
705                                 return binding_context;
706                         }
707                         set {
708                                 binding_context = value;
709                         }
710                 }
711         }
712 #endif
713
714         class One
715         {
716                 //----
717                 //private global::System.Collections.Generic.IList<Two> m_twoList
718                 //    = new global::System.Collections.Generic.List<Two> ();
719                 //
720                 //public global::System.Collections.Generic.IList<Two> TwoList
721                 //{
722                 //    get { return m_twoList; }
723                 //}
724
725                 //----
726                 private Two m_two;
727
728                 public Two Two
729                 {
730                         get { return m_two; }
731                         set { m_two = value; }
732                 }
733         
734                 //----
735                 private MockItem m_MockItem;
736
737                 public MockItem MockItem
738                 {
739                         get { return m_MockItem; }
740                         set { m_MockItem = value; }
741                 }
742         
743                 //----
744                 public override string ToString ()
745                 {
746                         return "!!! ToString on One !!!";
747                 }
748         }
749
750         class Two
751         {
752                 //private global::System.Collections.Generic.IList<MockItem> m_MockItemList
753                 //    = new global::System.Collections.Generic.List<MockItem> ();
754                 //
755                 //public global::System.Collections.Generic.IList<MockItem> MockItemList
756                 //{
757                 //    get { return m_MockItemList; }
758                 //}
759
760                 //----
761                 private MockItem m_MockItem;
762
763                 public MockItem MockItem
764                 {
765                         get { return m_MockItem; }
766                         set { m_MockItem = value; }
767                 }
768
769                 private Three m_Three;
770
771                 public Three Three
772                 {
773                         get { return m_Three; }
774                         set { m_Three = value; }
775                 }
776
777                 public override string ToString ()
778                 {
779                         return "!!! ToString on Two !!!";
780                 }
781         }
782
783         class Three
784         {
785                 private MockItem m_MockItem;
786
787                 public MockItem MockItem
788                 {
789                         get { return m_MockItem; }
790                         set { m_MockItem = value; }
791                 }
792
793                 public override string ToString ()
794                 {
795                         return "!!! ToString on Three !!!";
796                 }
797         }
798
799 }
800