Table of Contents

Class AutomatedTestsWithLocalDB

Namespace
CMS.Tests
Assembly
CMS.Tests.dll

Allows integration tests to run in isolation as for each test a clean database with current schema and default objects is created.

public abstract class AutomatedTestsWithLocalDB : AutomatedTestsWithData
Inheritance
object
AutomatedTestsWithLocalDB
Derived
Inherited Members
Extension Methods

Remarks

The isolated integration tests use LocalDB to create and drop databases when needed. It works with two types of database. The master database is created using SQL scripts from the solution. For each modification of this folder a new master database is created. The master database is detached after it has been created and its files are copied to create an instance database that a running test will use. The instance and master databases share a name, but the file names are different. The instance database is removed when a test finishes and a master database, that is out of date, is removed automatically.

Constructors

AutomatedTestsWithLocalDB()

Initializes a new instance of the IsolatedIntegrationTests class.

protected AutomatedTestsWithLocalDB()

Properties

SharedDatabaseForAllTests

Indicates if the same database is used for all tests in same test class.

public bool SharedDatabaseForAllTests { get; }

Property Value

bool

Methods

AutomatedTestsWithLocalDBFixtureSetup()

Init shared instance database in NUnit tests.

public void AutomatedTestsWithLocalDBFixtureSetup()

AutomatedTestsWithLocalDBFixtureTearDown()

Removes shared instance database in NUnit tests. Note: This method is called automatically in NUnit tests.

public void AutomatedTestsWithLocalDBFixtureTearDown()

AutomatedTestsWithLocalDBSetup()

Initializes the current test environment.

public void AutomatedTestsWithLocalDBSetup()

AutomatedTestsWithLocalDBTearDown()

Cleans the current test environment.

public void AutomatedTestsWithLocalDBTearDown()

EnsureExtraDatabase(string, bool)

Ensures the specified extra database for the test

public string EnsureExtraDatabase(string dbName, bool empty = false)

Parameters

dbName string

Database name

empty bool

If true, the database should be empty rather than regular installation

Returns

string

ExecuteWithAllDatabases(Action<string>)

Executes the same given action in the context of all test databases. Original database is handled first.

public void ExecuteWithAllDatabases(Action<string> action)

Parameters

action Action<string>

Action to execute

ExecuteWithExtraDatabase(string, Action)

Executes the given action in the context of the given extra database

public void ExecuteWithExtraDatabase(string dbName, Action action)

Parameters

dbName string

Database name

action Action

Action to execute

GetCurrentTestDatabaseName()

Gets the local database name

public string GetCurrentTestDatabaseName()

Returns

string

GetExtraDatabaseConnectionStringName(string)

Gets connection string name for given extra database

protected static string GetExtraDatabaseConnectionStringName(string extraDbName)

Parameters

extraDbName string

Database name

Returns

string

GetTestUniqueIndex()

Gets a unique index for the test run. All calls from a single test run return the same index.

public int GetTestUniqueIndex()

Returns

int

RefreshMacroSignatures(params string[])

Updates macro signatures in provided objectTypes. Signs all macros with GlobalAdministrator identity.

protected void RefreshMacroSignatures(params string[] objectTypes)

Parameters

objectTypes string[]