468,293 Members | 1,858 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,293 developers. It's quick & easy.

Strange NUnit and .NET integration problem

nikpreek
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
5 4236
Frinavale
9,735 Expert Mod 8TB
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
638 Expert 512MB
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
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
9,735 Expert Mod 8TB
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
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.

Similar topics

6 posts views Thread by Peter Rilling | last post: by
2 posts views Thread by Sky Kim | last post: by
5 posts views Thread by Naveen Mukkelli | last post: by
4 posts views Thread by geoffblanduk_nospam | last post: by
20 posts views Thread by Parag | last post: by
2 posts views Thread by Mark Elliott | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.