Open Miista opened 8 months ago
I can confirm that we do support shimming extension methods. Please see the following MVE:
public static class IntExtensions
{
// The extension method defaults to stringifying the int
public static string GetFunnyName(this int i) => i.ToString();
}
public class Program
{
public static void Main(string[] args)
{
var extensionShim = Shim
.Replace(() => IntExtensions.GetFunnyName(Is.A<int>()))
// We overwrite the extension method to simply return "H"
.With(delegate(int i) { return "H"; });
PoseContext.Isolate(()=>
{
var i = 0;
Console.WriteLine(i.GetFunnyName());
}, extensionShim);
}
}
Please note that the shim can be defined in one of the following ways.
Static method invocation
Shim
.Replace(() => IntExtensions.GetFunnyName(Is.A<int>()))
.With(delegate(int i) { return "H"; });
Extension method invocation
Shim
.Replace(() => Is.A<int>().GetFunnyName())
.With(delegate(int i) { return "H"; });
Please refer to tonerdo/pose#22
I will add tests to ensure that we continue to support this.
Tests