-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Darren Comeau edited this page Oct 11, 2018
·
9 revisions
string connection = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=tempdb;Integrated Security=True;";
DatabaseTester tester = new VulcanAnalytics.DBTester.MsSqlDatabaseTester(connection);
tester.ExecuteStatementWithoutResult("create schema [testing];");
tester.ExecuteStatementWithoutResult("create table [testing].[TestPerson]([TestId] int, [Name] varchar(255), [ModifiedDate] datetime);");
// HasSchema
bool hasSchema;
hasSchema = tester.HasSchema("testing");
// HasTable
bool hasTable;
hasTable = tester.HasTable("testing","TestPerson");
// ExecuteStatementWithoutResult
tester.ExecuteStatementWithoutResult("drop table if exists [dbo].[TestPerson];");
tester.ExecuteStatementWithoutResult("create table [dbo].[TestPerson]([TestId] int, [Name] varchar(255), [ModifiedDate] datetime);");
tester.ExecuteStatementWithoutResult("insert into [dbo].[TestPerson] values(1,'Joe','2018-09-28T12:49:13.576');");
tester.ExecuteStatementWithoutResult("insert into [dbo].[TestPerson] values(2,'John','2018-10-01T18:31:29.256');");
// ExecuteStatementWithResult
var results = tester.ExecuteStatementWithResult("select [TestId] from [dbo].[TestPerson] where [ModifiedDate] >= '2018-10-01T00:00:00.000';");
// work with System.Data.DataSet as normal
var rowCount = results.Tables[0].Rows.Count;
var name = results.Tables[0].Rows[0]["Name"];
var columns = new string[] { "TestId", "Name", "ModifiedDate" };
var data = new object[]
{
new Object[]{1,"Joe","2018-09-28T12:49:13.576"},
new Object[]{2,"John","2018-10-01T18:31:29.256"}
};
// InsertData
tester.InsertData("dbo", "mytesttable", columns, data);
// RowCount
var rowcountcount = tester.RowCount("dbo", "mytesttable");
Assert.AreEqual(2,rowcountcount);
// ClearTable
tester.ClearTable("dbo", "mytesttable");
Assert.AreEqual(0,tester.RowCount("dbo", "mytesttable"));
// DropTable
tester.DropTable("dbo", "mytesttable");
Assert.IsFalse(tester.HasTable("dbo", "mytesttable"));
To learn how to use the InsertData
method please go here
To learn how to use the RowCount
method please go here
To learn how to use the ClearTable
method please go here
To learn how to use the DropTable
method please go here