1
votes

I want to use fakes(shims) to mock nj4x library. I followed the guidelines here to generate them: https://msdn.microsoft.com/en-us/library/hh549174.aspx

However fakes for some classes are not generated. I tried solutions suggested here: Shims are not generated for .NET methods

Shims are not generated for .NET methods

but still not working. When I build, I get this warning:

Cannot generate shim for nj4x.Strategy: Could not resolve assembly 'NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c'. Are you missing an assembly reference?.

My assembly file for now is

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/"
       Diagnostic="true">
  <Assembly Name="nj4x" Version="2.5.6.0"/>
  <ShimGeneration>
    <Clear/>
    <Add Namespace="nj4x!"/>
    <Add Namespace="nj4x.metatrader!"/>
  </ShimGeneration>
</Fakes>

I have tried several other thins too but not working. I am really stuck here.

1
Without downloading and trying it, my guess is that the '!' is pulling in some classes that are dependent on other assemblies. You might try only generating a Shim for a specific class (and only the one class). If that works, slowly add additional classes. - doobop
I have tried <ShimGeneration> <Clear/> <Add FullName="nj4x.Strategy"/> </ShimGeneration> - Usama Aslam
But does not work. - Usama Aslam
@doobop The exclamationmark means "a class named exactly this". So Usama expects the nj4x namespace to contain a type called metatrader. He also expects a type in the global namespace called nj4x, which is clearly incorrect. - TamaMcGlinn

1 Answers

0
votes

I don't really know why but once I add fakes for NLog, fakes for required classes of nj4x are generated.