Вопрос

I have a line of code that behaves differently in my unit test than in my application, and I'm trying to determine why. The line of code is this:

var valid = Uri.IsWellFormedUriString("1.1.1.1:12345", UriKind.RelativeOrAbsolute);

When using .NET 4.0, this would set valid to true. After moving to .NET 4.5, this starting giving false. I'm not so concerned about this, as it is easily fixed. But it is apparently not easily tested. I tried writing a unit test to confirm the problem before fixing it, but the unit test passed. I copied the test code into a new Console project and there it shows the problem. When the console project is set to .NET 4.0, the value is true, and when it is set to .NET 4.5, the value is false. But in my unit test, it is always true, even though my test project is set to .NET 4.5. So it seems like ReSharper is using an older version of .NET.

I'm using VS2012 and reSharper 7.1.3, which is set to run tests with built-in NUnit 2.6.2, which claims to be able to run tests using 4.5 framework. From the NUnit documentation, I have the impression that this is controlled by a setting in a config file, but I'm not sure which setting in which file.

Assuming I've understood the problem correctly, can anyone tell me how to configure the version of NUnit used by ReSharper to use .NET 4.5?

Это было полезно?

Решение

As @TheESJ states, this is due to "quirks mode" in the .net 4.5 framework. The test runner in ReSharper 8.2 is only .net 4.0, so it triggers quirks mode, and you get the unexpected behaviour. The test runner in ReSharper 8.2.1 (currently at RC, but RTM Real Soon Now) also supports 4.5 directly. If your assembly is 4.5, the 4.5 runner executable launches, and you don't get quirks mode.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top