pose icon indicating copy to clipboard operation
pose copied to clipboard

Extension Method Replacement

Open Dreamwalker666 opened this issue 6 years ago • 7 comments

How do you use pose to replace extension methods?

I've tried replacing with Extension.MyExtension<T>(this myClass, T value) and also myClass.MyExtension(T value) and both fail to use the replacement code and use the original.

Is this possible? I realise I am probably doing something wrong or is it because it's a generic?

Dreamwalker666 avatar May 03 '18 12:05 Dreamwalker666

Pose cannot currently shim extension methods

tonerdo avatar May 08 '18 20:05 tonerdo

Is this feature being considered? This was my main use case for pulling in this library - disappointed to see its not currently supported. I haven't been able to find a .NET Standard friendly way of shimming an extension method at this point.

k-schneider avatar Jul 09 '18 22:07 k-schneider

Hi @k-schneider, currently revisiting the feature list for Pose and will add this to the backlog

tonerdo avatar Jul 10 '18 10:07 tonerdo

Count me as another vote for shimming of extension methods. I need this ability so I can test ASP.NET code that uses Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions such as the GetRequiredService<T>() method. Really frustrating that Microsoft chose to implement the functionality in such an untestable way!

SamerAdra avatar Aug 09 '18 18:08 SamerAdra

@Dreamwalker666 on second thought I think this might be supported just not very obvious. Can you paste a snippet of your code?

tonerdo avatar Aug 11 '18 15:08 tonerdo

Well I feel embarrased I didn't have the original code I was using. So I whipped up a quick test project that was similar in layout to what I was previously testing and it works :S

So I think something else may have been causing a problem or I missed something before.

I have attached the project I made is this how you were excpecting it to work?

PoseExtensionMethodTest.zip

Dreamwalker666 avatar Aug 13 '18 14:08 Dreamwalker666

@Dreamwalker666 I can confirm that v2.0 does support shimming extension method. Please refer to Miista/Pose#27

cc: @k-schneider @SamerAdra @tonerdo @azaytsev-csr @efotin

Miista avatar Jan 25 '24 18:01 Miista