Skip to content
Darren Comeau edited this page Oct 11, 2018 · 9 revisions

Welcome to the DBTester wiki!

Getting started and setting up a connection to my database

string connection = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=tempdb;Integrated Security=True;";

DatabaseTester tester = new VulcanAnalytics.DBTester.MsSqlDatabaseTester(connection);

My database Has something?

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");

Executing my SQL statements

// 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"];

Working with table data

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

Clone this wiki locally