I ran into an issue several months back where my code could not find
ConnectionStrings while running my code in NUnit under mono, however, I was
having trouble making a simple reproducible test case. Now I have one, and I
suspect that it is not an NUnit issue, as the same thing happens under xUnit.
Rather, I'm guessing that this has to do with how the AppDomain in mono
resolves configuration file locations in shadow copied assemblies like those
used by unit testing frameworks.
My simple test is below. The first test will succeed, but the second one will
fail only under mono (tried versions 2.10.8.1, 3.0.2, 3.1.2, and 3.2.0). Under
MS.NET, both will succeed. The only difference in the first and the second
test is that the second test uses HttpUtility from System.Web, and when this
happens, the ConfigurationManager.ConnectionStrings changes to the default one
from ASP.NET, containing a LocalSqlServer (SQLEXPRESS) and LocalSqliteServer.
Is anyone able to explain why this would happen only in the AppDomains as
created by unit testing frameworks? Any known workarounds for this to keep it
from loading a different config?
### TestCode.cs ###
using System;
using System.Configuration;
using NUnit.Framework;
namespace TestHarness
{
[TestFixture]
public class MyClass
{
[Test]
public void TestSomeCode1() {
var connStr =
ConfigurationManager.ConnectionStrings["mystr"];
Assert.IsNotNull (connStr);
}
[Test]
public void TestSomeCode2() {
System.Web.HttpUtility.ParseQueryString
("http://foo.bz?bar=fu");
var connStr =
ConfigurationManager.ConnectionStrings["mystr"];
Assert.IsNotNull (connStr);
}
}
}
### App.config ###
<configuration>
<connectionStrings>
<add name="mystr" connectionString="[email protected]" />
</connectionStrings>
</configuration>
_______________________________________________
Mono-list maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list