Visual Studio 2015, Microsoft Fakes and System.Security.Claims.Claim
Asked Answered
I

0

4

I have an interface in a .NET 4.5 (not 4.6) class library,

public interface IBrokenFakeInterface
{
    Claim WhyWontItGenerateFakeOfThisInterface();
}

In my unit test project (MSTest) when I have added the Fakes for the appropriate assembly containing this interface, I get compiler warning that says it cannot generate the stub.

Warning: Cannot generate stub for ClassLibrary1.IBrokenFakeInterface: method System.Security.Claims.Claim ClassLibrary1.IBrokenFakeInterface.WhyWontItGenerateFakeOfThisInterface() unstubbable: method is abstract and could not be stubbed, type System.Security.Claims.Claim is not available in the target framework version. ClassLibrary1Tests C:\Users\jacobsonba\Documents\Visual Studio 2015\Projects_tempFakeFiguringOut\ClassLibrary1Tests\Fakes\ClassLibrary1.fakes

While this is only a compiler warning, it results in compiler errors when a Unit Test project relies on StubIBrokenFakeInterface, because the Stub concrete type is not being created by the fakes generator.

Does anyone know the cause of this error, and a resolution? Changing the projects to be .NET 4.6 resolves it, but thats not a reasonable option for these projects for us. The exact same code compiles just fine in VS2013; in fact, if its compiled with VS2013, then open the solution in VS2015, it continues to work until the Fakes assembly is regenerated. So its obviously a problem in the fake generator that VS2015 is using.

Immanuel answered 21/7, 2015 at 13:50 Comment(5)
I've checked several more ASP.NET web projects of ours (~1000 unit tests per app), and this appears to be the only stub that the VS2015 fakes generator is having a problem with in our code base. For now, I've implemented a TestDouble class which alleviates the need for this particular stub. But its still annoying, and no idea if we'll run into other problems.Immanuel
I am seeing the same issue with Stubs that return MemoryStream. The issue is since Visual Studio 2013 Update 5Mccurdy
I'm having exactly the same problem. We have an issue with ClaimsIdentity and MemoryStreamJessikajessup
Just wanted to follow up; we've encountered no other stubs that had this problem.Immanuel
We've encountered the same problem with ClaimsIdentity. Follow up.Bob

© 2022 - 2024 — McMap. All rights reserved.