By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,993 Members | 1,898 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,993 IT Pros & Developers. It's quick & easy.

Strange NUnit and .NET integration problem

nikpreek
P: 22
Hi All,

This is my first post, I've been finding lots of solutions from this forum. Thanks to all who helped (and ones who asked questions).
I have a strange problem. I'm having a console app and one of the classes in this application needs to read a file from file system. The path is one directory below app path. e.g. if application is in C:\MyApp then the file would be in C:\MyApp\DataFiles directory. I used Reflection to get the path for my executable and just appended the subdirectory name to it for getting file.
Code: string sPath = System.Reflection.Assembly.GetExecutingAssembly(). Location;

It works in all cases, but with NUnit, as NUnit makes a Shadow copy of the loaded assembly, my subdirectory cant be located by my function and the test fails.
Everything works with console app running from cmd prompt, but I cant have NUnit test for it.

Can anyone suggest any way to get the path while running NUnit?
I dont want to use hardcoded path in App.config as it'll be changed with each installation.

Pls dont mind my way of putting the query, as this is my first post.

Thanks for responses in advance.

Cheers,
Nik
Jun 15 '07 #1
Share this Question
Share on Google+
5 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Hi All,

This is my first post, I've been finding lots of solutions from this forum. Thanks to all who helped (and ones who asked questions).
I have a strange problem. I'm having a console app and one of the classes in this application needs to read a file from file system. The path is one directory below app path. e.g. if application is in C:\MyApp then the file would be in C:\MyApp\DataFiles directory. I used Reflection to get the path for my executable and just appended the subdirectory name to it for getting file.
Code: string sPath = System.Reflection.Assembly.GetExecutingAssembly(). Location;

It works in all cases, but with NUnit, as NUnit makes a Shadow copy of the loaded assembly, my subdirectory cant be located by my function and the test fails.
Everything works with console app running from cmd prompt, but I cant have NUnit test for it.

Can anyone suggest any way to get the path while running NUnit?
I dont want to use hardcoded path in App.config as it'll be changed with each installation.

Pls dont mind my way of putting the query, as this is my first post.

Thanks for responses in advance.

Cheers,
Nik
I remember briefly using NUnit a few years ago. From what I remember you can leave the test data in your assembly and your code will work perfectly fine on any other install.

I guess I don't understand the problem completely.

A normal end user isn't going to run your code through NUnit...
Jun 15 '07 #2

TRScheel
Expert 100+
P: 638
Hi All,

This is my first post, I've been finding lots of solutions from this forum. Thanks to all who helped (and ones who asked questions).
I have a strange problem. I'm having a console app and one of the classes in this application needs to read a file from file system. The path is one directory below app path. e.g. if application is in C:\MyApp then the file would be in C:\MyApp\DataFiles directory. I used Reflection to get the path for my executable and just appended the subdirectory name to it for getting file.
Code: string sPath = System.Reflection.Assembly.GetExecutingAssembly(). Location;

It works in all cases, but with NUnit, as NUnit makes a Shadow copy of the loaded assembly, my subdirectory cant be located by my function and the test fails.
Everything works with console app running from cmd prompt, but I cant have NUnit test for it.

Can anyone suggest any way to get the path while running NUnit?
I dont want to use hardcoded path in App.config as it'll be changed with each installation.

Pls dont mind my way of putting the query, as this is my first post.

Thanks for responses in advance.

Cheers,
Nik
Expand|Select|Wrap|Line Numbers
  1. using system.windows.forms
  2.  
That gives you access to the application class, which has startup path. Use that instead

Should be something like:

Expand|Select|Wrap|Line Numbers
  1. Application.StartupPath
  2.  
Jun 15 '07 #3

nikpreek
P: 22
Thanks guys.
But, my Application path is changed to some NUnit Chached path and NUnit just copies dependencies (i.e. .config or interop dll ect) to this chache directory. My required files are copied in output directory dur to their set property, but NUnit doesn't understand it.
Anyways, I've moved my file path to App.config and not its absolute path and everythig works fine. :-)

Cheers,
Nik
Jun 19 '07 #4

Frinavale
Expert Mod 5K+
P: 9,731
Thanks guys.
But, my Application path is changed to some NUnit Chached path and NUnit just copies dependencies (i.e. .config or interop dll ect) to this chache directory. My required files are copied in output directory dur to their set property, but NUnit doesn't understand it.
Anyways, I've moved my file path to App.config and not its absolute path and everythig works fine. :-)

Cheers,
Nik

I'm glad you got it working!
Thanks for sharing your solution :)

-Frinny
Jun 19 '07 #5

P: 1
I remember briefly using NUnit a few years ago. From what I remember you can leave the test data in your assembly and your code will work perfectly fine on any other install.

I guess I don't understand the problem completely.

A normal end user isn't going to run your code through NUnit...

Hai
I have got the same problem and I found a solution which works. Download nunit 2.4 and in Tools/options disable shadow copy.

If you have found some other way round in older versions without the new release, please let me know.
Thanks
ArunK
Jun 21 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.