Search code examples
c#visual-studio-2010unit-testingc++-cliunittest2

Unit Testing a c# project which uses native code


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


Solution

  • 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.