NUnit test fails with DataAccess App Block

Topics: Data Access Application Block, General discussion
Jul 13, 2007 at 10:51 AM
Hello,

Surely, it's a configuration issue, but i spend the last three hours on it...

I'm doing an application, and all tests that uses Data Access Application Block fails. Example:

TestMethod
public void Test1()
{
DatabaseProviderFactory factory = new DatabaseProviderFactory(ConfigurationSourceFactory.Create());
Database _database = factory.CreateDefault();

DbCommand command = _database.GetSqlStringCommand("SELECT Count(*) FROM CabAlbaran");
int categoryCount = Convert.ToInt32(_database.ExecuteScalar(command));
Assert.GreaterOrEqual(1,categoryCount);
}

The test is for NUnit. Debugging the test, the connection string of the _database is correct, and the project has an app.conf correctly done for the test to run. Any ideas?
Jul 13, 2007 at 11:53 AM
Ok, I've found the problem. The DB of the connection string is not at the same machine, if i do the test with a local db, the test pass ok.... the connection string to the external db is ok, the application runs ok....but why tests doesn't work with external dbs??
Jul 13, 2007 at 1:59 PM
Hi,


Buitre wrote:
Ok, I've found the problem. The DB of the connection string is not at the same machine, if i do the test with a local db, the test pass ok.... the connection string to the external db is ok, the application runs ok....but why tests doesn't work with external dbs??


You should provide a description of the nature of the failure to get a sensible answer. Do the asserts fail, or do you get an exception? If you do get an exception, what is the error message and the stack?

Keep in mind that in order for the test runner to pick up the configuration file, it shouldn't be named "app.config" but "[dll file name].config". Please look at the configuration files for EntLib's unit tests for examples. This wouldn't explain why tests pass with a local db, though.

Hope this helps,
Fernando
Jul 13, 2007 at 2:19 PM
Edited Jul 13, 2007 at 2:35 PM
Tx for the reply,

That test is an example of the failure, i know it's useless as a test, i only want to show the main problem. The error is an exception at line _database.ExecuteScalar(command) or any other kind of "Execute" (executeNonQuery, ...). The exception...well, the text is in spanish, so the translation is something like "error while connecting", its an sqlException.

Its not a ".dll", it's a ".exe", and i've try with the exe file name.config, but it takes the config from app.conf anyway.
I'm sure that connection string is ok. With a copy of the DB at local, the test goes ok. I don't know how to look at the stack to post it, sorry.

Ed.:

With this test:
TestMethod
public void prob()
{
DatabaseProviderFactory factory =
new DatabaseProviderFactory(ConfigurationSourceFactory.Create());
Database _database = factory.Create("prueba2");
DbCommand command = _database.GetSqlStringCommand("SELECT Count(*) FROM Log");
>>>> _database.ExecuteScalar(command);
}

before the exception line (>>>>):
EAX = 013A20F8 EBX = 013A20F8 ECX = 04F34BA0 EDX = 00004E88 ESI = 013A20F8 EDI = 013848FC EIP = 0451F56A ESP = 0012B024 EBP = 0012B070
EFL = 00000246

after the exception line:
EAX = 00000000 EBX = 01393B68 ECX = 0012B5EC EDX = 0012A500 ESI = 01393B68 EDI = 01395CD8 EIP = 0451E137 ESP = 0012A4E0 EBP = 0012B604
EFL = 00000202

03B1E768 = 03B1E789

is this the stack? :)
Jul 13, 2007 at 2:29 PM
Hi,

No problem with the spanish text, I'm from Argentina :).

I'm not sure I follow. Do you have your NUnit tests in an exe file? It shouldn't matter, but it's unusual.

You can get the stack from one of the properties in the exception. I suggest you try cloning your test and changing it to use a SqlConnection created by you with the hardcoded connection string to the external DB and the raw ADO.NET API . If it works, you'll know there is a configuration issue.

Fernando
Jul 13, 2007 at 3:09 PM
Edited Jul 13, 2007 at 3:10 PM
I think i have found the problem. I work with Resharper 3.0, it has a pluggin for VisualStudio and NUint to run tests and debugg it without the need of use the NUnit GUID. With the GUID from NUnit, it works perfectly. I think this is the reason of reading the config from app.conf.

The test is only a "test", i was getting mad, so i took the test and pasted it in the main project.

Tx for the attention anyway, Fernando.