Search code examples
c#.netentity-frameworkunit-testingmicrosoft-fakes

How to isolate (detour) internal constructor with Microsoft Fakes shim?


I found bunch of examples with StreamReader but how to detour internal constructor? I need to create fakes of some public class with internal constructor to be able to test my code isolated.

Imagine I have

public class ChangesPostProcessor
{
    public void Process(IEnumerable<DbEntityEntry> changes)
    {
    ...
    }
 }

In this particular case I need to fake set of DbEntityEntry to be able to mock his numerous methods (working with DB) and test my logic isolated.


Solution

  • I have finally went with wrapper approach and implemented IDbEntityEnty interface with my own class with public constructor, containing DbEntityEntry inside. It lets me test but made me to rewrite enormous amount of code to change dependencies from DbEntityEntry to IDbEntityEntry.