Why is Fake incorrectly referencing the Fakes dll from the pre-created fakes project?

I have a problem trying to reference the mscorlib fake DLL from individual projects, as described below.

I have numerous VS12 solutions for which I write unit tests using MS Fakes. Based on the assumption in the following URL, I decided to create a project only for my fake Dlls: Coding, compilation and naming conventions in Microsoft Fakes . The idea is that the location of the fake DLLs will be localized, and I won’t need to have a lot of fake DLLs scattered across all my test projects. (I will call this the usual library of fakes.)

In my current unit tests, I use gaskets from PresentationCore , System.Management and System . However, the system pads that I use are actually located in mscorlib.dll , in particular Convert (static class) and DriveInfo (private class). Since I only need these two classes from mscorlib (for now), I created the following .fakes file for mscorlib:

 <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/"> <Assembly Name="mscorlib" Version="4.0.0.0"/> <StubGeneration> <Clear/> </StubGeneration> <ShimGeneration> <Clear/> <Add FullName="Convert"/> <Add FullName="DriveInfo"/> </ShimGeneration> </Fakes> 

For PresentationCore and SystemManagement, I have similar .fakes files that clear and then add classes by name.

However, in my test project, when I add the link for mscorlib.4.0.0.0.Fakes DLL from my shared fake library, tests using the Convert and DriveInfo jumpers do not start. Instead, the Microsoft.QualityTools.Testing.Fakes.Shims.ShimNotSupportedException method is called in the test method, calling the unsupported pad class. Tests that use the functionality from PresentationCore and System.Management still work when referencing a library of common fakes.

However, if I add the Fakes assembly for the system directly (and indirectly indirectly) to my test project, create the same mscorlib.fakes file in my test project and add links to the local mscorlib.4.0.0.0.Fakes Dll, the tests that threw exceptions related to the common fake library were executed without fail.

I looked at the fake mscorlib library in a shared fake library using the Object Browser and compared it to a locally built one and they look the same.

Does anyone know why the mscorlib fake link in the shared fakes library doesn't work?

+4
source share
1 answer

The thing about fakes is that it is designed to restore the DLLs for each assembly. This is less important for system dlls, but worth remembering. You should probably keep them as part of the project, because you cannot be sure how they are interconnected for laying.

I don't know how pads are implemented, but they explicitly override methods at runtime. I think we will need a developer to answer it in more detail, but this may even be a problem with mscorlib, which already has a bit of scaly support for Fakes (by design).

Ultimately, your goal is to keep a couple of clicks on your test projects, at the risk of losing your fakes. The chances of this are not important - it is probably not worth making your tests less explicit.

The goal of tests is to reduce maintenance costs, so hiding things is less important for them than for your regular code; he simply adds steps to the maintenance process. Fakes are mysterious enough for most people without the extra stress "oh, but this is referred to indirectly ... Does it even work?"

0
source

Source: https://habr.com/ru/post/1497867/


All Articles