Class MsAccessTestHelper
Helper class for unit tests, if there is a need for real database in tests. It creates temporary empty database for testing. This database is automatically deleted after finishing the work.
Inheritance
Namespace: Kros.UnitTests
Assembly: Kros.Utils.MsAccess.dll
Syntax
public class MsAccessTestHelper : IDisposable
Constructors
MsAccessTestHelper(ProviderType)
Creates an instance of helper with specified parameters. New database file is created as an empty database with random name in temporary folder.
Declaration
public MsAccessTestHelper(ProviderType provider)
Parameters
Type | Name | Description |
---|---|---|
ProviderType | provider | Microsoft Access provider type. |
MsAccessTestHelper(ProviderType, IEnumerable<String>)
Creates an instance of helper with specified parameters. New database file is created as an empty database
with random name in temporary folder and is initialized with scripts in initDatabaseScripts
.
Declaration
public MsAccessTestHelper(ProviderType provider, IEnumerable<string> initDatabaseScripts)
Parameters
Type | Name | Description |
---|---|---|
ProviderType | provider | Microsoft Access provider type. |
System.Collections.Generic.IEnumerable<System.String> | initDatabaseScripts | List of scripts, which are used for database initialization. For example, they can be scripts for creating and filling necessary tables. |
MsAccessTestHelper(ProviderType, Stream)
Creates an instance of helper with specified parameters. New database file is created as a copy of
sourceDatabaseStream
.
Declaration
public MsAccessTestHelper(ProviderType provider, Stream sourceDatabaseStream)
Parameters
Type | Name | Description |
---|---|---|
ProviderType | provider | Microsoft Access provider type. |
System.IO.Stream | sourceDatabaseStream | Source database. New temporary database is created as a copy of this. |
MsAccessTestHelper(ProviderType, Stream, IEnumerable<String>)
Creates an instance of helper with specified parameters. New database file is created as a copy of
sourceDatabaseStream
and initialized with scripts in initDatabaseScripts
.
Declaration
public MsAccessTestHelper(ProviderType provider, Stream sourceDatabaseStream, IEnumerable<string> initDatabaseScripts)
Parameters
Type | Name | Description |
---|---|---|
ProviderType | provider | Microsoft Access provider type. |
System.IO.Stream | sourceDatabaseStream | Source database. New temporary database is created as a copy of this. |
System.Collections.Generic.IEnumerable<System.String> | initDatabaseScripts | List of scripts, which are used for database initialization. For example, they can be scripts for creating and filling necessary tables. |
MsAccessTestHelper(ProviderType, Stream, String)
Creates an instance of helper with specified parameters. New database file is created as a copy of
sourceDatabaseStream
and initialized with script initDatabaseScript
.
Declaration
public MsAccessTestHelper(ProviderType provider, Stream sourceDatabaseStream, string initDatabaseScript)
Parameters
Type | Name | Description |
---|---|---|
ProviderType | provider | Microsoft Access provider type. |
System.IO.Stream | sourceDatabaseStream | Source database. New temporary database is created as a copy of this. |
System.String | initDatabaseScript | A script, which is used for database initialization. For example, it can be script for creating some table. |
MsAccessTestHelper(ProviderType, String)
Creates an instance of helper with specified parameters. New database file is created as a copy of
sourceDatabasePath
.
Declaration
public MsAccessTestHelper(ProviderType provider, string sourceDatabasePath)
Parameters
Type | Name | Description |
---|---|---|
ProviderType | provider | Microsoft Access provider type. |
System.String | sourceDatabasePath | Source database. New temporary database is created as a copy of this. |
MsAccessTestHelper(ProviderType, String, IEnumerable<String>)
Creates an instance of helper with specified parameters. New database file is created as a copy of
sourceDatabasePath
and initialized with scripts in initDatabaseScripts
.
Declaration
public MsAccessTestHelper(ProviderType provider, string sourceDatabasePath, IEnumerable<string> initDatabaseScripts)
Parameters
Type | Name | Description |
---|---|---|
ProviderType | provider | Microsoft Access provider type. |
System.String | sourceDatabasePath | Source database. New temporary database is created as a copy of this. |
System.Collections.Generic.IEnumerable<System.String> | initDatabaseScripts | List of scripts, which are used for database initialization. For example, they can be scripts for creating and filling necessary tables. |
MsAccessTestHelper(ProviderType, String, String)
Creates an instance of helper with specified parameters. New database file is created as a copy of
sourceDatabasePath
and initialized with script initDatabaseScript
.
Declaration
public MsAccessTestHelper(ProviderType provider, string sourceDatabasePath, string initDatabaseScript)
Parameters
Type | Name | Description |
---|---|---|
ProviderType | provider | Microsoft Access provider type. |
System.String | sourceDatabasePath | Source database. New temporary database is created as a copy of this. |
System.String | initDatabaseScript | A script, which is used for database initialization. For example, it can be script for creating some table. |
Properties
Connection
Connection to created temporary database.
Declaration
public OleDbConnection Connection { get; }
Property Value
Type | Description |
---|---|
System.Data.OleDb.OleDbConnection |
DatabasePath
Path to created temporary database.
Declaration
public string DatabasePath { get; }
Property Value
Type | Description |
---|---|
System.String |
Methods
Dispose()
Declaration
public void Dispose()
GenerateDatabaseName()
Generates path to the file where database will be created. Default is random filename in system's temp folder.
Declaration
protected virtual string GenerateDatabaseName()
Returns
Type | Description |
---|---|
System.String | Path to the database file. |
InitDatabase()
Initializes new empty database. Method is called after empty temporary database is created and it executes initialization scripts (specified in constructor). method is called only once.
Declaration
protected virtual void InitDatabase()