Unit (Integration) Test for code that interacts with a database I am trying to create some (I believe these are Integration not Unit) tests for code that interacts with a database and I am not sure this is the right approach.

I would appreciate any reviews and possible improvements.

Using: VS2010 Unit Testing Framework

This is the function I want to test:

public IDbConnection OpenThirdPartyDatabase(string path, string password)
{
    var provider = GetProvider(path, password);
    return DBObjectFactory.GetObject().GetConnection(provider.Name, true, true);
}


Functions used by OpenThirdPartyDatabase

private static IDBProvider GetProvider(string path, string password)
{
    var providers = DBProviders.GetObject();
    var providerExists = providers.Cast&lt;IDBProvider&gt;().Any(dbProvider =&gt; dbProvider.Name == "MyProviderName");

    return providerExists ? providers.GetDBProvider("MyProviderName") : CreateProvider(path, password); 
}


private static IDBProvider CreateProvider(string path, string password)
{
    IDBProvider provider = new DBAccessProvider("MyProviderName", path, "", password);
    DBProviders.GetObject().Add(provider);

    return provider;
}


public IDbConnection GetConnection(string ProviderName, bool OpenConnection, bool UseConnectionPool)
{
    IDBProvider dbProvider = DBProviders.GetObject().GetDBProvider(ProviderName);
    if (dbProvider == null)
        throw new UndeclaredDBProviderException(ProviderName);
    else
    {
        IDbConnection newConnection = null;
        if ((connectionPool.ContainsConnection(ProviderName)) &amp;&amp; (UseConnectionPool))
            newConnection = connectionPool.GetConnection(ProviderName);
        else
        {
            newConnection = dbProvider.GetConnection();
            if (UseConnectionPool)
                connectionPool.AddConnection(ProviderName, newConnection);
        }
        if ((OpenConnection) &amp;&amp; (newConnection.State == ConnectionState.Closed))
            newConnection.Open();
        return newConnection;
    }
}


Tests:

/// &lt;summary&gt;
/// Test Connection with valid path and password
/// &lt;/summary&gt;
[TestMethod]
public void ThirdPartyConnection_Valid()
{
    var testConnection = _thirdPartyConnManager.OpenThirdPartyDatabase("Data\\test.mdb", "pass");
    Assert.AreNotEqual(testConnection, null);
}

/// &lt;summary&gt;
/// Test Connection With Invalid Password
/// &lt;/summary&gt;
[TestMethod]
[ExpectedException(typeof(OleDbException),"Not a valid password.")]
public void ThirdPartyConnection_ShouldThrowOleDbException_InvalidPassword()
{
    var testConnection = _thirdPartyConnManager.OpenThirdPartyDatabase("Data\\test.mdb", "invalidpassword");
}

/// &lt;summary&gt;
/// Test Connection with invalid path
/// &lt;/summary&gt;
[TestMethod]
[ExpectedException(typeof(OleDbException))]
public void ThirdPartyConnection_ShouldThrowOleDbException_InvalidPath()
{
    var testConnection = _thirdPartyConnManager.OpenThirdPartyDatabase("InvalidPath\\Data\\test.mdb", "pass");
}

/// &lt;summary&gt;
/// Test Connection String
/// &lt;/summary&gt;
[TestMethod]
public void ThirdPartyConnection_ConnectionString()
{
    var testConnection = _thirdPartyConnManager.OpenThirdPartyDatabase("Data\\test.mdb", "pass");
    Assert.AreEqual(testConnection.ConnectionString,"Expected Connection String","Not expected Connection String");
}
I don't claim to be an expert, but here's my experience.

Apart from that i see you are using a constant string "MyProviderName" in your code and you would do well to move that to a const string for easy refactoring and future changes.

Also i suggest you use the more common "ArgumentNullException" vs creating your own custom "UndeclaredDBProviderException" as you want to capture that a null parameter was passed to the function.

I would also suggest you run the code through FxCop and fix any errors.