Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I easily replace a Microsoft Fakes assembly?

It's easy to add a Microsoft Fakes assembly to a test project: just right click on the parent assembly in the references section and choose "Add Fakes Assembly". However, when the parent assembly public interface changes (new interfaces, new methods), the Fakes Assembly becomes out of date.

When I right click on the parent assembly again, I'd love to see "Replace Fakes Assembly" or "Update Fakes Assembly", but all I see is "Add Fakes Assembly".

Choosing "Add Fakes Assembly" when the Fakes assembly has already been added results in an error:

Fakes assembly already referenced. A Fakes assembly for is already in the reference list. Remove the .Fakes reference and try again.

After following the instructions, then choosing "Add Fakes Assembly", the same error occurs.

I can resolve this by deleting the corresponding xml file in the Fakes directory (.fakes).

So, I have to manually delete two items (the fakes assembly and the fakes xml file) before I can successfully update the fakes assembly.

Is there an easier or more straightforward way to do this?

like image 444
woman among men Avatar asked Jan 11 '13 20:01

woman among men


People also ask

What is ADD fakes Assembly?

When you click on “Add Fakes Assembly” it will create the same assembly again with the Fakes keyword added that we will use for our testing purposes. The Fakes framework uses delegate-based methods for writing code.

What is a shim c#?

Shim, in C#, is a template class that is derived from a base class with derived classes that inherit the data and behavior of the base class and vary only in the type. The derived class of the shim class reuses the implementation provided by the shim class.


1 Answers

The Fakes code generator automatically detects changes in visible API of the target assembly and regenerates the fakes assembly when necessary. When the target assembly changes, simply build the test project that contains its .Fakes file.

like image 162
Oleg Sych Avatar answered Oct 22 '22 10:10

Oleg Sych