aknuds1
aknuds1

Reputation: 68127

Can I fake HttpContent.ReadAsAsync<T>?

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?

Upvotes: 2

Views: 1407

Answers (2)

Magus
Magus

Reputation: 1312

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.

Upvotes: 0

Patrick Tseng
Patrick Tseng

Reputation: 264

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.

Upvotes: 4

Related Questions