Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fakes assembly is not generating

I can't figure out what I need to do to generate Fakes. In my test project I included a reference to the assembly that I want to fake. It added /Fakes/<assembly name>.fakes to my project and it built the project. There were a ton of warnings, but there are 0 errors and the build completed successfully. But it is not adding any reference to the generated .Fakes assembly.

Most of the warnings were things like cannot generate stubs or shims for an enum, or some private class is not visible to the fakes assembly. There's really only 1 class in the assembly that I want to Shim, and nothing that I want to Stub. So I edited the .fakes file:

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/"
       Diagnostic="true">
  <Assembly Name="[assembly name]">
    <StubGeneration>
      <Clear />
    </StubGeneration>
    <ShimGeneration>
      <Clear />
      <Add Namespace="[namespace that the 1 class I want to shim is in]" />
    </ShimGeneration>
  </Assembly>
</Fakes>

I cleaned and rebuilt the project, and I am still getting tons of warnings, and no errors, that it can't stub or shim classes that I have excluded in the .fakes file, and the .Fakes assembly is still not getting generated.

How do I actually I stop it from trying to create stubs and only creating shims for classes that are in a specific namespace? The information from http://msdn.microsoft.com/en-us/library/hh708916.aspx is, apparently, not correct.

Also, I removed the Version attribute from the Assembly element, but the warnings that I'm getting still include the version number in the namespace. What's up with that?

like image 932
Nick Avatar asked Apr 30 '14 13:04

Nick


1 Answers

I found out what my problem was. I thought StubGeneration and ShimGeneration were supposed to be child elements of Assembly, but they aren't. They are supposed to be children of Fakes, and siblings of Assembly. After changing my .fakes file to this, it works:

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/"
       Diagnostic="true">
  <Assembly Name="[assembly name]" />
  <StubGeneration>
    <Clear />
  </StubGeneration>
  <ShimGeneration>
    <Clear />
    <Add Namespace="[namespace that the 1 class I want to shim is in]" />
  </ShimGeneration>
</Fakes>
like image 74
Nick Avatar answered Oct 17 '22 14:10

Nick