85 lines
2.2 KiB
C#
85 lines
2.2 KiB
C#
|
|
using System;
|
|||
|
|
using System.Data.SqlClient;
|
|||
|
|
using NUnit.Framework;
|
|||
|
|
|
|||
|
|
|
|||
|
|
namespace DatabaseUnitTesting
|
|||
|
|
{
|
|||
|
|
public class TestSetups
|
|||
|
|
{
|
|||
|
|
private SqlConnection _connection;
|
|||
|
|
private SqlTransaction _transaction;
|
|||
|
|
private DatabaseModificationTester _unitTests;
|
|||
|
|
private const bool _BSETUPMODE = false;
|
|||
|
|
private SqlCommand _command;
|
|||
|
|
private string _testResultsInitialPath = AppDomain.CurrentDomain.BaseDirectory + @"..\..\TestResults\";
|
|||
|
|
|
|||
|
|
|
|||
|
|
[OneTimeSetUp]
|
|||
|
|
public void TFSetup()
|
|||
|
|
{
|
|||
|
|
//Define the connection string
|
|||
|
|
string connectionString = Properties.Settings.Default["ConnectionString"].ToString();
|
|||
|
|
_connection = new SqlConnection(connectionString);
|
|||
|
|
|
|||
|
|
_connection.Open();
|
|||
|
|
//a database snapshot is created under the hood in this constructor
|
|||
|
|
|
|||
|
|
_unitTests = new DatabaseModificationTester(_connection, Properties.Settings.Default.DBName, Properties.Settings.Default.DBSnapshot);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[OneTimeTearDown]
|
|||
|
|
public void TFTearDown()
|
|||
|
|
{
|
|||
|
|
//a database snapshot is dropped under the hood in this method
|
|||
|
|
_unitTests.Dispose();
|
|||
|
|
// deleting test data is skipped
|
|||
|
|
_connection.Close();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[SetUp]
|
|||
|
|
public void SetUp()
|
|||
|
|
{
|
|||
|
|
_transaction = _unitTests.BeginTestTransaction();
|
|||
|
|
_command = _connection.CreateCommand();
|
|||
|
|
_command.Transaction = _transaction;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[TearDown]
|
|||
|
|
public void TearDown()
|
|||
|
|
{
|
|||
|
|
_unitTests.EndTestTransaction();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public String TestResultPath
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return _testResultsInitialPath;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public DatabaseModificationTester UnitTests
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return _unitTests;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public bool BSETUPMODE
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return _BSETUPMODE;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public SqlCommand Command
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return _command;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|