BindingManagerBaseTest.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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) 2007 Novell, Inc.
  21. //
  22. // Authors:
  23. // Chris Toshok [email protected]
  24. using System;
  25. using System.Collections;
  26. using System.ComponentModel;
  27. using System.Data;
  28. using System.Reflection;
  29. using System.Windows.Forms;
  30. using NUnit.Framework;
  31. using CategoryAttribute = NUnit.Framework.CategoryAttribute;
  32. namespace MonoTests.System.Windows.Forms.DataBinding
  33. {
  34. [TestFixture]
  35. public class BindingManagerBaseTest : TestHelper {
  36. [Test]
  37. public void BindingsTest ()
  38. {
  39. Control c1 = new Control ();
  40. Control c2 = new Control ();
  41. c1.CreateControl ();
  42. c2.CreateControl ();
  43. Binding binding;
  44. BindingManagerBase bm, bm2;
  45. c1.BindingContext = new BindingContext ();
  46. c2.BindingContext = c1.BindingContext;
  47. bm = c2.BindingContext[c1, "Text"];
  48. bm2 = c2.BindingContext[c1];
  49. #if NET_2_0
  50. bm.BindingComplete += delegate (object sender, BindingCompleteEventArgs e) { Console.WriteLine (Environment.StackTrace); };
  51. bm2.BindingComplete += delegate (object sender, BindingCompleteEventArgs e) { Console.WriteLine (Environment.StackTrace); };
  52. #endif
  53. binding = c2.DataBindings.Add ("Text", c1, "Text");
  54. Assert.AreEqual (0, bm.Bindings.Count, "1");
  55. Assert.AreEqual (1, bm2.Bindings.Count, "2");
  56. Assert.AreEqual (bm2.Bindings[0], binding, "3");
  57. }
  58. #if NET_2_0
  59. [Test]
  60. public void IsBindingSuspendedTest ()
  61. {
  62. Control c = new Control ();
  63. c.BindingContext = new BindingContext ();
  64. MockItem item = new MockItem ("A", 0);
  65. MockItem [] items = new MockItem [] { item };
  66. BindingManagerBase manager = c.BindingContext [item];
  67. BindingManagerBase manager2 = c.BindingContext [items];
  68. Assert.IsFalse (manager.IsBindingSuspended, "#A1");
  69. Assert.IsFalse (manager2.IsBindingSuspended, "#A2");
  70. manager.SuspendBinding ();
  71. manager2.SuspendBinding ();
  72. Assert.IsFalse (manager.IsBindingSuspended, "#B1");
  73. Assert.IsTrue (manager2.IsBindingSuspended, "#B2");
  74. manager.ResumeBinding ();
  75. manager2.ResumeBinding ();
  76. Assert.IsFalse (manager.IsBindingSuspended, "#C1");
  77. Assert.IsFalse (manager2.IsBindingSuspended, "#C2");
  78. }
  79. #endif
  80. }
  81. }