TestFu Static helper class for creating data binders Summary description for DataGeneratorCollection. A collection of . Adds a to the collection. to add to the collection. is a null reference (Nothing in Visual Basic) Removes a from the collection. to remove from the collection. is a null reference (Nothing in Visual Basic) Removes a associated to from the collection. whose generator is to be removed from the collection. is a null reference (Nothing in Visual Basic) Removes a associated to from the collection. Column named whose generator is to be removed from the collection. is a null reference (Nothing in Visual Basic) Gets the associated to the . is a null reference (Nothing in Visual Basic) Gets the associated to the column named . is a null reference (Nothing in Visual Basic) A collection of . Summary description for TablePopulatorCollection. A collection of . A collection of . Abstract class to perform administrative tasks on a database Initializes an instance of with the connection string. Connection string to the SQL server without initial catalog Catalog name The factory to use. is a null reference (Nothing in Visual Basic) Creates a backup of the specified database using the specified and . A defining the type of output device. Device path. is a null reference (Nothing in Visual Basic) Restores a backup of the specified database using the specified and . A defining the type of output device. Device path. is a null reference (Nothing in Visual Basic) If you plan to override an existing database, you must first drop this database. This method takes a conservative behavior and will not override an existing database. Creates a new database on the server Drops an existing new database on the server is a null reference (Nothing in Visual Basic) Gets a value indicating if the current database exists. true if it exists; otherwise, false. Drops the table. Name of the table to drop This method takes care of removing the constraints associated to the table before removing the table. Gets a value indicating if the database contains the table. Name of the table to search true if a table named is contained in the databse;oterwise false. Executes a non-query in a safe, transactional environement. The connection string. Query to execute. Optional arguments. Gets or sets the connection string with Initial Catalog information Connection string. Gets or sets the database name The database name. Gets or sets the database owner. Database owner name. Gets the connection string with Initial Catalog information. Connection string with Initial catalog information. Enumeration of available SQL backup devices DISK device TAPE device Output to named dump A factory for and instances. Creates a instance. Connection string to server A instance. An abstract base class for test fixtures involving database testing. The DbFixture (SqlFixture for MsSQL server) can be used as a base class for the fixtures involving database testing. [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(); } } Initializes a with a connection string. Connection string for accessing the test database. The name of the database to use. The factory to use. is a null reference (Nothing in Visual Basic) Opens a instance with the . This method must be implemented in inherited classes for different factorys. Executes a non-query command with the given parameters Query format string Query arguments for the format string Number of affected rows The connection is automatically opened if necessary. Executes a scalar query with the given parameters Query format string Query arguments for the format string Query result The connection is automatically opened if necessary. Executes query and returns the instance Query format string Query arguments for the format string A resulting from the query. The connection is automatically opened if necessary and the reader is created with option. Begins a new transaction. If a previous transaction was opened, by default, it is rolled back. The current connection is not created or not opened. Commits the current transaction if any. Rollsback the current transaction if any. Closes the current connection. If a transaction was opened, it is first rolled back. Gets the database instance A instance. Gets the current connection instance. instance. Gets the current transaction. A instance if was called and the connection not closed; otherwise, a null reference (Nothing in Visual Basic) Gets the connection string to access the db server (without database information. Gets the test database name. Gets the connection string to connecto the test database. A random data generator for values. This method generates Byte arrays with length in the range [, ]. Abstract base class from instance. An random data generator. Resets the generator Generates a new value and fills it in the corresponding . It is the user job to ensure that the instance provided is compatible with the generator definition and more specifically the it is associated with. Gets the generated type Generated . Gets or sets the probability to produce a NULL This value determines the probability to produce a null value. The probability ranges from 0 - never, to 1 - always. The probability to produce a null object. Gets the target column Target instance. Resets the generator Generates a new value New random data. Updates the internal data and verifies column information. Gets the generated type Generated type. Gets the target column Target instance. Gets or sets the probability to produce a NULL This value determines the probability to produce a null value. The probability ranges from 0, never to 1 always. The probability to produce a null object. Generates a new value New random data. Gets the generated type Generated type. Gets or sets the minimum length of the generated value Minimum generated length. Default is 16. Gets or sets the maximum generated value Maximum generated length. Default is 16. A random generator of values. Creates an instance with equal to 0.5. Generates a new value New random data. Gets the generated type Generated type. Gets or sets the probability to return true. Probability to return true. is not in [0,1]. A random data generator for values. This method generates byte values in a range [, ]. Generates a new value New random data. Gets the generated type Generated type. Gets or sets the minimum generated value Minimum generated value. Default is Gets or sets the maximum generated value Maximum generated value. Default is A random data generator for values. This method generates DateTime values in a range [, ]. Generates a new value New random data. Gets the generated type Generated type. Gets or sets the minimum generated value Minimum generated value. Default is Gets or sets the maximum generated value Maximum generated value. Default is A random data generator for values. This method generates decimal values in a range [, ]. Generates a new value New random data. Gets the generated type Generated type. Gets or sets the minimum generated value Minimum generated value. Default is Gets or sets the maximum generated value Maximum generated value. Default is A random data generator for values. This method generates double values in a range [, ]. Generates a new value New random data. Gets the generated type Generated type. Gets or sets the minimum generated value Minimum generated value. Default is Gets or sets the maximum generated value Maximum generated value. Default is A random generator of values. Generates a new value New random data. Gets the generated type Generated type. A random data generator for binary values. This method generates a bitmap of size [ by ]. Gets the generated type Generated type. Gets or sets the pixel format A random data generator for values. This method generates int values in a range [, ]. Generates a new value New random data. Gets the generated type Generated type. Gets or sets the minimum generated value Minimum generated value. Default is Gets or sets the maximum generated value Maximum generated value. Default is A random data generator for values. This method generates int values in a range [, ]. Generates a new value New random data. Gets the generated type Generated type. Gets or sets the minimum generated value Minimum generated value. Default is Gets or sets the maximum generated value Maximum generated value. Default is A random data generator for values. This method generates int values in a range [, ]. Generates a new value New random data. Gets the generated type Generated type. Gets or sets the minimum generated value Minimum generated value. Default is Gets or sets the maximum generated value Maximum generated value. Default is A random generator of instances. Initializes a new instance of . Gets the generated type Generated type. Gets or sets the minimum length of the string Minimum length of the string. set proprety, the value is negative. Gets or sets the maximum length of the string Maximum length of the string. set proprety, the value is less than 1. A random data generator for values. This method generates float values in a range [, ]. Generates a new value New random data. Gets the generated type Generated type. Gets or sets the minimum generated value Minimum generated value. Default is Gets or sets the maximum generated value Maximum generated value. Default is Generates a new value New random data. Generates a new value New random data. This method generates float values in a range [, ]. Generates a new value New random data. Gets the generated type Generated type. Gets or sets the minimum generated value Minimum generated value. Default is 0 Gets or sets the maximum generated value Maximum generated value. Default is 0 A random generator of instances. Initializes a new instance of . Generates a new value New random data. Gets or sets the string containing the generated characters A graph of (vertices) and (edges). Builds a new empty directed graph with default vertex and edge provider. Remove all of the edges and vertices from the graph. Add a new DataTableVertex to the graph and returns it. Created vertex Removes the vertex from the graph. vertex to remove v is null Add a new vertex from source to target Complexity: 2 search + 1 insertion Source vertex Target vertex Relation Created Edge source or target is a null reference source or target are not part of the graph Remove all edges to and from vertex u from the graph. Removes an edge from the graph. Complexity: 2 edges removed from the vertex edge list + 1 edge removed from the edge list. edge to remove e is a null reference (Nothing in Visual Basic) is not part of the graph Remove the edge (u,v) from the graph. If the graph allows parallel edges this remove all occurrences of (u,v). source vertex target vertex Add a new vertex to the graph and returns it. Create vertex Used for serialization. Not for private use. edge to add. Gets a value indicating if the set of out-edges is empty Usually faster that calling . true if the out-edge set is empty, false otherwise. v is a null reference (Nothing in Visual Basic) v is not part of the graph. Returns the number of out-degree edges of v vertex number of out-edges of the v v is a null reference (Nothing in Visual Basic) v is not part of the graph. Returns an iterable collection over the edge connected to v out-edges of v v is a null reference. v is not part of the graph. Test is an edge (u,v) is part of the graph source vertex target vertex true if part of the graph Returns the first out-edge that matches the predicate Edge predicate null if not found, otherwize the first Edge that matches the predicate. v or ep is null Returns the collection of out-edges that matches the predicate Edge predicate enumerable colleciton of vertices that matches the criteron v or ep is null Remove all the edges from graph g for which the predicate pred returns true. edge predicate Remove all the out-edges of vertex u for which the predicate pred returns true. vertex edge predicate Tests if a is part of the graph Vertex to test true if is part of the graph, false otherwize Returns the first that matches the predicate vertex predicate null if not found, otherwize the first vertex that matches the predicate. vp is null Returns the collection of vertices that matches the predicate vertex predicate enumerable colleciton of vertices that matches the criteron vp is null Tests if a () is part of the graph Edge to test true if is part of the graph, false otherwize Returns the first Edge that matches the predicate Edge predicate null if not found, otherwize the first Edge that matches the predicate. ep is null Returns the collection of edges that matches the predicate Edge predicate enumerable colleciton of vertices that matches the criteron ep is null Gets an enumerable collection of adjacent vertices Enumerable collection of adjacent vertices Gets a value indicating if the set of in-edges is empty Usually faster that calling . true if the in-edge set is empty, false otherwise. v is a null reference (Nothing in Visual Basic) is not part of the graph. Returns the number of in-degree edges of v number of in-edges of the vertex v v is a null reference (Nothing in Visual Basic) is not part of the graph. Returns an iterable collection over the in-edge connected to v in-edges of v v is a null reference (Nothing in Visual Basic) is not part of the graph. Incidence graph implementation Gets a value indicating if the set of edges connected to v is empty Usually faster that calling . true if the adjacent edge set is empty, false otherwise. v is a null reference Returns the number of in-edges plus out-edges. Returns the first in-edge that matches the predicate Edge predicate null if not found, otherwize the first Edge that matches the predicate. v or ep is null Returns the collection of in-edges that matches the predicate Edge predicate enumerable colleciton of vertices that matches the criteron v or ep is null Remove all the out-edges of vertex u for which the predicate pred returns true. vertex edge predicate Gets a value indicating if the is directed. true if the graph is directed, false if undirected. Gets a value indicating if the allows parallel edges. true if the is a multi-graph, false otherwise Gets the provider provider Gets the provider provider Gets a value indicating if the vertex set is empty Usually faster (O(1)) that calling VertexCount. true if the vertex set is empty, false otherwise. Gets the number of vertices Number of vertices in the graph Enumerable collection of vertices. Gets a value indicating if the vertex set is empty Usually faster that calling . true if the vertex set is empty, false otherwise. Gets the edge count Edges count Enumerable collection of edges. Initializes a new empty instance of the class. Adds an instance of type to the end of this . The Edge to be added to the end of this EdgeCollection. Removes the first occurrence of a specific Edge from this EdgeCollection. The Edge value to remove from this EdgeCollection. Determines whether a specfic value is in this EdgeCollection. edge value to locate in this . true if value is found in this collection; false otherwise. Returns an enumerator that can iterate through the elements of this EdgeCollection. An object that implements System.Collections.IEnumerator. Gets or sets the Edge at the given index in this EdgeCollection. Create a new enumerator on the collection collection to enumerate Moves cursor to next element. true if current is valid, false otherwize Resets the cursor to the position before the first element. The current element. A populator of instance. A with a instance. A validator check checks constraints Preprocesses the row modifies it to fullfill the constraint A database populator instance. Sets up the generators for the given instance. A representing the structure of the database to populate. is a null reference (Nothing in Visual Basic) Gets the instance associated to this populator. A schema used to set-up the generators. Gets a collection associated to each table. A containing populator associated to each . Gets the associated to the database. An instance that can fill a with data that are compatible with a given . Fill the row with data that is compatible with the foreign key. instance to fill. is a null reference (Nothing in Visual Basic). Gets the table populator associated to the foreign table. The instance associated to the foreign table. Gets the foreign constraint that needs to be satisfied. The associated to this provider. Gets a value indicating that the foreign table is empty and cannot provide keys. true if the foreign table is empty; otherwise false. An random generator compatible with the schema of a given . This example shows how the data generator can be used to create unit tests on database. In this example, we setup the dummy UserOrderProductDatabase and the populator in the SetUp method. using System; using System.Data; using MbUnit.Core.Framework; using MbUnit.Framework; using TestFu.Data; using TestFu.Data.Populators; namespace TestFu.Tests.Data { [TestFixture] public class DatabasePopulatorTest { private UserOrderProductDatabase db; private DatabasePopulator pop; private ITablePopulator users; private ITablePopulator orders; private ITablePopulator products; private ITablePopulator orderProducts; [SetUp] public void SetUp() { this.db=new UserOrderProductDatabase(); this.pop = new DatabasePopulator(); this.pop.Populate(this.db.DataSet); this.users=this.pop.Tables[this.db.Users]; this.orders=this.pop.Tables[this.db.Orders]; this.products=this.pop.Tables[this.db.Products]; this.orderProducts=this.pop.Tables[this.db.OrderProducts]; } [Test] public void AddOneUser() { DataRow row = users.Generate(); this.db.Users.Rows.Add(row); } [Test] public void AddOneUserOneOrder() { this.AddOneUser(); DataRow row = orders.Generate(); this.db.Orders.Rows.Add(row); } [Test] [ExpectedException(typeof(InvalidOperationException))] public void AddOneOrder() { DataRow row = orders.Generate(); } [Test] [ExpectedException(typeof(InvalidOperationException))] public void AddOneOrderProduct() { DataRow row = orderProducts.Generate(); } [Test] public void AddOneUserOneOrderOneProduct() { this.AddOneUserOneOrder(); DataRow row = products.Generate(); this.db.Products.Rows.Add(row); } [Test] public void AddOneUserOneOrderOneProductOneProductOrder() { this.AddOneUserOneOrderOneProduct(); DataRow row=orderProducts.Generate(); this.db.OrderProducts.Rows.Add(row); } [Test] public void AddTwoUsers() { AddOneUser(); AddOneUser(); } [TearDown] public void Check() { this.db.AcceptChanges(); Console.WriteLine(db.ToString()); } } } Generates a new . Generated instance. Updates randomly a number of rows The row to update. Updates randomly a number of rows The row to update. Flag to update any foreign keys. Gets an instance of the $ that contains this populator. Parent instance. Gets the instance that is the model to be populated. A instance whos schema is used to create new . Gets a collection of associated to each . A instance containing the validators associated to each unique constraint. Gets a collection of associated to each . A instance containing the providers associated to each foreign key. Gets a collection of associated to each column of the table. A instance containing the generators associated to each column. Gets the that ensures CHECK constraints. A instance if any check constraint to verify; otherwize a null reference. Gets the latest generated . Latest generated . A validator for constraints. The TestFu.Data namespace contains a Random generator to help developer test databases, data layers, business layers, etc... This example shows some usage of the class. This class can be used to easily backup, restore, create or drop databases on a server. is the implementation for the MSSQL server: [C#] 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"); } } The DbFixture (SqlFixture for MsSQL server) can be used as a base class for the fixtures involving database testing. [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(); } } This example shows how the data generator can be used to create unit tests on database. In this example, we setup the dummy UserOrderProductDatabase and the populator in the SetUp method. using System; using System.Data; using MbUnit.Core.Framework; using MbUnit.Framework; using TestFu.Data; using TestFu.Data.Populators; namespace TestFu.Tests.Data { [TestFixture] public class DatabasePopulatorTest { private UserOrderProductDatabase db; private DatabasePopulator pop; private ITablePopulator users; private ITablePopulator orders; private ITablePopulator products; private ITablePopulator orderProducts; [SetUp] public void SetUp() { this.db=new UserOrderProductDatabase(); this.pop = new DatabasePopulator(); this.pop.Populate(this.db.DataSet); this.users=this.pop.Tables[this.db.Users]; this.orders=this.pop.Tables[this.db.Orders]; this.products=this.pop.Tables[this.db.Products]; this.orderProducts=this.pop.Tables[this.db.OrderProducts]; } [Test] public void AddOneUser() { DataRow row = users.Generate(); this.db.Users.Rows.Add(row); } [Test] public void AddOneUserOneOrder() { this.AddOneUser(); DataRow row = orders.Generate(); this.db.Orders.Rows.Add(row); } [Test] [ExpectedException(typeof(InvalidOperationException))] public void AddOneOrder() { DataRow row = orders.Generate(); } [Test] [ExpectedException(typeof(InvalidOperationException))] public void AddOneOrderProduct() { DataRow row = orderProducts.Generate(); } [Test] public void AddOneUserOneOrderOneProduct() { this.AddOneUserOneOrder(); DataRow row = products.Generate(); this.db.Products.Rows.Add(row); } [Test] public void AddOneUserOneOrderOneProductOneProductOrder() { this.AddOneUserOneOrderOneProduct(); DataRow row=orderProducts.Generate(); this.db.OrderProducts.Rows.Add(row); } [Test] public void AddTwoUsers() { AddOneUser(); AddOneUser(); } [TearDown] public void Check() { this.db.AcceptChanges(); Console.WriteLine(db.ToString()); } } } The following codes decribes a simple User - Order - Product database contains 4 tables: Users, Orders, Products and OrderProducts. using System; using System.Data; using System.IO; using System.Xml; namespace TestFu.Tests.Data { public class UserOrderProductDatabase { private DataSet dataSet; private DataTable users; private DataColumn userID; private DataColumn userName; private DataTable orders; private DataColumn orderID; private DataColumn orderDate; private DataColumn oUserID; private DataTable products; private DataColumn productID; private DataColumn productName; private DataColumn productPrice; private DataTable orderProducts; private DataColumn opOrderID; private DataColumn opProductID; private DataColumn quantity; public UserOrderProductDatabase() { this.dataSet=new DataSet(); this.users=this.dataSet.Tables.Add("Users"); this.userID = this.users.Columns.Add("UserID",typeof(int)); this.userName=this.Users.Columns.Add("UserName",typeof(string)); this.userName.AllowDBNull=false; this.orders=this.dataSet.Tables.Add("Orders"); this.orderID=this.orders.Columns.Add("OrderID",typeof(int)); this.orderDate = this.orders.Columns.Add("OrderDate",typeof(DateTime)); this.oUserID = this.orders.Columns.Add("UserID",typeof(int)); this.products=this.dataSet.Tables.Add("Products"); this.productID=this.products.Columns.Add("ProductID",typeof(int)); this.productName = this.products.Columns.Add("ProductName",typeof(string)); this.productPrice = this.products.Columns.Add("ProductPrice",typeof(decimal)); this.orderProducts=this.dataSet.Tables.Add("OrderProducts"); this.opOrderID=this.orderProducts.Columns.Add("OrderID",typeof(int)); this.opProductID=this.orderProducts.Columns.Add("ProductID",typeof(int)); this.quantity=this.orderProducts.Columns.Add("Quantity",typeof(int)); // pks users.Constraints.Add("PK_Users",userID,true); orders.Constraints.Add("PK_Orders",orderID,true); products.Constraints.Add("PK_Products",productID,true); orderProducts.Constraints.Add("PK_OrderProducts", new DataColumn[]{ opOrderID, opProductID} ,true); // fks orders.Constraints.Add("FK_Orders_Users",userID,oUserID); orderProducts.Constraints.Add("FK_OrderProducts_Orders",orderID,opOrderID); orderProducts.Constraints.Add("FK_OrderProducts_Products",productID,opProductID); } } } Default implementation. This example shows how the data generator can be used to create unit tests on database. In this example, we setup the dummy UserOrderProductDatabase and the populator in the SetUp method. using System; using System.Data; using MbUnit.Core.Framework; using MbUnit.Framework; using TestFu.Data; using TestFu.Data.Populators; namespace TestFu.Tests.Data { [TestFixture] public class DatabasePopulatorTest { private UserOrderProductDatabase db; private DatabasePopulator pop; private ITablePopulator users; private ITablePopulator orders; private ITablePopulator products; private ITablePopulator orderProducts; [SetUp] public void SetUp() { this.db=new UserOrderProductDatabase(); this.pop = new DatabasePopulator(); this.pop.Populate(this.db.DataSet); this.users=this.pop.Tables[this.db.Users]; this.orders=this.pop.Tables[this.db.Orders]; this.products=this.pop.Tables[this.db.Products]; this.orderProducts=this.pop.Tables[this.db.OrderProducts]; } [Test] public void AddOneUser() { DataRow row = users.Generate(); this.db.Users.Rows.Add(row); } [Test] public void AddOneUserOneOrder() { this.AddOneUser(); DataRow row = orders.Generate(); this.db.Orders.Rows.Add(row); } [Test] [ExpectedException(typeof(InvalidOperationException))] public void AddOneOrder() { DataRow row = orders.Generate(); } [Test] [ExpectedException(typeof(InvalidOperationException))] public void AddOneOrderProduct() { DataRow row = orderProducts.Generate(); } [Test] public void AddOneUserOneOrderOneProduct() { this.AddOneUserOneOrder(); DataRow row = products.Generate(); this.db.Products.Rows.Add(row); } [Test] public void AddOneUserOneOrderOneProductOneProductOrder() { this.AddOneUserOneOrderOneProduct(); DataRow row=orderProducts.Generate(); this.db.OrderProducts.Rows.Add(row); } [Test] public void AddTwoUsers() { AddOneUser(); AddOneUser(); } [TearDown] public void Check() { this.db.AcceptChanges(); Console.WriteLine(db.ToString()); } } } Initiliazes a instance. A querying the databse. Base class for implementation. A based on a . Default implementation of Default implementation of An smart random generator. This example shows how the data generator can be used to create unit tests on database. In this example, we setup the dummy UserOrderProductDatabase and the populator in the SetUp method. using System; using System.Data; using MbUnit.Core.Framework; using MbUnit.Framework; using TestFu.Data; using TestFu.Data.Populators; namespace TestFu.Tests.Data { [TestFixture] public class DatabasePopulatorTest { private UserOrderProductDatabase db; private DatabasePopulator pop; private ITablePopulator users; private ITablePopulator orders; private ITablePopulator products; private ITablePopulator orderProducts; [SetUp] public void SetUp() { this.db=new UserOrderProductDatabase(); this.pop = new DatabasePopulator(); this.pop.Populate(this.db.DataSet); this.users=this.pop.Tables[this.db.Users]; this.orders=this.pop.Tables[this.db.Orders]; this.products=this.pop.Tables[this.db.Products]; this.orderProducts=this.pop.Tables[this.db.OrderProducts]; } [Test] public void AddOneUser() { DataRow row = users.Generate(); this.db.Users.Rows.Add(row); } [Test] public void AddOneUserOneOrder() { this.AddOneUser(); DataRow row = orders.Generate(); this.db.Orders.Rows.Add(row); } [Test] [ExpectedException(typeof(InvalidOperationException))] public void AddOneOrder() { DataRow row = orders.Generate(); } [Test] [ExpectedException(typeof(InvalidOperationException))] public void AddOneOrderProduct() { DataRow row = orderProducts.Generate(); } [Test] public void AddOneUserOneOrderOneProduct() { this.AddOneUserOneOrder(); DataRow row = products.Generate(); this.db.Products.Rows.Add(row); } [Test] public void AddOneUserOneOrderOneProductOneProductOrder() { this.AddOneUserOneOrderOneProduct(); DataRow row=orderProducts.Generate(); this.db.OrderProducts.Rows.Add(row); } [Test] public void AddTwoUsers() { AddOneUser(); AddOneUser(); } [TearDown] public void Check() { this.db.AcceptChanges(); Console.WriteLine(db.ToString()); } } } Helper class to performe task on a SQL server. This example shows some usage of the class. This class can be used to easily backup, restore, create or drop databases on a server. is the implementation for the MSSQL server: [C#] 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"); } } Initializes an instance of with the connection string. Connection string to the SQL server without initial catalog Catalog name is a null reference (Nothing in Visual Basic) Creates a backup of the specified database using the specified and . A defining the type of output device. Device path. is a null reference (Nothing in Visual Basic) Restores a backup of the specified database using the specified and . A defining the type of output device. Device path. is a null reference (Nothing in Visual Basic) If you plan to override an existing database, you must first drop this database. This method takes a conservative behavior and will not override an existing database. Priorly to restore the database, the method kills all the processes associeted to the database. Creates a new database on the server Drops an existing new database on the server is a null reference (Nothing in Visual Basic) Gets the connection string with Initial Catalog information. Connection string with Initial catalog information. A implementation for MSSQL server. Creates a instance. Creates a instance. Connection string to server A instance. Abstract base class for MSSQL server database testing. The DbFixture (SqlFixture for MsSQL server) can be used as a base class for the fixtures involving database testing. [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(); } } Initializes a with a connection string. Connection string for accessing the test database. database name is a null reference (Nothing in Visual Basic) Gets the current connection instance. instance. Gets the current transaction. A instance if was called and the connection not closed; otherwise, a null reference (Nothing in Visual Basic) Provides functions to capture the entire screen, or a particular window, and save it to a file. Source code takened from http://www.developerfusion.com/show/4630/ Creates an Image object containing a screen shot of the entire desktop Creates an Image object containing a screen shot of the entire desktop Creates an Image object containing a screen shot of the Creates an Image object containing a screen shot of a specific window The handle to the window. (In windows forms, this is obtained by the Handle property) Helper class containing Gdi32 API functions Helper class containing User32 API functions A that simulates a MouseDown event. Abstract base class for instance. Abstract base class for implementation. A user gesture. User gesture can be a combination of keyboard or mouse interactions. Executes the gesture This method should be executed on separate thread from the main thread, otherwize event will not be fired correctly. Gets the CodeDom statement creating this gesture Gets the that is targeted by the gesture Initializes an empty . Initializes a new instance with a form Raises the event. Converts the target from client to screen coordinates Position in client coordinates Position converted into screen coordinates This method makes a thread safe invokation of the Form.PointToScreen method. Converts the target from screen to client coordinates Position in screen coordinates Position converted into client coordinates This method makes a thread safe invokation of the Form.PointToClient method. Executes the gesture. Gets or sets the instance targeted by the A instance Raised when the target is changed A mouse gesture. Gets or sets a value indicating the involved in the gesture. A combined value of flags. Initializes an new . Initializes a new with a instance and the buttons involved in the gesture. Target instance value representing the involved in the gesture Gets or sets a value indicating the involved in the gesture. A combined value of flags. Initializes a new Initializes a new with a target instance and the left button Target form Initializes a new with a target instance and the buttons Target form value representing the involved in the gesture Executes the mouse down event A that simulates a MouseUp event Initialiazes a new . Initialiazes a new with a target . Target form Initialiazes a new with a target . Target form value representing the involved in the gesture Executes the mouse up event A that simulates a button click Initializes a new Initializes a new with a instance and the left button Target instance Initializes a new with a instance Target instance value representing the involved in the gesture Executes the mouse click A that moves the cursor to the center of a . An abstract base class for implementations that simulates a mouse movement Initializes a new Initialiazes a new with a target form and no buttons Target Initialiazes a new with a target form and the buttons Target value representing the involved in the gesture Steers the mouse towards the target Gets the target of the movement, in client coordinates A in client coordinates Gets or sets a value indicating the maximum velocity of the cursor A representing the maximum velocity of the cursor Initializes a new Initializes a new with a target and a target Target form Target control Initializes a new with a target , a target and the buttons pushed during the move Target form Target control value representing the involved in the gesture Gets or sets the target A instance where the cursor has to move Gets the center of the target . A representing the center of the target control in client coordiantes Offset of the target on the A that steers the cursor to a target Initializes a new Initializes a new with a target and a target Target form Target in client coordinates Initializes a new with a target and a target Target form Target in client coordinates value representing the involved in the gesture Gets the target of the movement, in client coordinates. A in client coordinates The property value is equal to . Gets or sets the target of the movement, in client coordinates A in client coordinates A implementation. A mutable collection of Adds a instance to the collection A instance to add to the collection Gets or sets the at position index of the gesture get property, the at position A helper factory of instance. Initializes a new with a instance Target form Creates a for the method and starts it. The to execute The started instance Creates a instance with a variable list of instances. gestures to execute in sequence. A instance Creates a that makes the thread sleep a given number of milliseconds Duration in milliseconds of the sleep A instance Creates a new with the gesture and the repeat count Target instance Number of repetition A instance Creates a that simulates a left click of the mouse A instance Creates a that simulates a left click of the mouse A instance Control to click Creates a that simulates a left click of the mouse A instance The control to click. Which button(s) to use. Creates a that simulates a left click of the mouse value representing the involved in the gesture A instance Creates a new instance that simulates a Mouse down event (left click) A instance Creates a new instance that simulates a Mouse down event with the buttons value representing the involved in the gesture A instance Creates a new instance that simulates a Mouse up event (left click) A instance Creates a new instance that simulates a Mouse up event with the buttons value representing the involved in the gesture A instance Creates a that simulates the movement of the mouse to the target Target client coordinate A instance Creates a that simulates the movement of the mouse to the target and the buttons down Target client coordinate value representing the involved in the gesture A instance Creates a that simulates the movement of the mouse to the center of the Target instance A instance Creates a that simulates the movement of the mouse to the center of the with the buttons down Target instance value representing the involved in the gesture A instance Creates a instance that simulates a drag and drop between and Source client coordinate Target client coordinate A instance that simulates the drag and drop Creates a instance that simulates a drag and drop between and Source client coordinate Target A instance that simulates the drag and drop Creates a instance that simulates a drag and drop between and Source Target client coordinate A instance that simulates the drag and drop Creates a instance that simulates a drag and drop between and Source Target A instance that simulates the drag and drop Creates a instance that simulates a drag and drop between and Source Target client coordinate A instance that simulates the drag and drop Gets the target instance A instance that is targetted by the gestures The TestFu.Gestures namespace contains classes ( instances) to simulate user mouse and keyboard interactions. The user interaction are simulated by using native methods mouse_event and keybd_event. The can be used to rapidly generate instances. The gestures should not be executed in the main thread but in a worker thread. Otherwize, you will miss message notifications. All gesture methods on and are thread safe. A that executes a Repeat of instances. Initializes a new instance Initialiazes a new instance with a instance. Target The gesture to be repeated The number of repetition Executes the contained in in Repeat. Gets the collection of to execute in Repeat A instance Gets or sets the number of gesture repetition The repetition count A that executes a sequence of instances. Initializes a new instance Initialiazes a new instance with a instance. Target Executes the contained in in sequence. Gets the collection of to execute in sequence A instance A that makes the sleep. Initialiazes a new instance. Initialiazes a new instance with a instance and a sleep duration Target instance Sleep duration in milliseconds Executes the sleep gestures Gets or sets the sleep duration (in milliseconds) Number of milliseconds of sleep A static helper for artificially generationg mouse and keyboard input. This class uses mouse_event and keybd_event native methods (through interop) to simulate user mouse or keyboard input. Generates a mouse event Combined flag describing the mouse event Mouse event with additional data Combined flag describing the mouse event Relative horizontal movement of the cursor Relative vertical movement of the cursor Additional data Move mouse of units horizontal movement vertical movement Notfies that a mouse movement is starting with the buttons settings Combined flag describing the current button state Notfies that a mouse movement is finishing with the buttons settings Combined flag describing the current button state Mouse click using button state Combined flag describing the current button state Mouse down event Mouse up event Mouse wheel event Wheel movement Simulates a Key action (KeyDown, Key, KeyUp message sequence) character pressed handle of control to receive the event Simulates a Backspace handle of control to receive the event Simulates a user typing text text to enter handle of control to receive the event Mouse even type enumeration No event Mouse move where dx,dy are in absolute coordinate Left button bown Left button up Middle button down middle button up Mouse moved Right button down Right button up Mouse wheel movement Additional button down Additional button up A that choose from a set of sub-. Abstract rule containing other rules. Abstract rule class A production rule A instance is used to execute a production. Executes the production using the rule. A production token authorizing production. is a null reference (Nothing in Visual Basic) Gets or sets a value indicating the rule importance Value indicating the rule importance set property, value is negative. Semantic actions event. Semantic action are triggered upon each successful rule execution. Gets a value indicating if the rule is terminal true if the rule is terminal; otherwise, false. Gets or sets the rule name (for debugging purpose) The rule name. Creates an empty rule true if the rule is terminal; otherwise, false. Raises the event. Executes the production using the rule (abstract class). A production token authorizing production. is a null reference (Nothing in Visual Basic) Gets a value indicating if the rule is terminal true if the rule is terminal; otherwise, false. Gets or sets the rule name The rule name Gets or sets the rule weight The rule weight set property, weight is negative Semantic action event. Creates an empty instance. Gets the list of rules stored in the rule. containing the child rules. Choose a and launch its production. Authorizing token Gets or sets the instance instance. If then else rule fashion. This rule uses the results of a instance to select which to execute: if (predicate.Test(...)) rule.Produce(...); else elseRule.Produce(...); Creates a with a instance and instance. instance used for testing rule to execute. or is a null reference. Creates a with a instance and instance. If the predicate returns false, is executed. instance used for testing rule to execute. rule to execute if predicate is false. or is a null reference. Executes one of the rules depending on the predicate result. A production token authorizing production. is a null reference (Nothing in Visual Basic) Gets or sets the predicate for the condition. instance used for testing the condition. set property, value is a null reference Gets or sets the rule executed when the predicate is true instance executed when is true. set property, value is a null reference Gets or sets the rule executed when the predicate is false instance executed when is false. Method that returns a bool. Current instance. A instance that executes a . Predicate that checks a given condition. Checks a condition and returns result. Predicate result Current production token Creates a new instance arounda to attach. is a null reference. Invokes the instance and returns the result. A class that limits the number of terminal execution. A production done by a grammar and its set of rules. Processes the request for a done by a rule and returns the token or throws. instance that requests the token. A valid instance. The request was defined using the internal production logic. Gets the seed that created the production Seed used to create the production Creates an instance that limits the number of terminal rule execution to . Maximum number of terminal execution. Processes the request for a done by a rule and returns the token or throws. instance that requests the token. A valid instance. The maximum number of terminal rule execution was hitted. Factory for instance. A factory for instances. Creates a new instance. A valid instance. Creates a factory of . Creates new instances of A instance A that wraps a call. Creates an instance with a attached. Handler to attach is a null reference Invokes handler. A grammar containing a set of rules, a . A grammar containing a set of rules, a . Launches a production. Gets or sets the starting rule. The start . Raised when production is finished. Creates an empty grammar. Launches a production. Gets or sets the instance. instance used for creating new productions. Gets or sets the starting rule. The start . A that guard an inner instance execution from a specific exceptionType. Creates an instance with the guarded rule and the expected exception type. Guarded instance Expected type. or is a null reference. Creates an instance with the guarded rule, the expected exception type and the regular expression to match the message. Guarded instance Expected type. Regular expression used to match the exception message or is a null reference. Raises the event. Executes the inner and guards for a particular exception type. Authorization token Semantic actions event Gets or sets the regular expression to match the message. The instance used to mach the message. If this property is set to null, no message matching is performed. Gets or sets the rule name (for debugging purpose) The rule name. Gets or sets a value indicating the rule importance Value indicating the rule importance Gets a value indicating if the rule is terminal. Always returns true. An authorization to execute a production. Gets a value indicating if the production is authorized true if authorized, otherwise false. Gets the that emited the token. The instance that emited the token. A class that creates random values. Returns a nonnegative random number. A 32-bit signed integer greater than or equal to zero and less than . Returns a nonnegative random number less than the specified maximum. A 32-bit signed integer greater than or equal to zero and less than . Returns a random number within a specified range. The lower bound of the random number returned. The upper bound of the random number returned. maxValue must be greater than or equal to minValue. A 32-bit signed integer greater than or equal to minValue and less than maxValue; that is, the range of return values includes minValue but not MaxValue. If minValue equals maxValue, minValue is returned. Returns a random number between 0.0 and 1.0. A double-precision floating point number greater than or equal to 0.0, and less than 1.0. A collection of . Gets an instance of the rules. A valid instance. An enumerator over instance. Gets the current instance Current instance. A list of Adds a to the list. to add Inserts a instance at position position to insert the rule to insert Removes the first occurence of . to remove Gets a value indicating if is in the list. to test. true if is in the list; otherwise, false. Clears the list. Gets or sets the at position . index. A object that select a rule between a collection of rules. Select a from array to select from Select instance is a null reference is empty Select a from collection to select from Select instance is a null reference is empty A rule that executes a . Creates a new instance around a to attach. is a null reference. Invokes the instance. Autorization token The TestFu.Grammars namespace contains a framwork for implementing Production Grammars. Exception throwed when an exception is catched and is not from the expected type. Creates an instance with the expected exception type and the actual exception. Expected exception Actual catch instance Exception throwed when an exception message does not match with the message regular expression Creates an instance with the message regular expression and the actual catched exception. The instance used to match the message The actual instance. Gets the instance used to match the exception message message matcher. A static helper class for creating . Creates a around condition to wrap A Expection class used to stop production. Gets the production that stopped. Default implementation of Creates a token from production to wrap. is a null reference (Nothing in Visual Basic). Gets the that emited the token. The instance that emited the token. Gets a value indicating if the production is authorized true if authorized, otherwise false. A rule that executes a . Creates a new instance around a to attach. is a null reference. Invokes the instance. Autorization token Summary description for ProductionTokenEventArgs. System implementation of Creates an instance initialized using .Now.Ticks. Uniform random rule selector. Select a from array to select from Select instance is a null reference is empty Select a from collection to select from Select instance is a null reference is empty Gets or sets the random generator The instance used for random data generation set property, value is a null reference A that executes repeatidely an inner Creates an instance that executes the rule between and times. to repeat Minimum number of occurence Maximum number of occurence Executes repeatidely the inner rule. Authorization token Converts rule to EBNF like representation EBNF-like string representing the rule. Gets or sets the random generator used for selection repetition counts The random generator. set property, value is a null reference Gets the inner instance Repeated instance. Gets the minimum of rule execution Minimum of rule execution Gets the maximum of rule execution Maximum of rule execution Round Robin rule selector. Select a from array to select from Select instance is a null reference is empty Select a from collection to select from Select instance is a null reference is empty Gets or sets the current rule index. Current rule index A collection of elements of type IRule Initializes a new empty instance of the RuleList class. Adds an instance of type IRule to the end of this RuleList. The IRule to be added to the end of this RuleList. Determines whether a specfic IRule value is in this RuleList. The IRule value to locate in this RuleList. true if value is found in this RuleList; false otherwise. Inserts an element into the RuleList at the specified index The index at which the IRule is to be inserted. The IRule to insert. Removes the first occurrence of a specific IRule from this RuleList. The IRule value to remove from this RuleList. Returns an enumerator that can iterate through the elements of this RuleList. An object that implements System.Collections.IEnumerator. Gets or sets the IRule at the given index in this RuleList. Type-specific enumeration class, used by RuleList.GetEnumerator. Static helper class for creating rules. Creates an alternative of rules. Set of rule to choose from alternatively. [EBNF] rule := A | B | C [C#] IRule rule = Rules.Alt(A,B,C); An instance implementing the alternative rule choosing. Creates a weighted alternative of rules. Set of rule to choose from alternatively. The property of each rule is used to weight the probability to choose the rule. [EBNF] rule := A | B | C where A is chosen with P(A)=A.Weight / ABC.Weight and ABC.Weight = A.Weight + B.Weight + C.Weight [C#] IRule rule = Rules.WeightedAlt(A,B,C); An instance implementing the alternative rule choosing. Creates a sequence of rules. Set of rule to execute in sequence. [EBNF] rule := A B C [C#] IRule rule = Rules.Seq(A,B,C); An instance implementing the sequence of rules. Creates an optional rule. Rule to execute optionaly. [EBNF] rule := A? [C#] IRule rule = Rules.Opt(A); An instance implementing the ? operator. Creates a rule to be execute one or more times. Rule to be executed. [EBNF] rule := A+ [C#] IRule rule = Rules.Pos(A); An instance implementing the + operator. Creates a rule to be execute zero or more times. Rule to be executed. [EBNF] rule := A* [C#] IRule rule = Rules.Kleene(A); An instance implementing the * operator. Creates a rule to be execute between and times. Rule to be executed. [EBNF] rule := A{m,n} [C#] IRule rule = Rules.Repetition(A,m,n); minimum number of execution of maximum number of execution of An instance implementing the {m,n} operator. Creates a that executes an . to execute instance that contains Creates a that executes an . to execute instance that contains Creates a that executes an . to execute instance that contains Guards the execution of a from an expected type. instance to guard. Expected throwed exception when is executed A instance guarding Creates a conditional rule with "if" rule. Condition expression to execute if condition is true. A implementing condition rule execution. Creates a conditional rule with "if" rule and "else" rule. Condition expression to execute if condition is true. to execute if condition is false. A implementing condition rule execution. Creates a conditional rule with "if" rule. Condition expression to execute if condition is true. to execute if condition is false. A implementing condition rule execution. Creates a conditional rule with "if" rule and "else" rule. Condition expression to execute if condition is true. A implementing condition rule execution. A sequence of rules. Executes sub-rule production in sequence. to authorize production. Weighted random rule selector. Select a from array to select from Select instance is a null reference is empty Select a from collection to select from Select instance is a null reference is empty TestFu, the Art of Testing. The TestFu assembly contains a bunch of framework to help developper build automated tests using random generators, models, grammars, etc... The TestFu.Operations namespace contains classes for building Combinatorial Test suites. The algorithms for generating the covergate suites are extracted from Efficient Algorithms for Generation of Combinatorial Covering Suites, by Adrian Dumitrescu. A class to generate permutations. This class can generate any sequence of permutation of order . The method returns the next permutation, while can be used to iterates all the rest of the permutations. The permutation can be applied to an array using , it can also be inverted using . This class was extracted from Using Permutations in .NET for Improved Systems Security by Dr. James McCaffrey. Creates a new idenity permutation order of the new permutation Creates the -th permutation of order . Checks that the permutation is correct Converts the permutation to a string representation. Applis the permutation to the array A array of Length equal to . A new array containing the permutated element of Creates the inverse of the permutation. Creates the next permutation in lexicographic order. The next instance if there remain any; otherwize a null reference. Gets an enumerable collection of successors. Gets the order of the permutation