Project Description
This Framework is very helpful for testing and configuration purpose, it has some methods that will be used as utilities that developers may need in unit testing, integration testing, configuration and automation or anything else that not related
to the business logic of any project but related to the development and testing purpose, so of course it can be reused in other projects.
Authors : Mohamed Radwan
Examples:
DeleteTableDataAndRessedId Method
This method will delete all data in a given table in the given database and also reseed the Ids for that table, you can use this method to restate a table before inserting test data in the table to return the table to the original state.
Syntax
C#
void DeleteTableDataAndRessedId(
string tableName,
string connectionString
)
Parameters
tableName
Type: System.String
The table name that will delete its data and reseed its Ids.
connectionString
Type: System.String
The connection string of the database that has the desired table.
--------------------------------------------------------------------------------------------------------------
DeleteDataBaseDataAndReseedAllIds Method
This method will delete all data in all tables in a given database and also reseed the Ids for all tables, you can use this method to restate a database tables to return the tables to the original state.
Syntax
C#
void DeleteDataBaseDataAndReseedAllIds(
string
connectionString
)
Parameters
connectionString
Type: System.String
The connection string of the database that has the desired table.
--------------------------------------------------------------------------------------------------------------
GetValueFromDB Method
This method will return a scalar value from any table with a where condition, we can use this method to check for specific value in the DB so this method will be very helpful in the testing scenario when we want to make sure that our CRUD was successed
Syntax
C#
string GetValueFromDB(
string connectionString,
string tableName,
string searchByColumn,
string searchValue,
string targetColumn)
)
Parameters
connectionString
Type: System.String
The connection string of the database that has the desired table.
tableName
Type: System.String
The table name that we want to use
searchByColumn
Type: System.String
The search by column that will be used in the where clause.
searchValue
Type: System.String
The value that will be used in the where clause after the = operator, remember to put single quotes around the value if the value is string for example 'Seif'.
targetColumn
Type: System.String
The name of column that we want to get its value.
Return Value
Type: System.String
The scalar value that we want to retrieve
--------------------------------------------------------------------------------------------------------------
And many other methods….
Note:
This Framework need SQL Server because it use Microsoft.SqlServer.Management.Smo which contains the instance object classes that represent SQL Server Database Engine objects and some utility classes that represent specific tasks, such as scripting. When a connection to the instance of the SQL Server Database Engine has been established by using a Server object variable, objects on the instance can be accessed by using the SMO instance objects.