Database rollback tests
"Eric" <[email protected]> Sat, 26 Jul 2008 15:21:18 -0700
| Newsgroups | gmane.comp.windows.dotnet.nunit.user |
|---|---|
| Message-ID | <!&!AAAAAAAAAAAYAAAAAAAAADoe/GS0t01DguRS+0fvNArCgAAAEAAAANCbYFCGbetGpRjKIq5kT1cBAAAAAA==@cox.net> |
I'm trying the xtUnit extension (TeamAgile) and can't understand if it's the
extension or my tests (code below) that are off. The db is SQl CE, which I'm
using with Enterprise Library.
After running the Add_SQL() test, server explorer shows the db table as
having only the two test data items it started with before the insert, so it
would seem the DataRollBack worked. Yet running the FindAll_SQL() test
afterwards fails. If I clean my solution and rebuild it, then then state is
somehow restored and the FindAll_SQL() test succeeds again.
TIA,
Eric
Helpful links for DB testing strategies/tools would also be much
appreciated.
==== Code =======
private static Database _db;
[SetUp]
public void SetUp() {
_db = null;
_db = DatabaseFactory.CreateDatabase();
}
[Test, DataRollBack]
public void FindAll_SQL() {
Assert.That(_findAll(), Is.EqualTo(2));
}
private static int _findAll() {
return (int)
_db.ExecuteScalar(_db.GetSqlStringCommand("SELECT COUNT(*) FROM Company"));
}
[Test, DataRollBack]
public void Add_SQL() {
var companyCount = _findAll();
var sqlInsert = string.Format("INSERT INTO Company (CompanyId,
CompanyName) VALUES ('{0}', '{1}')", Guid.NewGuid(), "Microsoft");
var rowsAffected =
_db.ExecuteNonQuery(_db.GetSqlStringCommand(sqlInsert));
Assert.That(rowsAffected, Is.EqualTo(1));
Assert.That(_findAll(), Is.EqualTo(companyCount + 1));
}
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/