Question

Is it possible to create a stub that implements HttpContent.ReadAsAsync<T> with the help of Microsoft Fakes (in Visual Studio 2012)? If so, how?

Was it helpful?

Solution

HttpContent.ReadAsAsync<T> cannot be stubbed in VS2012. Reason being that this is not a virtual method but an extension method. Only virtual interface/class method can be stubbed.

OTHER TIPS

For the sake of future searches...

Stubs can only override methods for their own instance. You can stub any type which exposes members that can be overridden, be it abstract, interface, or a class.

In this case, you could use a shim:

ShimHttpContent.ReadAsAsyncOf1<TypeYouWant> = *something matching the method signature*

The added advantage this offers is that you can now specify the behavior per type. This is one of the most valid reasons for using shims.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top