question

NewCodee-7655 avatar image
0 Votes"
NewCodee-7655 asked PengGe-MSFT answered

How to de-route dll calls?

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?

dotnet-csharpvs-testing
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

PengGe-MSFT avatar image
0 Votes"
PengGe-MSFT answered

Hi, @NewCodee-7655

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.