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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With