PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/CurrencyManagerTest.cs

https://bitbucket.org/danipen/mono
C# | 1266 lines | 972 code | 246 blank | 48 comment | 43 complexity | 2c036dccf3e06ce2c71fce041b66d8a8 MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0
  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. 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. #if NET_2_0
  32. using System.Collections.ObjectModel;
  33. #endif
  34. namespace MonoTests.System.Windows.Forms.DataBinding
  35. {
  36. [TestFixture]
  37. public class CurrencyManagerTest : TestHelper
  38. {
  39. [Test]
  40. public void Defaults ()
  41. {
  42. BindingContext bc = new BindingContext ();
  43. ArrayList data_source = new ArrayList ();
  44. CurrencyManager cm = bc [data_source] as CurrencyManager;
  45. Assert.AreSame (data_source, cm.List, "DEFAULTS1");
  46. Assert.AreEqual (0, cm.Count, "DEFAULTS2");
  47. Assert.AreEqual (-1, cm.Position, "DEFAULTS3");
  48. }
  49. [Test]
  50. [ExpectedException (typeof (IndexOutOfRangeException))]
  51. public void UninitializedCurrent ()
  52. {
  53. BindingContext bc = new BindingContext ();
  54. ArrayList data_source = new ArrayList ();
  55. CurrencyManager cm = bc [data_source] as CurrencyManager;
  56. // This line should throw
  57. Assert.AreSame (null, cm.Current, "CurrentOfEmpty");
  58. }
  59. [Test]
  60. public void DataSetList ()
  61. {
  62. DataSet dataset = new DataSet ("DataSet");
  63. DataTable table = new DataTable ("Table");
  64. BindingContext bc = new BindingContext ();
  65. CurrencyManager cm;
  66. dataset.Tables.Add (table);
  67. cm = bc [dataset] as CurrencyManager;
  68. Assert.AreEqual (typeof (DataViewManager), cm.List.GetType (), "DATASETLIST1");
  69. Assert.AreEqual (1, cm.Count, "DATASETLIST2");
  70. Assert.AreEqual (0, cm.Position, "DATASETLIST3");
  71. // Assert.AreEqual (typeof (DataViewManagerListItemTypeDescriptor), cm.Current.GetType (),
  72. // "DATASETLIST4");
  73. }
  74. [Test]
  75. public void DataSetListTable ()
  76. {
  77. DataSet dataset = new DataSet ("DataSet");
  78. DataTable table = new DataTable ("Table");
  79. BindingContext bc = new BindingContext ();
  80. CurrencyManager cm;
  81. dataset.Tables.Add (table);
  82. cm = bc [dataset, "Table"] as CurrencyManager;
  83. Assert.AreEqual (typeof (DataView), cm.List.GetType (), "DATASETLIST1");
  84. Assert.AreEqual (0, cm.Count, "DATASETLIST2");
  85. Assert.AreEqual (-1, cm.Position, "DATASETLIST3");
  86. }
  87. [Test]
  88. [ExpectedException (typeof (ArgumentException))]
  89. public void DataSetListTableBogusField ()
  90. {
  91. DataSet dataset = new DataSet ("DataSet");
  92. DataTable table = new DataTable ("Table.Column");
  93. BindingContext bc = new BindingContext ();
  94. CurrencyManager cm;
  95. dataset.Tables.Add (table);
  96. // child list can't be created
  97. cm = bc [dataset, "Table"] as CurrencyManager;
  98. TestHelper.RemoveWarning (cm);
  99. }
  100. [Test] // bug #80107
  101. public void DataView ()
  102. {
  103. DataView dv = new DataView ();
  104. BindingContext bc = new BindingContext ();
  105. CurrencyManager cm = bc [dv, string.Empty] as CurrencyManager;
  106. Assert.IsNotNull (cm, "#A1");
  107. Assert.AreEqual (0, cm.Count, "#A2");
  108. Assert.AreEqual (-1, cm.Position, "#A3");
  109. DataTable dt = new DataTable ("Testdata");
  110. dt.Columns.Add ("A");
  111. dt.Columns.Add ("B");
  112. dt.Rows.Add (new object [] { "A1", "B1" });
  113. dt.Rows.Add (new object [] { "A2", "B2" });
  114. dv.Table = dt;
  115. Assert.AreEqual (2, cm.Count, "#B1");
  116. Assert.AreEqual (0, cm.Position, "#B2");
  117. }
  118. #if NET_2_0
  119. [Test]
  120. public void IsBindingEmptyDataSource ()
  121. {
  122. Control c = new Control ();
  123. c.BindingContext = new BindingContext ();
  124. c.CreateControl ();
  125. BindingList<string> list = new BindingList<string> ();
  126. CurrencyManager cm = (CurrencyManager)c.BindingContext [list];
  127. Assert.AreEqual (true, cm.IsBindingSuspended, "A1");
  128. cm.ResumeBinding ();
  129. Assert.AreEqual (true, cm.IsBindingSuspended, "B1");
  130. list.Add ("A");
  131. Assert.AreEqual (false, cm.IsBindingSuspended, "D1");
  132. list.Clear ();
  133. Assert.AreEqual (true, cm.IsBindingSuspended, "E1");
  134. }
  135. #endif
  136. [Test]
  137. public void MoveArrayListForward ()
  138. {
  139. ArrayList data_source = new ArrayList ();
  140. BindingContext bc = new BindingContext ();
  141. for (int i = 0; i < 10; i++)
  142. data_source.Add (new object ());
  143. CurrencyManager cm = bc [data_source] as CurrencyManager;
  144. for (int i = 0; i < 10; i++) {
  145. Assert.AreSame (data_source [i], cm.Current, "MOVEALF" + i);
  146. cm.Position++;
  147. }
  148. cm.Position++;
  149. cm.Position++;
  150. Assert.AreSame (data_source [9], cm.Current, "MOVEALFEND");
  151. }
  152. [Test]
  153. public void MoveArrayListBackward ()
  154. {
  155. ArrayList data_source = new ArrayList ();
  156. BindingContext bc = new BindingContext ();
  157. for (int i = 0; i < 10; i++)
  158. data_source.Add (new object ());
  159. CurrencyManager cm = bc [data_source] as CurrencyManager;
  160. cm.Position = 9;
  161. for (int i = 9; i >= 0; i--) {
  162. Assert.AreSame (data_source [i], cm.Current, "MOVEALB" + i);
  163. cm.Position--;
  164. }
  165. cm.Position--;
  166. cm.Position--;
  167. Assert.AreSame (data_source [0], cm.Current, "MOVEALBSTART");
  168. }
  169. [Test]
  170. public void SetPositionArrayList ()
  171. {
  172. ArrayList data_source = new ArrayList ();
  173. BindingContext bc = new BindingContext ();
  174. for (int i = 0; i < 10; i++)
  175. data_source.Add (new object ());
  176. CurrencyManager cm = bc [data_source] as CurrencyManager;
  177. for (int i = 3; i >= 0; i--) {
  178. cm.Position = i;
  179. Assert.AreSame (data_source [i], cm.Current, "MOVEAL1-" + i);
  180. }
  181. cm.Position--;
  182. for (int i = 0; i < 10; i++) {
  183. cm.Position = i;
  184. Assert.AreSame (data_source [i], cm.Current, "MOVEAL2-" + i);
  185. }
  186. for (int i = 5; i < 10; i++) {
  187. cm.Position = i;
  188. Assert.AreSame (data_source [i], cm.Current, "MOVEAL3-" + i);
  189. }
  190. }
  191. [Test]
  192. public void LateBuildDataTable ()
  193. {
  194. DataTable data_source = new DataTable ("Table");
  195. BindingContext bc = new BindingContext ();
  196. CurrencyManager cm = bc [data_source] as CurrencyManager;
  197. Assert.AreEqual (-1, cm.Position, "LATEBUILDTABLE1");
  198. Assert.AreEqual (0, cm.Count, "LATEBUILDTABLE2");
  199. DataColumn column = new DataColumn ("Column");
  200. column.DataType = typeof (int);
  201. data_source.Columns.Add (column);
  202. for (int i = 0; i < 10; i++) {
  203. DataRow row = data_source.NewRow ();
  204. row ["Column"] = i;
  205. data_source.Rows.Add (row);
  206. }
  207. Assert.AreEqual (0, cm.Position, "LATEBUILDTABLE3");
  208. Assert.AreEqual (10, cm.Count, "LATEBUILDTABLE4");
  209. }
  210. [Test]
  211. public void LateBuildArrayList ()
  212. {
  213. ArrayList data_source = new ArrayList ();
  214. BindingContext bc = new BindingContext ();
  215. CurrencyManager cm = bc [data_source] as CurrencyManager;
  216. Assert.AreEqual (-1, cm.Position, "LATEBUILDLIST1");
  217. Assert.AreEqual (0, cm.Count, "LATEBUILDLIST2");
  218. data_source.AddRange (new object [] { 1, 2, 3, 4, 5, 6, 7 });
  219. Assert.AreEqual (-1, cm.Position, "LATEBUILDLIST3");
  220. Assert.AreEqual (7, cm.Count, "LATEBUILDLIST4");
  221. }
  222. [Test]
  223. public void MoveDataTableForward ()
  224. {
  225. DataTable data_source = new DataTable ("Table");
  226. BindingContext bc = new BindingContext ();
  227. CurrencyManager cm = bc [data_source] as CurrencyManager;
  228. DataColumn column = new DataColumn ("Column");
  229. column.DataType = typeof (int);
  230. data_source.Columns.Add (column);
  231. for (int i = 0; i < 10; i++) {
  232. DataRow row = data_source.NewRow ();
  233. row ["Column"] = i;
  234. data_source.Rows.Add (row);
  235. }
  236. for (int i = 0; i < 10; i++) {
  237. DataRowView row = cm.Current as DataRowView;
  238. Assert.IsFalse (row == null, "MOVETABLEF-NULL-" + i);
  239. Assert.AreEqual (row ["Column"], i, "MOVETABLEF-" + i);
  240. cm.Position++;
  241. }
  242. cm.Position++;
  243. cm.Position++;
  244. Assert.AreEqual (9, ((DataRowView) cm.Current) ["Column"], "MOVETABLEF-END");
  245. }
  246. [Test]
  247. public void MoveDataTableBackward ()
  248. {
  249. DataTable data_source = new DataTable ("Table");
  250. BindingContext bc = new BindingContext ();
  251. CurrencyManager cm = bc [data_source] as CurrencyManager;
  252. DataColumn column = new DataColumn ("Column");
  253. column.DataType = typeof (int);
  254. data_source.Columns.Add (column);
  255. for (int i = 0; i < 10; i++) {
  256. DataRow row = data_source.NewRow ();
  257. row ["Column"] = i;
  258. data_source.Rows.Add (row);
  259. }
  260. cm.Position = 9;
  261. for (int i = 9; i >= 0; i--) {
  262. DataRowView row = cm.Current as DataRowView;
  263. Assert.IsFalse (row == null, "MOVETABLEB-NULL-" + i);
  264. Assert.AreEqual (row ["Column"], i, "MOVETABLEB-" + i);
  265. cm.Position--;
  266. }
  267. cm.Position--;
  268. cm.Position--;
  269. Assert.AreEqual (0, ((DataRowView) cm.Current) ["Column"], "MOVETABLEB-START");
  270. }
  271. [Test]
  272. public void SetPositionDataTable ()
  273. {
  274. DataTable data_source = new DataTable ("Table");
  275. BindingContext bc = new BindingContext ();
  276. CurrencyManager cm = bc [data_source] as CurrencyManager;
  277. DataColumn column = new DataColumn ("Column");
  278. column.DataType = typeof (int);
  279. data_source.Columns.Add (column);
  280. for (int i = 0; i < 10; i++) {
  281. DataRow row = data_source.NewRow ();
  282. row ["Column"] = i;
  283. data_source.Rows.Add (row);
  284. }
  285. for (int i = 5; i < 10; i++) {
  286. cm.Position = i;
  287. DataRowView row = cm.Current as DataRowView;
  288. Assert.IsFalse (row == null, "SETTABLE1-NULL-" + i);
  289. Assert.AreEqual (row ["Column"], i, "SETTABLE1-" + i);
  290. }
  291. for (int i = 5; i >= 0; i--) {
  292. cm.Position = i;
  293. DataRowView row = cm.Current as DataRowView;
  294. Assert.IsFalse (row == null, "SETTABLE2-NULL-" + i);
  295. Assert.AreEqual (row ["Column"], i, "SETTABLE2-" + i);
  296. }
  297. }
  298. [Test]
  299. public void NavigateDataSetToTable ()
  300. {
  301. DataSet data_source = new DataSet ("DataSet");
  302. DataTable table = new DataTable ("Table");
  303. DataColumn column = new DataColumn ("Column");
  304. BindingContext bc = new BindingContext ();
  305. data_source.Tables.Add (table);
  306. column.DataType = typeof (int);
  307. table.Columns.Add (column);
  308. for (int i = 0; i < 10; i++) {
  309. DataRow row = table.NewRow ();
  310. row ["Column"] = i;
  311. table.Rows.Add (row);
  312. }
  313. CurrencyManager cm = bc [data_source, "Table"] as CurrencyManager;
  314. Assert.AreEqual (0, cm.Position, "NAVSETTOTABLE1");
  315. Assert.AreEqual (10, cm.Count, "NAVSETTOTABLE2");
  316. Assert.AreEqual (typeof (DataView), cm.List.GetType (), "NAVSETTOTABLE3");
  317. for (int i = 0; i < 10; i++) {
  318. DataRowView row = cm.Current as DataRowView;
  319. Assert.IsFalse (row == null, "NAVSETTOTABLE-NULL-" + i);
  320. Assert.AreEqual (i, row ["Column"], "NAVSETTOTABLE-" + i);
  321. cm.Position++;
  322. }
  323. cm.Position++;
  324. cm.Position++;
  325. Assert.AreEqual (9, ((DataRowView) cm.Current) ["Column"], "NAVSETTOTABLE-END");
  326. }
  327. [Test]
  328. public void NavigateDataSetToColumn ()
  329. {
  330. DataSet data_source = new DataSet ("DataSet");
  331. DataTable table = new DataTable ("Table");
  332. DataColumn column = new DataColumn ("Column");
  333. BindingContext bc = new BindingContext ();
  334. data_source.Tables.Add (table);
  335. column.DataType = typeof (int);
  336. table.Columns.Add (column);
  337. for (int i = 0; i < 10; i++) {
  338. DataRow row = table.NewRow ();
  339. row ["Column"] = i;
  340. table.Rows.Add (row);
  341. }
  342. CurrencyManager cm = bc [data_source, "Table.Column"] as CurrencyManager;
  343. Assert.AreEqual (null, cm, "NAVSETTOCOLUMN1");
  344. }
  345. [Test]
  346. public void NavigateDataSetToParentRelation ()
  347. {
  348. DataSet data_source = CreateRelatedDataSet ();
  349. BindingContext bc = new BindingContext ();
  350. CurrencyManager cm = bc [data_source, "Table1.Relation"] as CurrencyManager;
  351. Assert.AreEqual (0, cm.Position, "NAVSETTORELATION1");
  352. Assert.AreEqual (1, cm.Count, "NAVSETTORELATION2");
  353. Assert.IsTrue (cm.List is DataView, "NAVSETTORELATION3");
  354. DataRowView row = cm.Current as DataRowView;
  355. Assert.IsFalse (row == null, "NAVSETTORELATION-NULL-VALUE");
  356. Assert.AreEqual (0, row ["Two"], "NAVSETTORELATION-VALUE");
  357. cm.Position++;
  358. cm.Position++;
  359. Assert.AreEqual (0, ((DataRowView) cm.Current) ["Two"], "NAVSETTORELATION-END");
  360. }
  361. [Test]
  362. [ExpectedException (typeof (ArgumentException))]
  363. public void DataSetToChildRelation ()
  364. {
  365. DataSet data_source = CreateRelatedDataSet ();
  366. BindingContext bc = new BindingContext ();
  367. // Can't create a list on a child relation
  368. CurrencyManager cm = bc [data_source, "Table2.Relation"] as CurrencyManager;
  369. TestHelper.RemoveWarning (cm);
  370. }
  371. [Test]
  372. public void DataSetToParentRelationField ()
  373. {
  374. DataSet data_source = CreateRelatedDataSet ();
  375. BindingContext bc = new BindingContext ();
  376. CurrencyManager cm = bc [data_source, "Table1.Relation.Two"] as CurrencyManager;
  377. Assert.AreEqual (null, cm, "SETTOPARENTRELATIONFIELD");
  378. }
  379. [Test]
  380. public void MultiColumnedRelation ()
  381. {
  382. DataSet dataset = new DataSet ();
  383. DataTable sports = new DataTable ("Sports");
  384. DataTable athletes = new DataTable ("Athletes");
  385. DataColumn column;
  386. DataRow row;
  387. column = new DataColumn ();
  388. column.DataType = typeof (int);
  389. column.ColumnName = "SportID";
  390. column.Unique = true;
  391. sports.Columns.Add (column);
  392. column = new DataColumn ();
  393. column.DataType = typeof (string);
  394. column.ColumnName = "SportName";
  395. sports.Columns.Add (column);
  396. string [] sports_names = new string [] { "Hockey", "Baseball", "Basketball", "Football", "Boxing", "Surfing" };
  397. for (int i = 0; i < sports_names.Length; i++) {
  398. row = sports.NewRow ();
  399. row ["SportID"] = i;
  400. row ["SportName"] = sports_names [i];
  401. sports.Rows.Add (row);
  402. }
  403. // Athletes table
  404. column = new DataColumn ();
  405. column.DataType = typeof (int);
  406. column.ColumnName = "AthleteID";
  407. column.Unique = true;
  408. athletes.Columns.Add (column);
  409. column = new DataColumn ();
  410. column.DataType = typeof (int);
  411. column.ColumnName = "Sport";
  412. athletes.Columns.Add (column);
  413. column = new DataColumn ();
  414. column.DataType = typeof (string);
  415. column.ColumnName = "AthleteName";
  416. athletes.Columns.Add (column);
  417. string [] athlete_names = new string [] { "@alp", "@lupus", "@tjfontaine", "duncan", "marv", "WindowsUninstall",
  418. "@jackson", "@migHome", "_Synced[work]", "GodZhila", "Raboo",
  419. "@jchambers", "@mkestner", "barbosa", "IzeBurn", "squinky86",
  420. "@kangaroo", "@paco", "Demian", "logiclrd", "tenshiKur0" };
  421. for (int i = 0; i < athlete_names.Length; i++) {
  422. row = athletes.NewRow ();
  423. row ["AthleteID"] = i;
  424. row ["Sport"] = i % sports_names.Length;
  425. row ["AthleteName"] = athlete_names [i];
  426. athletes.Rows.Add (row);
  427. }
  428. dataset.Tables.Add (sports);
  429. dataset.Tables.Add (athletes);
  430. dataset.Relations.Add ("AthletesSports", sports.Columns ["SportID"], athletes.Columns ["Sport"]);
  431. BindingContext bc = new BindingContext ();
  432. CurrencyManager cm = bc [dataset, "Sports.AthletesSports"] as CurrencyManager;
  433. Assert.AreEqual (0, cm.Position, "MC1");
  434. Assert.AreEqual (4, cm.Count, "MC2");
  435. DataRowView rowview = cm.Current as DataRowView;
  436. Assert.IsFalse (rowview == null, "MC3");
  437. Assert.AreEqual (0, rowview ["AthleteID"], "MC4");
  438. Assert.AreEqual ("@alp", rowview ["AthleteName"], "MC5");
  439. Assert.AreEqual (0, rowview ["Sport"], "MC6");
  440. cm.Position++;
  441. rowview = cm.Current as DataRowView;
  442. Assert.IsFalse (rowview == null, "MC7");
  443. Assert.AreEqual (6, rowview ["AthleteID"], "MC8");
  444. Assert.AreEqual ("@jackson", rowview ["AthleteName"], "MC9");
  445. Assert.AreEqual (0, rowview ["Sport"], "MC10");
  446. cm.Position++;
  447. rowview = cm.Current as DataRowView;
  448. Assert.IsFalse (rowview == null, "MC11");
  449. Assert.AreEqual (12, rowview ["AthleteID"], "MC12");
  450. Assert.AreEqual ("@mkestner", rowview ["AthleteName"], "MC13");
  451. Assert.AreEqual (0, rowview ["Sport"], "MC14");
  452. cm.Position++;
  453. rowview = cm.Current as DataRowView;
  454. Assert.IsFalse (rowview == null, "MC15");
  455. Assert.AreEqual (18, rowview ["AthleteID"], "MC16");
  456. Assert.AreEqual ("Demian", rowview ["AthleteName"], "MC17");
  457. Assert.AreEqual (0, rowview ["Sport"], "MC18");
  458. cm.Position++;
  459. rowview = cm.Current as DataRowView;
  460. Assert.IsFalse (rowview == null, "MC19");
  461. Assert.AreEqual (18, rowview ["AthleteID"], "MC20");
  462. Assert.AreEqual ("Demian", rowview ["AthleteName"], "MC21");
  463. Assert.AreEqual (0, rowview ["Sport"], "MC22");
  464. }
  465. private DataSet CreateRelatedDataSet ()
  466. {
  467. DataSet dataset = new DataSet ("DataSet");
  468. DataTable dt1 = new DataTable ("Table1");
  469. DataTable dt2 = new DataTable ("Table2");
  470. DataColumn column;
  471. column = new DataColumn ("One");
  472. column.DataType = typeof (int);
  473. column.Unique = true;
  474. dt1.Columns.Add (column);
  475. for (int i = 0; i < 10; i++) {
  476. DataRow row = dt1.NewRow ();
  477. row ["One"] = i;
  478. dt1.Rows.Add (row);
  479. }
  480. column = new DataColumn ("Two");
  481. column.DataType = typeof (int);
  482. column.Unique = true;
  483. dt2.Columns.Add (column);
  484. for (int i = 0; i < 10; i++) {
  485. DataRow row = dt2.NewRow ();
  486. row ["Two"] = i;
  487. dt2.Rows.Add (row);
  488. }
  489. dataset.Tables.Add (dt1);
  490. dataset.Tables.Add (dt2);
  491. dataset.Relations.Add ("Relation", dt1.Columns ["One"], dt2.Columns ["Two"]);
  492. return dataset;
  493. }
  494. [Test]
  495. public void EndUninitializedEdit ()
  496. {
  497. ArrayList list = new ArrayList ();
  498. BindingContext bc = new BindingContext ();
  499. CurrencyManager cm = bc [list] as CurrencyManager;
  500. cm.EndCurrentEdit ();
  501. }
  502. [Test]
  503. public void CancelUninitializedEdit ()
  504. {
  505. ArrayList list = new ArrayList ();
  506. BindingContext bc = new BindingContext ();
  507. CurrencyManager cm = bc [list] as CurrencyManager;
  508. cm.CancelCurrentEdit ();
  509. }
  510. [Test]
  511. public void CheckPositionOfRelatedSibling1 ()
  512. {
  513. DataSet data_source = CreateRelatedDataSet ();
  514. BindingContext bc = new BindingContext ();
  515. CurrencyManager cm = bc [data_source, "Table1.Relation"] as CurrencyManager;
  516. CurrencyManager scm = bc [data_source, "Table1"] as CurrencyManager;
  517. cm.Position++;
  518. cm.Position++;
  519. // position is not updated
  520. Assert.AreEqual (0, scm.Position, "#8");
  521. }
  522. [Test]
  523. public void CheckPositionOfRelatedSibling2 ()
  524. {
  525. DataSet data_source = CreateRelatedDataSet ();
  526. BindingContext bc = new BindingContext ();
  527. CurrencyManager cm = bc [data_source, "Table1.Relation"] as CurrencyManager;
  528. CurrencyManager scm = bc [data_source, "Table1"] as CurrencyManager;
  529. Assert.AreEqual (0, cm.Position, "#1");
  530. scm.Position++;
  531. Assert.AreEqual (0, cm.Position, "#2");
  532. }
  533. int event_num;
  534. int current_changed;
  535. int position_changed;
  536. int item_changed;
  537. int metadata_changed;
  538. string event_log = "";
  539. ItemChangedEventArgs item_changed_args;
  540. #if NET_2_0
  541. bool list_changed_called;
  542. ListChangedEventArgs list_changed_args;
  543. #endif
  544. void CurrentChanged (object sender, EventArgs args)
  545. {
  546. current_changed = ++event_num;
  547. Console.WriteLine ("current_changed = {0}", current_changed);
  548. //Console.WriteLine (Environment.StackTrace);
  549. event_log += String.Format ("{0}: CurrentChanged\n", current_changed);
  550. }
  551. void PositionChanged (object sender, EventArgs args)
  552. {
  553. position_changed = ++event_num;
  554. Console.WriteLine ("position_changed = {0}", position_changed);
  555. //Console.WriteLine (Environment.StackTrace);
  556. event_log += String.Format ("{0}: PositionChanged (to {1})\n", position_changed, ((CurrencyManager)sender).Position);
  557. }
  558. void ItemChanged (object sender, ItemChangedEventArgs args)
  559. {
  560. item_changed = ++event_num;
  561. item_changed_args = args;
  562. Console.WriteLine ("item_changed = {0}, index = {1}", item_changed, args.Index);
  563. //Console.WriteLine (Environment.StackTrace);
  564. event_log += String.Format ("{0}: ItemChanged (index = {1})\n", item_changed, args.Index);
  565. }
  566. void ListChanged (object sender, ListChangedEventArgs args)
  567. {
  568. Console.WriteLine ("ListChanged ({0},{1},{2})", args.ListChangedType, args.OldIndex, args.NewIndex);
  569. //Console.WriteLine (Environment.StackTrace);
  570. event_log += String.Format (" : ListChanged ({0}, {1}, {2})\n", args.ListChangedType, args.OldIndex, args.NewIndex);
  571. }
  572. void MetaDataChanged (object sender, EventArgs args)
  573. {
  574. metadata_changed = ++event_num;
  575. Console.WriteLine ("metadata_changed = {0}", metadata_changed);
  576. //Console.WriteLine (Environment.StackTrace);
  577. event_log += String.Format ("{0}: MetaDataChanged\n", metadata_changed);
  578. }
  579. #if NET_2_0
  580. // CurrencyManager.ListChanged handler, not IBindingList.ListChanged
  581. void ListChangedEvent (object sender, ListChangedEventArgs args)
  582. {
  583. list_changed_called = true;
  584. list_changed_args = args;
  585. Console.WriteLine ("CurrencyManager.ListChanged ({0},{1},{2})", args.ListChangedType, args.OldIndex, args.NewIndex);
  586. }
  587. #endif
  588. [Test]
  589. public void AddNew ()
  590. {
  591. DataSet data_source = CreateRelatedDataSet ();
  592. BindingContext bc = new BindingContext ();
  593. CurrencyManager cm = bc [data_source, "Table1"] as CurrencyManager;
  594. event_num = current_changed = position_changed = -1;
  595. cm.CurrentChanged += new EventHandler (CurrentChanged);
  596. cm.PositionChanged += new EventHandler (PositionChanged);
  597. cm.ItemChanged += new ItemChangedEventHandler (ItemChanged);
  598. #if NET_2_0
  599. list_changed_called = false;
  600. cm.ListChanged += new ListChangedEventHandler (ListChangedEvent);
  601. #endif
  602. Assert.AreEqual (0, cm.Position, "AddNew1");
  603. Assert.AreEqual (10, cm.Count, "AddNew2");
  604. Assert.AreEqual (cm.Count, cm.List.Count, "AddNew2.5");
  605. cm.AddNew ();
  606. Assert.AreEqual (10, cm.Position, "AddNew3");
  607. Assert.AreEqual (11, cm.Count, "AddNew4");
  608. Assert.AreEqual (cm.Count, cm.List.Count, "AddNew4.5");
  609. Assert.AreEqual (0, item_changed, "AddNew5");
  610. Assert.AreEqual (-1, item_changed_args.Index, "AddNew6");
  611. Assert.AreEqual (1, current_changed, "AddNew7");
  612. Assert.AreEqual (2, position_changed, "AddNew8");
  613. #if NET_2_0
  614. Assert.AreEqual (true, list_changed_called, "AddNew9");
  615. Assert.AreEqual (-1, list_changed_args.OldIndex, "AddNew10");
  616. Assert.AreEqual (10, list_changed_args.NewIndex, "AddNew11");
  617. #endif
  618. cm.CurrentChanged -= new EventHandler (CurrentChanged);
  619. cm.PositionChanged -= new EventHandler (PositionChanged);
  620. #if NET_2_0
  621. cm.ListChanged -= new ListChangedEventHandler (ListChangedEvent);
  622. #endif
  623. }
  624. [Test]
  625. public void CancelAddNew ()
  626. {
  627. if (TestHelper.RunningOnUnix) {
  628. Assert.Ignore ("Fails at the moment");
  629. }
  630. DataSet data_source = CreateRelatedDataSet ();
  631. BindingContext bc = new BindingContext ();
  632. CurrencyManager cm = bc [data_source, "Table1"] as CurrencyManager;
  633. DataView dv = cm.List as DataView;
  634. event_num = current_changed = position_changed = -1;
  635. cm.CurrentChanged += new EventHandler (CurrentChanged);
  636. cm.PositionChanged += new EventHandler (PositionChanged);
  637. cm.ItemChanged += new ItemChangedEventHandler (ItemChanged);
  638. dv.ListChanged += new ListChangedEventHandler (ListChanged);
  639. Assert.AreEqual (0, cm.Position, "CancelAddNew1");
  640. Assert.AreEqual (10, cm.Count, "CancelAddNew2");
  641. Assert.AreEqual (cm.Count, cm.List.Count, "AddNew2.5");
  642. cm.AddNew ();
  643. Assert.AreEqual (0, item_changed, "CancelAddNew3");
  644. Assert.AreEqual (-1, item_changed_args.Index, "CancelAddNew4");
  645. Assert.AreEqual (1, current_changed, "CancelAddNew5");
  646. Assert.AreEqual (2, position_changed, "CancelAddNew6");
  647. cm.CancelCurrentEdit ();
  648. Assert.AreEqual (6, item_changed, "CancelAddNew7");
  649. Assert.AreEqual (9, item_changed_args.Index, "CancelAddNew8");
  650. Assert.AreEqual (3, current_changed, "CancelAddNew9");
  651. Assert.AreEqual (4, position_changed, "CancelAddNew10");
  652. Assert.AreEqual (9, cm.Position, "CancelAddNew11");
  653. Assert.AreEqual (10, cm.Count, "CancelAddNew12");
  654. Assert.AreEqual (cm.Count, cm.List.Count, "AddNew12.5");
  655. cm.CurrentChanged -= new EventHandler (CurrentChanged);
  656. cm.PositionChanged -= new EventHandler (PositionChanged);
  657. }
  658. #if NET_2_0
  659. class CancelAddNewList<T> : Collection<T>, ICancelAddNew
  660. {
  661. public bool EndNewCalled;
  662. public bool CancelNewCalled;
  663. public int LastIndex = -1;
  664. public void EndNew (int index)
  665. {
  666. EndNewCalled = true;
  667. LastIndex = index;
  668. }
  669. public void CancelNew (int index)
  670. {
  671. CancelNewCalled = true;
  672. LastIndex = index;
  673. }
  674. public void Reset ()
  675. {
  676. EndNewCalled = CancelNewCalled = false;
  677. LastIndex = -1;
  678. }
  679. }
  680. // Support for ICancelNew interface
  681. [Test]
  682. public void CancelAddNew2 ()
  683. {
  684. BindingContext bc = new BindingContext ();
  685. CancelAddNewList<int> list = new CancelAddNewList<int> ();
  686. list.Add (4);
  687. list.Add (6);
  688. CurrencyManager cm = (CurrencyManager)bc [list];
  689. Assert.AreEqual (false, list.EndNewCalled, "A1");
  690. Assert.AreEqual (false, list.CancelNewCalled, "A2");
  691. Assert.AreEqual (-1, list.LastIndex, "A3");
  692. cm.CancelCurrentEdit ();
  693. Assert.AreEqual (false, list.EndNewCalled, "B1");
  694. Assert.AreEqual (true, list.CancelNewCalled, "B2");
  695. Assert.AreEqual (0, list.LastIndex, "B3");
  696. cm.Position = 1;
  697. list.Reset ();
  698. cm.CancelCurrentEdit ();
  699. Assert.AreEqual (false, list.EndNewCalled, "C1");
  700. Assert.AreEqual (true, list.CancelNewCalled, "C2");
  701. Assert.AreEqual (1, list.LastIndex, "C3");
  702. }
  703. #endif
  704. [Test]
  705. public void EndAddNew ()
  706. {
  707. #if NET_2_0
  708. if (TestHelper.RunningOnUnix) {
  709. Assert.Ignore ("Fails with 2.0 profile");
  710. }
  711. #endif
  712. DataSet data_source = CreateRelatedDataSet ();
  713. BindingContext bc = new BindingContext ();
  714. CurrencyManager cm = bc [data_source.Tables["Table1"], ""] as CurrencyManager;
  715. data_source.Tables["Table1"].DefaultView.ListChanged +=
  716. new ListChangedEventHandler (DataView_ListChanged);
  717. event_num = current_changed = position_changed = -1;
  718. cm.CurrentChanged += new EventHandler (CurrentChanged);
  719. cm.PositionChanged += new EventHandler (PositionChanged);
  720. cm.ItemChanged += new ItemChangedEventHandler (ItemChanged);
  721. Assert.AreEqual (0, cm.Position, "EndAddNew1");
  722. Assert.AreEqual (10, cm.Count, "EndAddNew2");
  723. cm.AddNew ();
  724. Console.WriteLine ("position = {0}", cm.Position);
  725. Assert.AreEqual (0, item_changed, "EndAddNew3");
  726. Assert.AreEqual (-1, item_changed_args.Index, "EndAddNew4");
  727. Assert.AreEqual (1, current_changed, "EndAddNew5");
  728. Assert.AreEqual (2, position_changed, "EndAddNew6");
  729. cm.EndCurrentEdit ();
  730. Console.WriteLine ("position = {0}", cm.Position);
  731. Assert.AreEqual (3, item_changed, "EndAddNew7");
  732. Assert.AreEqual (-1, item_changed_args.Index, "EndAddNew8");
  733. Assert.AreEqual (1, current_changed, "EndAddNew9");
  734. Assert.AreEqual (2, position_changed, "EndAddNew10");
  735. Assert.AreEqual (10, cm.Position, "EndAddNew11");
  736. Assert.AreEqual (11, cm.Count, "EndAddNew12");
  737. cm.CurrentChanged -= new EventHandler (CurrentChanged);
  738. cm.PositionChanged -= new EventHandler (PositionChanged);
  739. }
  740. void DataView_ListChanged (object sender, ListChangedEventArgs e)
  741. {
  742. Console.WriteLine ("{0} {1} {2}", e.ListChangedType, e.OldIndex, e.NewIndex);
  743. }
  744. #if NET_2_0
  745. // Support for ICancelNew interface
  746. [Test]
  747. public void EndAddNew2 ()
  748. {
  749. BindingContext bc = new BindingContext ();
  750. CancelAddNewList<int> list = new CancelAddNewList<int> ();
  751. list.Add (4);
  752. list.Add (6);
  753. CurrencyManager cm = (CurrencyManager)bc [list];
  754. Assert.AreEqual (false, list.EndNewCalled, "A1");
  755. Assert.AreEqual (false, list.CancelNewCalled, "A2");
  756. Assert.AreEqual (-1, list.LastIndex, "A3");
  757. cm.EndCurrentEdit ();
  758. Assert.AreEqual (true, list.EndNewCalled, "B1");
  759. Assert.AreEqual (false, list.CancelNewCalled, "B2");
  760. Assert.AreEqual (0, list.LastIndex, "B3");
  761. cm.Position = 1;
  762. list.Reset ();
  763. cm.EndCurrentEdit ();
  764. Assert.AreEqual (true, list.EndNewCalled, "C1");
  765. Assert.AreEqual (false, list.CancelNewCalled, "C2");
  766. Assert.AreEqual (1, list.LastIndex, "C3");
  767. }
  768. #endif
  769. [Test]
  770. public void AddNew2 ()
  771. {
  772. if (TestHelper.RunningOnUnix) {
  773. Assert.Ignore ("Fails at the moment due to a System.Data constraint violation");
  774. }
  775. DataSet data_source = CreateRelatedDataSet ();
  776. BindingContext bc = new BindingContext ();
  777. CurrencyManager cm = bc [data_source, "Table1"] as CurrencyManager;
  778. DataView dv = cm.List as DataView;
  779. event_num = current_changed = position_changed = -1;
  780. cm.CurrentChanged += new EventHandler (CurrentChanged);
  781. cm.PositionChanged += new EventHandler (PositionChanged);
  782. cm.ItemChanged += new ItemChangedEventHandler (ItemChanged);
  783. dv.ListChanged += new ListChangedEventHandler (ListChanged);
  784. Assert.AreEqual (0, cm.Position, "AddNew1");
  785. Assert.AreEqual (10, cm.Count, "AddNew2");
  786. cm.AddNew ();
  787. Assert.AreEqual (10, cm.Position, "AddNew3");
  788. Assert.AreEqual (11, cm.Count, "AddNew4");
  789. // this does an implicit EndCurrentEdit
  790. cm.AddNew ();
  791. Assert.AreEqual (11, cm.Position, "AddNew5");
  792. Assert.AreEqual (12, cm.Count, "AddNew6");
  793. }
  794. DataSet CreateRelatedDataSetLarge ()
  795. {
  796. DataSet dataset = new DataSet ("CustomerSet");
  797. DataTable dt1 = new DataTable ("Customers");
  798. DataTable dt2 = new DataTable ("Orders");
  799. DataTable dt3 = new DataTable ("Addresses");
  800. DataColumn column;
  801. // customer table
  802. column = new DataColumn ("CustomerID");
  803. column.DataType = typeof (int);
  804. column.Unique = true;
  805. dt1.Columns.Add (column);
  806. column = new DataColumn ("CustomerName");
  807. column.DataType = typeof (string);
  808. column.Unique = false;
  809. dt1.Columns.Add (column);
  810. // order table
  811. column = new DataColumn ("OrderID");
  812. column.DataType = typeof (int);
  813. column.Unique = true;
  814. dt2.Columns.Add (column);
  815. column = new DataColumn ("ItemName");
  816. column.DataType = typeof (string);
  817. column.Unique = false;
  818. dt2.Columns.Add (column);
  819. column = new DataColumn ("CustomerID");
  820. column.DataType = typeof (int);
  821. column.Unique = false;
  822. dt2.Columns.Add (column);
  823. column = new DataColumn ("AddressID");
  824. column.DataType = typeof (int);
  825. column.Unique = false;
  826. dt2.Columns.Add (column);
  827. // address table
  828. column = new DataColumn ("AddressID");
  829. column.DataType = typeof (int);
  830. column.Unique = true;
  831. dt3.Columns.Add (column);
  832. column = new DataColumn ("AddressString");
  833. column.DataType = typeof (string);
  834. column.Unique = false;
  835. dt3.Columns.Add (column);
  836. column = new DataColumn ("CustomerID");
  837. column.DataType = typeof (int);
  838. column.Unique = false;
  839. dt3.Columns.Add (column);
  840. for (int i = 0; i < 10; i ++) {
  841. DataRow row = dt1.NewRow ();
  842. row["CustomerID"] = i;
  843. row["CustomerName"] = String.Format ("Customer Name #{0}", i);
  844. dt1.Rows.Add (row);
  845. }
  846. int ordernum = 0;
  847. for (int i = 0; i < 10; i ++) {
  848. for (int j = 0; j < (i < 5 ? 3 : 5); j ++) {
  849. DataRow row = dt2.NewRow ();
  850. row["OrderID"] = ordernum++;
  851. row["ItemName"] = String.Format ("Item order #{0}", j);
  852. row["CustomerID"] = i;
  853. row["AddressID"] = j;
  854. dt2.Rows.Add (row);
  855. }
  856. }
  857. int addressid = 0;
  858. for (int i = 0; i < 4; i ++) {
  859. for (int j = 0; j < 4; j ++) {
  860. DataRow row = dt3.NewRow ();
  861. row["AddressID"] = addressid++;
  862. row["AddressString"] = String.Format ("Customer Address {0}", j);
  863. row["CustomerID"] = i;
  864. dt3.Rows.Add (row);
  865. }
  866. }
  867. dataset.Tables.Add (dt1);
  868. dataset.Tables.Add (dt2);
  869. dataset.Tables.Add (dt3);
  870. dataset.Relations.Add ("Customer_Orders", dt1.Columns["CustomerID"], dt2.Columns["CustomerID"]);
  871. dataset.Relations.Add ("Customer_Addresses", dt1.Columns["CustomerID"], dt3.Columns["CustomerID"]);
  872. dataset.Relations.Add ("Address_Orders", dt3.Columns["AddressID"], dt2.Columns["AddressID"]);
  873. return dataset;
  874. }
  875. [Test]
  876. public void RelatedCurrencyManagerTest ()
  877. {
  878. DataSet data_source = CreateRelatedDataSetLarge ();
  879. BindingContext bc = new BindingContext ();
  880. CurrencyManager cm = bc [data_source, "Customers"] as CurrencyManager;
  881. CurrencyManager rcm = bc [data_source, "Customers.Customer_Orders"] as CurrencyManager;
  882. IList list = rcm.List;
  883. Assert.AreEqual (3, rcm.Count, "count1");
  884. Assert.AreEqual (3, list.Count, "listcount1");
  885. cm.Position = 1;
  886. Assert.AreEqual (3, rcm.Count, "count2");
  887. Assert.AreEqual (3, list.Count, "listcount2");
  888. cm.Position = 5;
  889. Assert.AreEqual (5, rcm.Count, "count3");
  890. Assert.AreEqual (3, list.Count, "listcount3");
  891. }
  892. [Test]
  893. public void TestCurrencyManagerBindings ()
  894. {
  895. DataSet data_source = CreateRelatedDataSetLarge ();
  896. BindingContext bc = new BindingContext ();
  897. CurrencyManager cm = bc [data_source] as CurrencyManager;
  898. Console.WriteLine ("cm properties:");
  899. foreach (PropertyDescriptor pd in cm.GetItemProperties ())
  900. Console.WriteLine (" + {0}", pd.Name);
  901. Console.WriteLine ();
  902. Console.WriteLine ("dataset:");
  903. Console.WriteLine ("cm = {0}", cm.GetType());
  904. Console.WriteLine ("cm.Count = {0}", cm.Count);
  905. cm.Position = 0;
  906. Console.WriteLine ("cm.Current = {0}", cm.Current);
  907. Console.WriteLine ("cm.Current properties");
  908. foreach (PropertyDescriptor pd in ((ICustomTypeDescriptor)cm.Current).GetProperties ())
  909. Console.WriteLine (" + {0}", pd.Name);
  910. Console.WriteLine ();
  911. cm = bc [data_source.Tables["Customers"]] as CurrencyManager;
  912. Console.WriteLine ("datatable:");
  913. Console.WriteLine ("cm = {0}", cm.GetType());
  914. Console.WriteLine ("cm.Count = {0}", cm.Count);
  915. cm.Position = 0;
  916. Console.WriteLine ("cm.Current = {0}", cm.Current);
  917. Console.WriteLine ("cm.Current properties");
  918. foreach (PropertyDescriptor pd in ((ICustomTypeDescriptor)cm.Current).GetProperties ())
  919. Console.WriteLine (" + {0}", pd.Name);
  920. Console.WriteLine ();
  921. DataViewManager vm = new DataViewManager (data_source);
  922. Console.WriteLine ("vm properties:");
  923. foreach (PropertyDescriptor pd in ((ITypedList)vm).GetItemProperties (null))
  924. Console.WriteLine (" + {0}", pd.Name);
  925. Console.WriteLine ();
  926. }
  927. Type GetFinalType (CurrencyManager cm)
  928. {
  929. FieldInfo fi = cm.GetType().GetField ("finalType", BindingFlags.NonPublic | BindingFlags.Instance);
  930. return (Type)fi.GetValue (cm);
  931. }
  932. [Test]
  933. public void FinalTypeTest ()
  934. {
  935. BindingContext bc = new BindingContext ();
  936. CurrencyManager cm;
  937. ArrayList al;
  938. DataSet data_source = CreateRelatedDataSetLarge ();
  939. /* empty arraylist */
  940. al = new ArrayList ();
  941. cm = bc[al] as CurrencyManager;
  942. Assert.AreEqual (typeof (ArrayList), GetFinalType (cm), "A1");
  943. /* arraylist with a string element*/
  944. al = new ArrayList ();
  945. al.Add ("hi");
  946. cm = bc[al] as CurrencyManager;
  947. Assert.AreEqual (typeof (ArrayList), GetFinalType (cm), "A2");
  948. /* string array */
  949. string[] s = new string[1];
  950. s[0] = "hi";
  951. cm = bc[s] as CurrencyManager;
  952. Assert.AreEqual (typeof (string[]), GetFinalType (cm), "A3");
  953. /* dataview */
  954. cm = bc [data_source, "Customers"] as CurrencyManager;
  955. Assert.AreEqual (typeof (DataView), GetFinalType (cm), "A4");
  956. /* relatedview */
  957. cm = bc [data_source, "Customers.Customer_Orders"] as CurrencyManager;
  958. /* on MS this is a RelatedView, on Mono a RelatedDataView. both subclass from DataView, so let's check that. */
  959. Assert.IsFalse (typeof (DataView) == GetFinalType (cm), "A5");
  960. Assert.IsTrue (typeof (DataView).IsAssignableFrom (GetFinalType (cm)), "A6");
  961. }
  962. #if NET_2_0
  963. [Test]
  964. public void ListChangedEventTest ()
  965. {
  966. Control c = new Control ();
  967. c.BindingContext = new BindingContext ();
  968. c.CreateControl ();
  969. BindingListChild<MockItem> binding_list = new BindingListChild<MockItem> ();
  970. CurrencyManager currency_manager = (CurrencyManager)c.BindingContext [binding_list];
  971. currency_manager.ListChanged += new ListChangedEventHandler(ListChangedEvent);
  972. ClearListChangedLog ();
  973. MockItem item = binding_list.AddNew ();
  974. binding_list.EndNew (binding_list.IndexOf (item));
  975. Assert.IsTrue (list_changed_called, "#A1");
  976. Assert.AreEqual (ListChangedType.ItemAdded, list_changed_args.ListChangedType, "#A2");
  977. ClearListChangedLog ();
  978. binding_list.Insert (0, new MockItem ());
  979. Assert.IsTrue (list_changed_called, "#B1");
  980. Assert.AreEqual (ListChangedType.ItemAdded, list_changed_args.ListChangedType, "#B2");
  981. ClearListChangedLog ();
  982. binding_list.RemoveAt (0);
  983. Assert.IsTrue (list_changed_called, "#D1");
  984. Assert.AreEqual (ListChangedType.ItemDeleted, list_changed_args.ListChangedType, "#D2");
  985. ClearListChangedLog ();
  986. binding_list [0] = new MockItem ();
  987. Assert.IsTrue (list_changed_called, "#E1");
  988. Assert.AreEqual (ListChangedType.ItemChanged, list_changed_args.ListChangedType, "#E2");
  989. ClearListChangedLog ();
  990. binding_list.DoResetItem (0);
  991. Assert.IsTrue (list_changed_called, "#F1");
  992. Assert.AreEqual (ListChangedType.ItemChanged, list_changed_args.ListChangedType, "#F2");
  993. ClearListChangedLog ();
  994. binding_list.DoResetBinding ();
  995. Assert.IsTrue (list_changed_called, "#G1");
  996. Assert.AreEqual (ListChangedType.Reset, list_changed_args.ListChangedType, "#G2");
  997. binding_list.Clear ();
  998. Assert.IsTrue (list_changed_called, "#F1");
  999. Assert.AreEqual (ListChangedType.Reset, list_changed_args.ListChangedType, "#F2");
  1000. currency_manager.ListChanged -= ListChangedEvent;
  1001. }
  1002. void ClearListChangedLog ()
  1003. {
  1004. list_changed_called = false;
  1005. list_changed_args = null;
  1006. }
  1007. public class BindingListChild<T> : BindingList<T>
  1008. {
  1009. public void DoResetItem (int position)
  1010. {
  1011. ResetItem (position);
  1012. }
  1013. public void DoResetBinding ()
  1014. {
  1015. ResetBindings ();
  1016. }
  1017. }
  1018. #endif
  1019. }
  1020. }