BindingTest.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 [email protected]
  24. using System;
  25. using System.Data;
  26. using System.Collections;
  27. using System.Windows.Forms;
  28. using NUnit.Framework;
  29. namespace MonoTests.System.Windows.Forms {
  30. [TestFixture]
  31. public class BindingTest {
  32. [SetUp]
  33. protected virtual void SetUp ()
  34. {
  35. }
  36. [TearDown]
  37. protected virtual void TearDown ()
  38. {
  39. }
  40. [Test]
  41. public void CtorTest ()
  42. {
  43. string prop = "PROPERTY NAME";
  44. object data_source = new object ();
  45. string data_member = "DATA MEMBER";
  46. Binding b = new Binding (prop, data_source, data_member);
  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. Assert.AreSame (b.PropertyName, prop, "ctor5");
  53. Assert.AreSame (b.DataSource, data_source, "ctor6");
  54. }
  55. [Test]
  56. public void CtorNullTest ()
  57. {
  58. Binding b = new Binding (null, null, null);
  59. Assert.IsNull (b.PropertyName, "ctornull1");
  60. Assert.IsNull (b.DataSource, "ctornull2");
  61. }
  62. [Test]
  63. /* create control and set binding context */
  64. public void BindingContextChangedTest ()
  65. {
  66. Control c = new Control ();
  67. // Test BindingContextChanged Event
  68. c.BindingContextChanged += new EventHandler (Event_Handler1);
  69. BindingContext bcG1 = new BindingContext ();
  70. eventcount = 0;
  71. c.BindingContext = bcG1;
  72. Assert.AreEqual (1, eventcount, "A1");
  73. }
  74. [Test]
  75. [Category ("NotWorking")]
  76. /* create control and show control */
  77. public void BindingContextChangedTest2 ()
  78. {
  79. Form f = new Form ();
  80. Control c = new Control ();
  81. f.Controls.Add (c);
  82. c.BindingContextChanged += new EventHandler (Event_Handler1);
  83. eventcount = 0;
  84. f.Show ();
  85. Assert.AreEqual (2, eventcount, "A1");
  86. f.Dispose();
  87. }
  88. [Test]
  89. /* create control, set binding context, and show control */
  90. public void BindingContextChangedTest3 ()
  91. {
  92. Form f = new Form ();
  93. Control c = new Control ();
  94. f.Controls.Add (c);
  95. c.BindingContextChanged += new EventHandler (Event_Handler1);
  96. eventcount = 0;
  97. c.BindingContext = new BindingContext ();;
  98. f.Show ();
  99. Assert.AreEqual (1, eventcount, "A1");
  100. f.Dispose ();
  101. }
  102. int eventcount;
  103. public void Event_Handler1 (object sender, EventArgs e)
  104. {
  105. Console.WriteLine (Environment.StackTrace);
  106. eventcount++;
  107. }
  108. }
  109. }