1

I have three projects

1)unmanaged c++ containing full business logic

2)C++/CLI (Project name managed)

3)C# GUI

I have added the library file of unmanaged c++ in C++/CLI and then dll of C++/CLI in C# project.This this all is working fine and execution is trouble-less.

Now i want to do unit testing of C# function that does call the C++/CLI wrapper and then get the results back.I created a unit test using Visual Studio 2010.I added the dll of C++/CLI in my test project.Now when i am trying to execute the test it throws the exception managed.dll not found

Here is the code

   [TestMethod()]
   public void getstateTest()
   {
    bool expected=true;
    bool actual=false;
    try
     {
        GUI.test target = new test();
        expected    = true; // TODO: Initialize to an appropriate value
        actual      = target.getstate();
     }
     catch (FileNotFoundException exception)
     {
        MessageBox.Show("Missing file is : " + exception.FileName);
     }
     Assert.AreEqual(expected, actual);
    }



    The getstate function is

namespace GUI
{
public class test
{
    public bool getstate()
    {
        bool chk = false;
        bool result;
        String a = "some path";
        String b = "some path"
        String c = "some path"
        managed  objct;
        objct = new  managed();
        objct.Initialize(a, b, c, chk);
        objct.Execute();//calls the C++/CLI execute which calls unmanaged C++
        result = objct.Executionresult();//gets a bool result
        return result;
    }
}

}

Same thing works fine when i run the application but on running the test project it says the dll is missing

Sorry if i made it confusing.Please ask if you need more information.Thanks in advance

manu_dilip_shah
  • 880
  • 14
  • 32

2 Answers2

1

Have you looked at the test project output folder ? Maybe the managed.dll isn't copied to the output.

Update:

Could you please post fusion log from the exception ? This should give some ideas why the file is not found.

Dmitry Reznik
  • 6,812
  • 2
  • 32
  • 27
0

The projects are probably compiling to different directories.

This causes the compiler to compile correctly, but at runtime it can't find the files.

This often happens when you import separate projects into a new solution.

Make the new Unit test compile to the same directory.

Yochai Timmer
  • 48,127
  • 24
  • 147
  • 185