PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/mcs/class/WindowsBase/Test/System.Collections.Specialized/NotifyCollectionChangedEventArgsTest.cs

https://bitbucket.org/foobar22/mono
C# | 712 lines | 434 code | 136 blank | 142 comment | 0 complexity | 2fdeb3388e413d46b08894ea951895ae MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0, Unlicense, Apache-2.0, LGPL-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. // Authors:
  21. // Brian O'Keefe (zer0keefie@gmail.com)
  22. //
  23. using System;
  24. using System.Collections;
  25. using System.Collections.Generic;
  26. using System.Collections.Specialized;
  27. using NUnit.Framework;
  28. namespace MonoTests.System.Collections.Specialized {
  29. [TestFixture]
  30. public class NotifyCollectionChangedEventArgsTest {
  31. public NotifyCollectionChangedEventArgsTest()
  32. {
  33. }
  34. [Test]
  35. public void NotifyCollectionChangedEventArgsConstructor1Test()
  36. {
  37. /* Expected Behavior:
  38. *
  39. * If action is Reset, success.
  40. * If action is not Reset, throw an ArgumentException
  41. */
  42. // Trying with Reset
  43. NotifyCollectionChangedEventArgs args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset);
  44. CollectionChangedEventValidators.ValidateResetOperation (args, "#A01");
  45. // Trying with Add
  46. try {
  47. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add);
  48. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Add.");
  49. } catch (ArgumentException) {
  50. }
  51. // Trying with Remove
  52. try {
  53. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove);
  54. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Remove.");
  55. } catch (ArgumentException) {
  56. }
  57. // Trying with Move
  58. try {
  59. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Move);
  60. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Move.");
  61. } catch (ArgumentException) {
  62. }
  63. // Trying with Replace
  64. try {
  65. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace);
  66. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Replace.");
  67. } catch (ArgumentException) {
  68. }
  69. }
  70. [Test]
  71. public void NotifyCollectionChangedEventArgsConstructor2Test()
  72. {
  73. /* Expected Behavior:
  74. *
  75. * If action is Add, success.
  76. * If action is Remove, success.
  77. * If action is Reset:
  78. * If changedItems is null, success.
  79. * If changedItems is non-null, throw an Argument Exception
  80. * If action is Move or Replace, throw an Argument Exception
  81. */
  82. IList changedItems = new List<object> ();
  83. // Trying with Add
  84. NotifyCollectionChangedEventArgs args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, changedItems);
  85. CollectionChangedEventValidators.ValidateAddOperation (args, changedItems, "#B01");
  86. // Trying to add a null array
  87. try {
  88. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, (IList)null);
  89. Assert.Fail ("Cannot call .ctor if changedItems is null.");
  90. } catch (ArgumentNullException) {
  91. }
  92. // Trying with Remove
  93. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, changedItems);
  94. CollectionChangedEventValidators.ValidateRemoveOperation (args, changedItems, "#B02");
  95. // Trying with Reset (works if changedItems is null)
  96. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, (IList)null);
  97. CollectionChangedEventValidators.ValidateResetOperation (args, "#B03");
  98. try {
  99. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, changedItems);
  100. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset.");
  101. } catch (ArgumentException) {
  102. }
  103. // Trying with Move
  104. try {
  105. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Move, changedItems);
  106. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Move.");
  107. } catch (ArgumentException) {
  108. }
  109. // Trying with Replace
  110. try {
  111. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, changedItems);
  112. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Replace.");
  113. } catch (ArgumentException) {
  114. }
  115. // Add some items, and repeat
  116. changedItems.Add (new object ());
  117. changedItems.Add (new object ());
  118. changedItems.Add (new object ());
  119. // Trying with Add
  120. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, changedItems);
  121. CollectionChangedEventValidators.ValidateAddOperation (args, changedItems, "#B04");
  122. // Trying with Remove
  123. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, changedItems);
  124. CollectionChangedEventValidators.ValidateRemoveOperation (args, changedItems, "#B05");
  125. }
  126. [Test]
  127. public void NotifyCollectionChangedEventArgsConstructor3Test()
  128. {
  129. /* Expected Behavior:
  130. *
  131. * If action is Add, success.
  132. * If action is Remove, success.
  133. * If action is Reset:
  134. * If changedItem is null, success.
  135. * If changedItem is non-null, throw an Argument Exception
  136. * If action is Move or Replace, throw an Argument Exception
  137. */
  138. object changedItem = new object ();
  139. // Trying with Add
  140. NotifyCollectionChangedEventArgs args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, changedItem);
  141. CollectionChangedEventValidators.ValidateAddOperation (args, new object [] { changedItem }, "#C01");
  142. // Trying with Remove
  143. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, changedItem);
  144. CollectionChangedEventValidators.ValidateRemoveOperation (args, new object [] { changedItem }, "#C02");
  145. // Trying with Reset
  146. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, (object)null);
  147. CollectionChangedEventValidators.ValidateResetOperation (args, "#C03");
  148. try {
  149. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, changedItem);
  150. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset.");
  151. } catch (ArgumentException) {
  152. }
  153. // Trying with Move
  154. try {
  155. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Move, changedItem);
  156. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Move.");
  157. } catch (ArgumentException) {
  158. }
  159. // Trying with Replace
  160. try {
  161. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, changedItem);
  162. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Replace.");
  163. } catch (ArgumentException) {
  164. }
  165. }
  166. [Test]
  167. public void NotifyCollectionChangedEventArgsConstructor4Test()
  168. {
  169. /* Expected Behavior:
  170. *
  171. * If action is Replace:
  172. * If newItems is null, throw an ArgumentNullException.
  173. * If oldItems is null, throw an ArgumentNullException
  174. * Otherwise, success.
  175. * If action is not Replace, throw an ArgumentException
  176. */
  177. IList newItems = new List<object> ();
  178. IList oldItems = new List<object> ();
  179. // Trying with Replace
  180. NotifyCollectionChangedEventArgs args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, newItems, oldItems);
  181. CollectionChangedEventValidators.ValidateReplaceOperation (args, oldItems, newItems, "#D01");
  182. // Add some items to test this one.
  183. newItems.Add (new object ());
  184. newItems.Add (new object ());
  185. newItems.Add (new object ());
  186. // Trying with Replace again
  187. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, newItems, oldItems);
  188. CollectionChangedEventValidators.ValidateReplaceOperation (args, oldItems, newItems, "#D02");
  189. // Add some more items to test this one.
  190. oldItems.Add (new object ());
  191. oldItems.Add (new object ());
  192. oldItems.Add (new object ());
  193. // Trying with Replace again
  194. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, newItems, oldItems);
  195. CollectionChangedEventValidators.ValidateReplaceOperation (args, oldItems, newItems, "#D03");
  196. // Trying with null arguments.
  197. try {
  198. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, (IList)null, oldItems);
  199. Assert.Fail ("The newItems argument cannot be null.");
  200. } catch (ArgumentNullException) {
  201. }
  202. try {
  203. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, newItems, (IList)null);
  204. Assert.Fail ("The oldItems argument cannot be null.");
  205. } catch (ArgumentNullException) {
  206. }
  207. // Trying with Reset
  208. try {
  209. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, newItems, oldItems);
  210. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset.");
  211. } catch (ArgumentException) {
  212. }
  213. // Trying with Move
  214. try {
  215. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Move, newItems, oldItems);
  216. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Move.");
  217. } catch (ArgumentException) {
  218. }
  219. // Trying with Add
  220. try {
  221. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, newItems, oldItems);
  222. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Add.");
  223. } catch (ArgumentException) {
  224. }
  225. // Trying with Remove
  226. try {
  227. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, newItems, oldItems);
  228. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Remove.");
  229. } catch (ArgumentException) {
  230. }
  231. }
  232. [Test]
  233. public void NotifyCollectionChangedEventArgsConstructor5Test()
  234. {
  235. /* Expected Behavior:
  236. *
  237. * If action is Add or Remove:
  238. * If changedItems is null, throw an ArgumentNullException.
  239. * If startingIndex < -1, throw an ArgumentException
  240. * Otherwise, success.
  241. * If action is Reset:
  242. * If changedItems is non-null, throw an ArgumentException
  243. * If startingIndex != 0, throw an ArgumentException
  244. * Otherwise, success.
  245. * If action is Move or Replace, throw an ArgumentException
  246. */
  247. IList changedItems = new List<object> ();
  248. int startingIndex = 5; // Doesn't matter what the value of this is.
  249. // Trying with Add
  250. NotifyCollectionChangedEventArgs args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, changedItems, startingIndex);
  251. CollectionChangedEventValidators.ValidateAddOperation (args, changedItems, startingIndex, "#E01");
  252. // Trying with Remove
  253. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, changedItems, startingIndex);
  254. CollectionChangedEventValidators.ValidateRemoveOperation (args, changedItems, startingIndex, "#E02");
  255. // Add some items to test this one.
  256. changedItems.Add (new object ());
  257. changedItems.Add (new object ());
  258. changedItems.Add (new object ());
  259. // Trying with Add
  260. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, changedItems, startingIndex);
  261. CollectionChangedEventValidators.ValidateAddOperation (args, changedItems, startingIndex, "#E03");
  262. try {
  263. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, changedItems, -5);
  264. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Add if startingIndex < -1.");
  265. } catch (ArgumentException) {
  266. }
  267. try {
  268. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, (IList)null, startingIndex);
  269. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Add if changedItems is null.");
  270. } catch (ArgumentNullException) {
  271. }
  272. // Trying with Remove
  273. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, changedItems, startingIndex);
  274. CollectionChangedEventValidators.ValidateRemoveOperation (args, changedItems, startingIndex, "#E04");
  275. try {
  276. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, changedItems, -5);
  277. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Remove if startingIndex < -1.");
  278. } catch (ArgumentException) {
  279. }
  280. try {
  281. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, (IList)null, startingIndex);
  282. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Remove if changedItems is null.");
  283. } catch (ArgumentNullException) {
  284. }
  285. // Trying with Reset
  286. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, (IList)null, -1);
  287. try {
  288. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, changedItems, -1);
  289. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset unless changeItems is null");
  290. } catch (ArgumentException) {
  291. }
  292. try {
  293. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, (IList)null, 1);
  294. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset unless startingIndex is -1");
  295. } catch (ArgumentException) {
  296. }
  297. try {
  298. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, changedItems, startingIndex);
  299. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset.");
  300. } catch (ArgumentException) {
  301. }
  302. // Trying with Move
  303. try {
  304. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Move, changedItems, startingIndex);
  305. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Move.");
  306. } catch (ArgumentException) {
  307. }
  308. // Trying with Replace
  309. try {
  310. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, changedItems, startingIndex);
  311. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Replace.");
  312. } catch (ArgumentException) {
  313. }
  314. }
  315. [Test]
  316. public void NotifyCollectionChangedEventArgsConstructor6Test()
  317. {
  318. object changedItem = new object ();
  319. int startingIndex = 5; // Doesn't matter what the value of this is.
  320. // Trying with Add
  321. NotifyCollectionChangedEventArgs args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, changedItem, startingIndex);
  322. CollectionChangedEventValidators.ValidateAddOperation (args, new object [] { changedItem }, startingIndex, "#F01");
  323. // Trying with Remove
  324. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, changedItem, startingIndex);
  325. CollectionChangedEventValidators.ValidateRemoveOperation (args, new object [] { changedItem }, startingIndex, "#F02");
  326. // Trying with Reset
  327. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, (object)null, -1);
  328. CollectionChangedEventValidators.ValidateResetOperation (args, "#F03");
  329. try {
  330. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, changedItem, -1);
  331. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset unless changeItems is null");
  332. } catch (ArgumentException) {
  333. }
  334. try {
  335. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, (object)null, 1);
  336. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset unless startingIndex is -1");
  337. } catch (ArgumentException) {
  338. }
  339. try {
  340. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, changedItem, startingIndex);
  341. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset.");
  342. } catch (ArgumentException) {
  343. }
  344. // Trying with Move
  345. try {
  346. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Move, changedItem, startingIndex);
  347. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Move.");
  348. } catch (ArgumentException) {
  349. }
  350. // Trying with Replace
  351. try {
  352. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, changedItem, startingIndex);
  353. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Replace.");
  354. } catch (ArgumentException) {
  355. }
  356. }
  357. [Test]
  358. public void NotifyCollectionChangedEventArgsConstructor7Test()
  359. {
  360. object oldItem = new object ();
  361. object newItem = new object (); // Doesn't matter what the value of this is.
  362. // Trying with Add
  363. NotifyCollectionChangedEventArgs args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, newItem, oldItem);
  364. CollectionChangedEventValidators.ValidateReplaceOperation (args, new object [] { oldItem }, new object [] { newItem }, "#G01");
  365. // Trying null items
  366. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, (object)null, oldItem);
  367. CollectionChangedEventValidators.ValidateReplaceOperation (args, new object [] { oldItem }, new object [] { null }, "#G02");
  368. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, newItem, (object)null);
  369. CollectionChangedEventValidators.ValidateReplaceOperation (args, new object [] { null }, new object [] { newItem }, "#G03");
  370. // Trying with Reset
  371. try {
  372. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, newItem, oldItem);
  373. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset.");
  374. } catch (ArgumentException) {
  375. }
  376. // Trying with Move
  377. try {
  378. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Move, newItem, oldItem);
  379. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Move.");
  380. } catch (ArgumentException) {
  381. }
  382. // Trying with Add
  383. try {
  384. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, newItem, oldItem);
  385. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Add.");
  386. } catch (ArgumentException) {
  387. }
  388. // Trying with Remove
  389. try {
  390. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, newItem, oldItem);
  391. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Remove.");
  392. } catch (ArgumentException) {
  393. }
  394. }
  395. [Test]
  396. public void NotifyCollectionChangedEventArgsConstructor8Test()
  397. {
  398. IList newItems = new List<object> ();
  399. IList oldItems = new List<object> ();
  400. int startIndex = 5;
  401. // Trying with Replace
  402. NotifyCollectionChangedEventArgs args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, newItems, oldItems, startIndex);
  403. CollectionChangedEventValidators.ValidateReplaceOperation (args, oldItems, newItems, startIndex, "#H01");
  404. // Add some items to test this one.
  405. newItems.Add (new object ());
  406. newItems.Add (new object ());
  407. newItems.Add (new object ());
  408. // Trying with Replace again
  409. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, newItems, oldItems, startIndex);
  410. CollectionChangedEventValidators.ValidateReplaceOperation (args, oldItems, newItems, startIndex, "#H02");
  411. // Add some more items to test this one.
  412. oldItems.Add (new object ());
  413. oldItems.Add (new object ());
  414. oldItems.Add (new object ());
  415. // Trying with Replace again
  416. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, newItems, oldItems, startIndex);
  417. CollectionChangedEventValidators.ValidateReplaceOperation (args, oldItems, newItems, startIndex, "#H03");
  418. // Trying with null arguments.
  419. try {
  420. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, (IList)null, oldItems, startIndex);
  421. Assert.Fail ("The newItems argument cannot be null.");
  422. } catch (ArgumentNullException) {
  423. }
  424. try {
  425. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, newItems, (IList)null, startIndex);
  426. Assert.Fail ("The oldItems argument cannot be null.");
  427. } catch (ArgumentNullException) {
  428. }
  429. // Trying with Reset
  430. try {
  431. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, newItems, oldItems, startIndex);
  432. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset.");
  433. } catch (ArgumentException) {
  434. }
  435. // Trying with Move
  436. try {
  437. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Move, newItems, oldItems, startIndex);
  438. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Move.");
  439. } catch (ArgumentException) {
  440. }
  441. // Trying with Add
  442. try {
  443. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, newItems, oldItems, startIndex);
  444. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Add.");
  445. } catch (ArgumentException) {
  446. }
  447. // Trying with Remove
  448. try {
  449. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, newItems, oldItems);
  450. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Remove.");
  451. } catch (ArgumentException) {
  452. }
  453. }
  454. [Test]
  455. public void NotifyCollectionChangedEventArgsConstructor9Test()
  456. {
  457. IList changed = new List<object> ();
  458. int newIndex = 2;
  459. int oldIndex = 5;
  460. // Trying with Replace
  461. NotifyCollectionChangedEventArgs args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Move, changed, newIndex, oldIndex);
  462. CollectionChangedEventValidators.ValidateMoveOperation (args, changed, newIndex, oldIndex, "#I01");
  463. // Add some items to test this one.
  464. changed.Add (new object ());
  465. changed.Add (new object ());
  466. changed.Add (new object ());
  467. // Trying with Replace again
  468. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Move, changed, newIndex, oldIndex);
  469. CollectionChangedEventValidators.ValidateMoveOperation (args, changed, newIndex, oldIndex, "#I02");
  470. // Trying with newIndex < 0.
  471. try {
  472. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Move, changed, -5, oldIndex);
  473. Assert.Fail ("The index argument cannot be less than 0.");
  474. } catch (ArgumentException) {
  475. }
  476. // Trying with Reset
  477. try {
  478. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, changed, newIndex, oldIndex);
  479. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset.");
  480. } catch (ArgumentException) {
  481. }
  482. // Trying with Replace
  483. try {
  484. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, changed, newIndex, oldIndex);
  485. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Replace.");
  486. } catch (ArgumentException) {
  487. }
  488. // Trying with Add
  489. try {
  490. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, changed, newIndex, oldIndex);
  491. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Add.");
  492. } catch (ArgumentException) {
  493. }
  494. // Trying with Remove
  495. try {
  496. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, changed, newIndex, oldIndex);
  497. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Remove.");
  498. } catch (ArgumentException) {
  499. }
  500. }
  501. [Test]
  502. public void NotifyCollectionChangedEventArgsConstructor10Test()
  503. {
  504. object changed = new object ();
  505. int newIndex = 2;
  506. int oldIndex = 5;
  507. // Trying with Replace
  508. NotifyCollectionChangedEventArgs args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Move, changed, newIndex, oldIndex);
  509. CollectionChangedEventValidators.ValidateMoveOperation (args, new object [] { changed }, newIndex, oldIndex, "#J01");
  510. // Trying with newIndex < 0.
  511. try {
  512. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Move, changed, -5, oldIndex);
  513. Assert.Fail ("The newIndex argument cannot be less than 0.");
  514. } catch (ArgumentException) {
  515. }
  516. // Trying with Reset
  517. try {
  518. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, changed, newIndex, oldIndex);
  519. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset.");
  520. } catch (ArgumentException) {
  521. }
  522. // Trying with Replace
  523. try {
  524. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, changed, newIndex, oldIndex);
  525. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Replace.");
  526. } catch (ArgumentException) {
  527. }
  528. // Trying with Add
  529. try {
  530. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, changed, newIndex, oldIndex);
  531. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Add.");
  532. } catch (ArgumentException) {
  533. }
  534. // Trying with Remove
  535. try {
  536. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, changed, newIndex, oldIndex);
  537. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Remove.");
  538. } catch (ArgumentException) {
  539. }
  540. }
  541. [Test]
  542. public void NotifyCollectionChangedEventArgsConstructor11Test()
  543. {
  544. object newItem = new object ();
  545. object oldItem = new object ();
  546. int startIndex = 5;
  547. // Trying with Replace
  548. NotifyCollectionChangedEventArgs args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Replace, newItem, oldItem, startIndex);
  549. CollectionChangedEventValidators.ValidateReplaceOperation (args, new object [] { oldItem }, new object [] { newItem }, startIndex, "#K01");
  550. // Trying with Reset
  551. try {
  552. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset, newItem, oldItem, startIndex);
  553. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Reset.");
  554. } catch (ArgumentException) {
  555. }
  556. // Trying with Move
  557. try {
  558. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Move, newItem, oldItem, startIndex);
  559. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Move.");
  560. } catch (ArgumentException) {
  561. }
  562. // Trying with Add
  563. try {
  564. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, newItem, oldItem, startIndex);
  565. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Add.");
  566. } catch (ArgumentException) {
  567. }
  568. // Trying with Remove
  569. try {
  570. args = new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, newItem, oldItem);
  571. Assert.Fail ("Should not be able to call .ctor with NotifyCollectionChangedAction.Remove.");
  572. } catch (ArgumentException) {
  573. }
  574. }
  575. }
  576. }