Fake assemblies show warnings when creating spacers for an interface and stubs for closed types

I have an assembly configured with a CI message in which some tests run. Although the tests succeed, the assembly shows warnings:

: Cannot create stub for StructuremapMvc: type sealed. : Unable to create pad for IUnitOfWork: type - this is the interface. : Cannot create pad for Repository.IRepository`1: type - this is an interface.

etc.

I use a common repository template with Unit of Work. I added Fake Assemblies for my MVC WebApi project (which uses Injection Dependency using StructureMap) and a Data project that contains my repositories and UnitOfWork. I investigated this error and it seems somewhat convinced that this is possible due to the limitations of Fake Assembly, but I must be absolutely sure that I am not doing anything wrong.

+7
c # unit-testing structuremap microsoft-fakes irepository
source share
2 answers

As I got rid of these warnings, it was only necessary to create gaskets. I added the following to the fakes configuration file.

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

The! at the end of the filter makes an exact match with the case.

For stubs, I only ever dug interfaces, so it's easy:

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

There is more detailed information here: http://msdn.microsoft.com/en-us/library/hh708916.aspx#bkmk_type_filtering

+15
source share

This is not really a limitation of fakes, but it is not a mistake. What you need to know is that there are plugs and gaskets.

The support is simple: it is a class that implements or extends a class, overriding each method using the delegation property, and a flag that determines whether it should then call the base class (note: this flag is for the entire stub, not for the method). You use them to inject dependencies, as they allow you to find all your logic in lambdas in code, rather than in the generated class. Because they extend non-interfaces, private classes cannot be drowned out.

Gaskets are more complex because they apply to any instance of a particular type. Not sure exactly how this is done, but what matters to you is that since the interface cannot have an instance, it cannot have spacers. This is great since you must use a stub. They are dangerous because with the help of a pad, you redefine the result of the function in the whole shimscontext and almost exclusively when something breaks that you do not have access - something that would be better to enter.

Therefore, I would not worry about warnings. They are not very important, just make sure you know what is going on.

+2
source share

All Articles