Visual Studio 2012 Fakes not generating a stub for an interface that has a method with Stream return type
-
26-06-2021 - |
Question
Using Visual Studio 2012 to generate stubs with "Add Fakes Assembly", everything works as expected, except it is failing to generate a stub for this interface:
public interface IFileWrapper
{
IEnumerable<string> ReadLines(string path);
bool Exists(string path);
Stream OpenReadStream(string path);
}
When I change the Stream to a FileStream (as Stream is an abstract class and I wanted to check if this is only happening with abstract classes), I am still not able to generate.
When I remove the method signature completely (that is deleting Stream OpenReadStream(string path);
), I am able to generate the stub.
This is my .fake file content:
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true" Verbosity="Noisy">
<Assembly Name="System.IO.Abstractions"/>
<StubGeneration>
<Clear />
<Add AbstractClasses="true"/>
<Add Interfaces="true"/>
</StubGeneration>
<ShimGeneration>
<Clear />
</ShimGeneration>
</Fakes>
- Any idea why is this happening and how can I avoid it?
- There is supposed to be a Visual Studio output panel where the Fake generation results will display. I can't see any and they are not displaying in the regular build panel. Any ideas where I can find it? I searched all VS 2012 menus.
Solution
This is caused by a limitation in the Fakes' current implementation. You can work around this problem by switching the target framework in your unit test project from 4.0 to 4.5.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow