[Mono-dev] MySQL Connector - Location Issue

Rafael Teixeira monoman at gmail.com
Wed Aug 27 09:51:33 EDT 2008

You are really mixing some concepts.

Configuration files are tied to the program/process that is running, not to
any of many libraries that are being executed in that process. That is the
default behavior.

ASP.NET machinery uses some hooks inside System.Configuration to merge the
various levels of web.config files, to present the merged result as the
"configuration" file to the code executing in a web application.

MD and/or NUnit could implement a similar approach to have libraries of
tests seeing specific configuration, but AFAIR neither does that.

More commonly we have the tested class split into a part that receives the
connection as a constructor parameter/property (Inversion-Of-Control) e some
setup code in the tests create the appropriate connection before the tests
are executed.

The connection factory part of the split class goes untested or is tested
with a small executable (non-Nunit testing).

Using the System.Configuration hooks to cook a tailored unit test is doable
but it is normally not worth the trouble.

Hope it helps,

On Tue, Aug 26, 2008 at 9:55 AM, krdavis <KEITH.DAVIS at zunisoft.com> wrote:

> First off I have scoured the list and found similar but not identical
> problems to mine without a solution. Development environemnt is Ubuntu
> 8.04,
> Mono 1.9.1 and Monodevelop 2.0 Alpha.
> I have used JUnit for years and I am new NUnit and the nuances of
> assemblies
> and how they are located and loaded.  I have an ASP.NET application that
> uses a custom membership provider (w/MySQL as the backend).  The provider
> works fine,  everything is being updated and what not.  I added the
> following to my web.config to get my MySQL connection working:
> <system.web>
> ...
> <system.data>
>    <DbProviderFactories>
>      <clear />
>      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient"
>           description=".Net Framework Data Provider for MySQL"
>           type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,
>               Version=, Culture=neutral,
> PublicKeyToken=c5687fc88969c44d" />
>    </DbProviderFactories>
>  </system.data>
> <system.web>
> This is great and the ASP.NET app works with MySQL, now the problem.
>  Being
> a good developer, I want to create some unit tests for my membership
> provider.  I created a separate test project from my memberhip library
> project.  I added a project reference to the membership project in my test
> project (good, the dll will get copied to the test project).
> In the test project I created an app.config with the above section from my
> web.config so my NUnit test will know about the MySQL provider.  I create a
> simple test and my membership dll (not the NUnit dll) throws:
> Failed to find or load the registered .Net Framework Data Provider
> 'MySql.Data.MySqlClient'. () ()
> My NUnit project copies the app.config to the appropriate output directory
> properly named <assembly-name>.dll.config.  Examining the build output
> directory shows the NUnit dll and its corresponding config file.  I added a
> bit of code to the nunit test and found it is not picking up the correct
> config file for the test dll. (it was picking up another config
> *md*.config,
> monodevelop maybe?) I thought the default behavior for NUnit was to pick up
> the config if I configured the build directory with the renamed dll.
> I tried to open the dll.confg in the unit test directly (I think that just
> lets me query the values, it doesn't actually load the provider reference,
> if I am wrong here, please advise).
> Long winded, but here is the question:  What is the proper way to configure
> a unit test to use an app.config so I can specify a provider factory not in
> the machine.config?  Or should I just add the factory to machine.config?
> Anyway it is strange that the ASP.NET app works, but the test fails (wrong
> configuration being picked up) on the same machine.
> Any and all help would be appreciated, I have been googling this issue for
> a
> whole day without a decent solution.
> TIA!
> --
> View this message in context:
> http://www.nabble.com/MySQL-Connector---Location-Issue-tp19161468p19161468.html
> Sent from the Mono - Dev mailing list archive at Nabble.com.
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list

Rafael "Monoman" Teixeira
"I myself am made entirely of flaws, stitched together with good
Augusten Burroughs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080827/69320d3e/attachment.html 

More information about the Mono-devel-list mailing list