Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Config file manipulations fail
sunny
#1 Posted : Sunday, March 4, 2012 2:04:37 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/4/2012(UTC)
Posts: 6

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
Hi, I have a tests, in which Setup I write some entries in the config file, and on tear-down I remove them.

I use:

var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

All this works well under NUnit or Reshrper, but fails in NCrunch. I.e. looks like the writing in the config file works, but later on during the test, the runner does not find the right config file, because the tests fail with config entry not found.

Stepping trough the Setup method, I see that the above line of code uses FilePath "C:\\Users\\sunny\\AppData\\Local\\NCrunch\\2424\\19\\MobileServices.Tests\\bin\\Debug\\MobileServices.Tests.dll.config.ncrunchconfig

As the entries I create are for WCF endpoints (I need to test that my startup class succeeds to bind the proxies), looks like when the WCF infrastructure kicks in to get the config file, it gets something else.

Running the same thing under resharper shows that it gets/writes in MobileServices.Tests.dll.config, and it works.

Any idea how to approach this problem?
Remco
#2 Posted : Sunday, March 4, 2012 9:37:12 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,982

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi,

Thanks for posting. I've done some quick testing on my side and I couldn't recreate any issues with the manipulation of config files in the way you've described - though I haven't yet tested this in detail with any WCF infrastructure.

NCrunch does use remoting channels for communication between the task runner host (Visual Studio) and the test being executed, so I'm wondering if it's possible that the issue you're seeing could be because the test environment has a set of channels that is inconsistent with what you're expecting. Do you also experience issues when reading/writing other configuration details (such as appsettings)?

Is there any chance you could reduce the test to a code snippet that surfaces the problem? This would be enormously helpful.

Thanks!

Remco
Roman Temek
#3 Posted : Tuesday, March 6, 2012 10:03:17 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/6/2012(UTC)
Posts: 3

Thanks: 2 times
Hi,
I experience kind of the same issue.
In my test project (a project that contains tests) I have a standard app.config file and a custom config DataAccess.InMemory.config.
In runtime a test has no problems with accessing app.config, but when I try to open DataAccess.InMemory.config test can't find it.
It tries to look at C:\Users\XXX\AppData\Local\NCrunch\5804\117\TestResults\ff598651-3720-4dee-9943-3a69ae9dd65d\Out\DataAccess.InMemory.config - but there is no such file in the directory. It is empty.
Here is a piece of code I use to load the config file:

var configFile = "DataAccess.InMemory.config";
var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = configFile };
var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

On this stage configuration.FilePath quals to "C:\\Users\\XXX\\AppData\\Local\\NCrunch\\5804\\123\\TestResults\\04e49901-389d-4fc5-9e18-f308a12bdc6d\\Out\\DataAccess.InMemory.config"
So, it looks into "Out" directory for the file instead of project folder. Is it the way it has to work? If so, how make the config visible for test executed by ncrunch?
A note: the same test works perfectly when I run it by visual studio unit testing tools.

sunny
#4 Posted : Tuesday, March 6, 2012 4:23:51 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/4/2012(UTC)
Posts: 6

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
Actually, it works OK. I had no App.config file, and it appears that on first run, config.Save is creating it, but it's too late for NCrunch to pick it.

Just adding an empty App.config solved the problem for me, as the build copies it to bin folder, and then the test can modify it.
1 user thanked sunny for this useful post.
Remco on 3/6/2012(UTC)
Remco
#5 Posted : Tuesday, March 6, 2012 8:43:03 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,982

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi Roman,

Thanks for posting! Can you give me any more details about the DataAccess.InMemory.config? Is this a statically created file that exists as part of your project and is copied to the output directory, or is it dynamically created at run-time through one of your tests?

If it's a static file and needs to be copied to the testing directory, how do you have this configured? Are you using [DeploymentItem] or do you have configuration in your MSTest settings that specifically targets the file?
Roman Temek
#6 Posted : Wednesday, March 7, 2012 7:30:27 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/6/2012(UTC)
Posts: 3

Thanks: 2 times
Hi,
Thanks for your reply.
DataAccess.InMemory.config is a statically created file and it is a part of the project.
To make the file visible for MSTest I enabled deployment (menu Test->Edit Test Settings->Local->Deployment->Enable deployment) and specified DataAccess.InMemory.config as an additional file to deploy. In this way MSTest works, but if I disable deployment, if fails because the test is unable find the file in runtime.
I tried to configure NCruch to copy DataAccess.InMemory.config to workspace by specifying it in "Additional files to include" for tests project. This doesn't help.
I'd appreciate any help on this.
Remco
#7 Posted : Wednesday, March 7, 2012 9:29:46 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,982

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi Roman,

This makes good sense now. NCrunch doesn't support MSTest's global configuration settings, so if you specify deployment items globally then they won't be copied to the output directory.

There are two ways you can work around this.

The first is to use the [DeploymentItem] attribute on all tests that require a particular resource to be copied to the MSTest 'Out' directory (may not work so well for you).

The second is to reference the config file using a relative path that reaches out of the MSTest 'Out' directory and back into your source solution. This should allow your test to work with both the Visual Studio testing tools and NCrunch.
1 user thanked Remco for this useful post.
Roman Temek on 3/12/2012(UTC)
Roman Temek
#8 Posted : Wednesday, March 7, 2012 11:01:15 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/6/2012(UTC)
Posts: 3

Thanks: 2 times
Hi
The approach with [DeploymentItem] works like a charm. The only concern I have now is that I have to add this attribute to all my tests. Currently I can live with it, but what if had dozen of such files? In this case the test code would be spoiled with [DeploymentItem] attributes. It would be very handy to make NCrunch either to support MSTest's global configuration settings or provide own funcntionality that does the same.
Thanks for your help, now I can continue my NCrunch journey :)
Remco
#9 Posted : Wednesday, March 7, 2012 9:38:44 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,982

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Supporting the global MSTest configuration is something I looked into doing when implementing the MSTest support, though unfortunately it requires a large amount of integration and at the time I couldn't find a reliable way to do it. There are also changes coming in NCrunch that would be logically incompatible with this kind of configuration, so I've instead taken to trying to encourage people to avoid using it.

I definitely have to recommend referencing your configuration file as it sits in your solution by using a relative path. The location of MSTest's 'Out' directory is always consistent relative to your source code, so I think that this could be an ideal solution for you. Otherwise it may be worth having a look at other test frameworks that do not use MSTest's file copying approach (such as NUnit).
otac0n
#10 Posted : Friday, March 9, 2012 10:54:12 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 5/22/2011(UTC)
Posts: 51
Location: Seattle, WA

Was thanked: 7 time(s) in 7 post(s)
DeploymentItem can be applied per-class, as well.
1 user thanked otac0n for this useful post.
Roman Temek on 3/12/2012(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.069 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download