// ConstraintTest.cs - NUnit Test Cases for testing the abstract class System.Data.Constraint
// The tests use an inherited class (UniqueConstraint) to test the Constraint class.
//
-// Franklin Wise <gracenote@earthlink.net>
+// Authors:
+// Franklin Wise <gracenote@earthlink.net>
+// Martin Willemoes Hansen <mwh@sysrq.dk>
//
// (C) 2002 Franklin Wise
+// (C) 2003 Martin Willemoes Hansen
//
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
using NUnit.Framework;
using System;
using System.Data;
// }
// }
- public class ConstraintTest : TestCase
+ [TestFixture]
+ public class ConstraintTest : Assertion
{
private DataTable _table;
private Constraint _constraint1;
private Constraint _constraint2;
- public ConstraintTest() : base ("MonoTests.System.Data.ConstraintTest") {}
- public ConstraintTest(string name) : base(name) {}
-
- public void PublicSetup(){SetUp();}
- protected override void SetUp() {
+ [SetUp]
+ public void GetReady() {
//Setup DataTable
_table = new DataTable("TestTable");
+
_table.Columns.Add("Col1",typeof(int));
_table.Columns.Add("Col2",typeof(int));
_constraint1 = new UniqueConstraint(_table.Columns[0],false);
_constraint2 = new UniqueConstraint(_table.Columns[1],false);
+ // not sure why this is needed since a new _table was just created
+ // for us, but this Clear() keeps the tests from throwing
+ // an exception when the Add() is called.
+ _table.Constraints.Clear();
}
-
- protected override void TearDown() {}
-
- public static ITest Suite {
- get {
- return new TestSuite(typeof(ConstraintTest));
- }
- }
-
- public void TestSetConstraintNameNullOrEmptyExceptions() {
+ [Test]
+ public void SetConstraintNameNullOrEmptyExceptions() {
bool exceptionCaught = false;
string name = null;
_table.Constraints.Add (_constraint1);
- Console.WriteLine(_constraint1.ConstraintName);
-
for (int i = 0; i <= 1; i++) {
exceptionCaught = false;
if (0 == i) name = null;
exceptionCaught = true;
}
catch {
- Assertion.Fail("Wrong exception type thrown.");
+ Fail("Wrong exception type thrown.");
}
- Assertion.Assert("Failed to throw exception.",
+ Assert("Failed to throw exception.",
true == exceptionCaught);
}
}
- public void TestSetConstraintNameDuplicateException() {
+ [Test]
+ [ExpectedException (typeof (DuplicateNameException))]
+ public void SetConstraintNameDuplicateException ()
+ {
_constraint1.ConstraintName = "Dog";
_constraint2.ConstraintName = "Cat";
_table.Constraints.Add(_constraint1);
_table.Constraints.Add(_constraint2);
- try {
- //Should throw DuplicateNameException
- _constraint2.ConstraintName = "Dog";
-
- Assertion.Fail("Failed to throw " +
- " DuplicateNameException exception.");
- }
- catch (DuplicateNameException) {}
- catch (AssertionFailedError exc) {throw exc;}
- catch {
- Assertion.Fail("Wrong exception type thrown.");
- }
-
+ //Should throw DuplicateNameException
+ _constraint2.ConstraintName = "Dog";
}
- public void TestToString() {
- //_constraint1.ConstraintName = "Test";
- Assertion.Assert("ToString is the same as constraint name.", _constraint1.ConstraintName.CompareTo( _constraint1.ToString()) == 0);
+ [Test]
+ public void ToStringTest() {
+ _constraint1.ConstraintName = "Test";
+ Assert("ToString is the same as constraint name.", _constraint1.ConstraintName.CompareTo( _constraint1.ToString()) == 0);
+
+ _constraint1.ConstraintName = null;
+ AssertNotNull("ToString should return empty.",_constraint1.ToString());
}
- public void TestGetExtendedProperties() {
+ [Test]
+ public void GetExtendedProperties() {
PropertyCollection col = _constraint1.ExtendedProperties as
PropertyCollection;
- Assertion.AssertNotNull("ExtendedProperties returned null or didn't " +
+ AssertNotNull("ExtendedProperties returned null or didn't " +
"return the correct type", col);
}
-
}
}