Fake Assemblies show warnings when generating shims for Interface and stubs for sealed types

Tinu picture Tinu · Oct 15, 2013 · Viewed 7.9k times · Source

I have a build configured with CI post which some tests are run. Although the tests run successfully, the build shows warnings:

: Cannot generate stub for StructuremapMvc: type is sealed. : Cannot generate shim for IUnitOfWork: type is an interface. : Cannot generate shim for Repository.IRepository`1: type is an interface.

and so on.

I am using a generic repository pattern along with Unit Of Work. I have added Fake Assemblies for my MVC WebApi project (which leverages Dependency Injection using StructureMap) and Data project which contains my Repositories and UnitOfWork. I have explored this error and seem somewhat convinced that this maybe due to limitations of the Fake Assemblies, but I need to be absolutely sure that I am not doing anything wrong

Answer

user1069816 picture user1069816 · Jan 29, 2014

The way I got rid of these warnings was to only create the shims which are needed. I added the following to the fakes config file.

  <ShimGeneration>
    <Clear/>
    <Add FullName="ATypeToShim!"/>
    <Add FullName="AnotherTypeToShim!"/>
  </ShimGeneration>

The ! at the end of the filter makes it a precise case-sensitive match.

For stubs, I only ever stub interfaces so its easy:

<StubGeneration>
  <Clear />
  <Add Interfaces ="true"/>
</StubGeneration>

There are more details here: http://msdn.microsoft.com/en-us/library/hh708916.aspx#bkmk_type_filtering