How to de-route dll calls?

NewCodee 1 Reputation point
2021-11-03T10:21:48.79+00:00

I have the following piece of code which needs to be unit tested:
namespace namespace1
{
public class A {
public void method( B obj) {
}
}
}

class B definition is something like this:
namespace namespace1
{
internal class B {
private MyWrapper myWrapper;

    public B() {
        this.myWrapper = new MyWrapper();
    }
}

}

Here MyWrapper class is in wrapper.dll file which needs to be faked,
namespace namespace2
{
public class MyWrapper {
public MyWrapper();
}
}

So far I tried creating shims for wrapper.dll. But the actual wrapper.dll cannot be accessed/referenced so I am getting a file not found exception.

Is there a way to de-route the 'new MyWrapper();' call?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,199 questions
Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
326 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. PengGe-MSFT 3,326 Reputation points
    2021-11-04T07:34:39.42+00:00

    Hi, @NewCodee

    Welcome to Microsoft Q&A!

    I created a project with reference to the code you provided, but the method (B obj) of class A will throw a compilation exception CS0051.
    Can your code run before unit testing? According to this document, The return type and parameter types of a method must be at least as accessible as the method itself.
    You can try to modify the access modifier of class B before unit testing.

    Sincerely,
    Peng
    *
    If you have extra questions about this answer, please click "Comment". If the answer is the right solution, please click "Accept Answer" and kindly upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments