Skip to content
Darren Comeau edited this page Oct 29, 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");

To learn how to use the HasSchema method please go here

To learn how to use the HasTable method please go here

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],[Name] 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"];

To learn how to use the ExecuteStatementWithoutResult method please go here

To learn how to use the ExecuteStatementWithResult method please go here

Working with table data

// create a table for testing
tester.DropTable("dbo", "mytesttable");
tester.ExecuteStatementWithoutResult("create table [dbo].[mytesttable]([TestId] int, [Name] varchar(255), [ModifiedDate] datetime);");


// Prepare data to insert
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);


// ObjectData
var tableContent = tester.ObjectData("dbo", "mytesttable");

Assert.AreEqual("Joe",tableContent.Rows[0]["Name"]);


// 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 ObjectData 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