I have added abunch of classes for database testing in the TestFu project (Download Now ):
· SqlAdministrator: backup, restore, create or drop databases, and also some methods on tables, constraints,etc...
· SqlExplorer: extracts the schema of database to a DataSet
· SqlFixture: a mini data abstraction layer "TestFixture" oriented
Let's see them in action...
SqlAdministrator
· Backup database to a file:
· Restore a database from a file:
· Drop a database:
· Drop a table:
· Drop a constraint:
· etc...
using System; using TestFu.Data; public class Demo { public static void Main(string[] args) { DbAdministrator admin = new SqlAdministrator("..."); // backup Northwind admin.Backup("Northwind",SqlBackupDevice.Disk,@"c:\Backups\Northwind.bkp"); // drop Northwind admin.Drop("Northwind"); // restore Northwind admin.Restore("Northwind",SqlBackupDevice.Disk,@"c:\Backups\Northwind.bkp"); } }
SqlFixture
The DbFixture (SqlFixture for MsSQL server) can be used as a base class for the fixtures involving database testing:
DbFixture
[TestFixture] public class DatabaseTest : SqlFixture { public DatabaseTest() :base("Data Source=testserver;...","MyTestDatabase") {} [SetUp] public void SetUp() { this.Open(); this.BeginTransaction(); } [Test] public void Selec() { IDbCollection cmd = this.Connection.CreateCommand("select * from anytable",this.Transaction); ... } [TearDown] public void TearDown() { this.Close(); } }
Page rendered at Monday, September 08, 2008 6:58:13 PM UTC
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.