質問

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?

役に立ちましたか?

解決

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.

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top