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

Notification

Icon
Error

Testing methods that load files
stasek27
#1 Posted : Sunday, February 8, 2015 7:10:34 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/8/2015(UTC)
Posts: 2
Location: United Kingdom

Was thanked: 1 time(s) in 1 post(s)
How do i test if a method correctly loads a file that is located in my project folder?

This is how code looks:
Code:

	path = Path.Combine(Environment.CurrentDirectory, "Ranges", "test.range");


But NCrunch looks in a different folder and I get an exception

System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\Users\[removed]\AppData\Local\NCrunch\5916\83\VS\ProjectName\CommonsTests\bin\Debug\Ranges\Holdem\3B16.range'.

How do I make Ncrunch to look in the [ProgramOutputFolder]\Ranges\Holdem\ folder?




Remco
#2 Posted : Sunday, February 8, 2015 9:26:06 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,000

Thanks: 932 times
Was thanked: 1259 time(s) in 1172 post(s)
Hi, thanks for posting!

The correct behaviour is for NCrunch to look up a copy of the file inside its workspace. In this way, it works completely in isolation from your code.

With this in mind, NCrunch is already looking in the right place. The problem is that the file hasn't been copied there.

There are a few ways you can handle this. If your code relies on a file that isn't included in any project file, NCrunch considers this to be an 'Implicit dependency'. You can read more about implicit dependencies and how to resolve them here - http://www.ncrunch.net/documentation/considerations-and-constraints_implicit-file-dependencies.

If for some reason you don't want NCrunch to copy the file to the workspace (for example, if it's really big and copying it just isn't resource efficient), the NCrunch.Framework.Environment.GetOriginalSolutionPath() can be used to find your original solution when running inside NCrunch's test environment.

stasek27
#3 Posted : Monday, February 16, 2015 3:45:51 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/8/2015(UTC)
Posts: 2
Location: United Kingdom

Was thanked: 1 time(s) in 1 post(s)
This has worked. Thanks.
1 user thanked stasek27 for this useful post.
Remco on 2/16/2015(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.030 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download