ConstraintCollectionTest.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // ConstraintCollection.cs - NUnit Test Cases for testing the ConstraintCollection
  2. // class.
  3. //
  4. //
  5. // Franklin Wise ([email protected])
  6. //
  7. // (C) Franklin Wise
  8. //
  9. using NUnit.Framework;
  10. using System;
  11. using System.Data;
  12. namespace MonoTests.System.Data
  13. {
  14. public class ConstraintCollectionTest : TestCase
  15. {
  16. private DataTable _table;
  17. private Constraint _constraint1;
  18. private Constraint _constraint2;
  19. public ConstraintCollectionTest() : base ("MonoTests.System.Data.ConstraintCollectionTest") {}
  20. public ConstraintCollectionTest(string name) : base(name) {}
  21. public void PublicSetup(){SetUp();}
  22. protected override void SetUp()
  23. {
  24. //Setup DataTable
  25. _table = new DataTable("TestTable");
  26. _table.Columns.Add("Col1",typeof(int));
  27. _table.Columns.Add("Col2",typeof(int));
  28. //Use UniqueConstraint to test Constraint Base Class
  29. _constraint1 = new UniqueConstraint(_table.Columns[0],false);
  30. _constraint2 = new UniqueConstraint(_table.Columns[1],false);
  31. }
  32. protected override void TearDown() {}
  33. public static ITest Suite
  34. {
  35. get
  36. {
  37. return new TestSuite(typeof(ConstraintCollectionTest));
  38. }
  39. }
  40. public void TestAdd()
  41. {
  42. ConstraintCollection col = _table.Constraints;
  43. col.Add(_constraint1);
  44. col.Add(_constraint2);
  45. Assertion.AssertEquals("Count doesn't equal added.",2, col.Count);
  46. }
  47. public void TestAddExceptions()
  48. {
  49. ConstraintCollection col = _table.Constraints;
  50. try
  51. {
  52. col.Add(null);
  53. Assertion.Fail("B1: Failed to throw ArgumentNullException.");
  54. }
  55. catch (ArgumentNullException) {}
  56. catch (AssertionFailedError exc) {throw exc;}
  57. catch
  58. {
  59. Assertion.Fail("A1: Wrong exception type");
  60. }
  61. try
  62. {
  63. _constraint1.ConstraintName = "Dog";
  64. _constraint2.ConstraintName = "dog"; //case insensitive
  65. col.Add(_constraint1);
  66. col.Add(_constraint2);
  67. Assertion.Fail("Failed to throw Duplicate name exception.");
  68. }
  69. catch (DuplicateNameException) {}
  70. catch (AssertionFailedError exc) {throw exc;}
  71. catch (Exception exc)
  72. {
  73. Assertion.Fail("A2: Wrong exception type. " + exc.ToString());
  74. }
  75. //Constraint Already exists
  76. try
  77. {
  78. col.Add(_constraint1);
  79. Assertion.Fail("B2: Failed to throw ArgumentException.");
  80. }
  81. catch (ArgumentException) {}
  82. catch (AssertionFailedError exc) {throw exc;}
  83. catch
  84. {
  85. Assertion.Fail("A3: Wrong exception type");
  86. }
  87. }
  88. public void TestRemoveExceptions()
  89. {
  90. }
  91. }
  92. }