Strange NUnit and .NET integration problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nikpreek
    New Member
    • Jun 2007
    • 22

    Strange NUnit and .NET integration problem

    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\DataFi les 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.Reflecti on.Assembly.Get ExecutingAssemb ly().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
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by 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\DataFi les 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.Reflecti on.Assembly.Get ExecutingAssemb ly().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...

    Comment

    • TRScheel
      Recognized Expert Contributor
      • Apr 2007
      • 638

      #3
      Originally posted by 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\DataFi les 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.Reflecti on.Assembly.Get ExecutingAssemb ly().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
      Code:
      using system.windows.forms
      That gives you access to the application class, which has startup path. Use that instead

      Should be something like:

      Code:
      Application.StartupPath

      Comment

      • nikpreek
        New Member
        • Jun 2007
        • 22

        #4
        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

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Originally posted by nikpreek
          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

          Comment

          • arunelr
            New Member
            • Jun 2007
            • 1

            #6
            Originally posted by Frinavale
            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

            Comment

            Working...