Skip to content

Document extension method shimming #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 tasks
Miista opened this issue Jan 24, 2024 · 1 comment
Open
2 tasks

Document extension method shimming #27

Miista opened this issue Jan 24, 2024 · 1 comment
Assignees
Labels
documentation Improvements or additions to documentation priority: medium The issue has medium priority
Milestone

Comments

@Miista
Copy link
Owner

Miista commented Jan 24, 2024

Please refer to tonerdo/pose#22

I will add tests to ensure that we continue to support this.

  • Add tests (see below)
  • Update README with example

Tests

Defined using Called using Expected result
Static method invocation Static method invocation ✔️
Static method invocation Extension method invocation ✔️
Extension method invocation Static method invocation ✔️
Extension method invocation Extension method invocation ✔️
@Miista Miista added the question/investigation Further information or investigation is required label Jan 24, 2024
@Miista
Copy link
Owner Author

Miista commented Jan 25, 2024

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"; });

@Miista Miista self-assigned this Jan 25, 2024
@Miista Miista added the documentation Improvements or additions to documentation label Jan 25, 2024
@Miista Miista added the priority: medium The issue has medium priority label Jan 27, 2024
@Miista Miista added this to the v2.1 milestone Jan 27, 2024
@Miista Miista removed the question/investigation Further information or investigation is required label Jan 27, 2024
@Miista Miista modified the milestones: v2.1, v2.2 Jan 28, 2024
@Miista Miista changed the title Do we support shimming extension methods? Document extension method shimming Feb 21, 2024
@Miista Miista modified the milestones: v2.2, v2.1, v2.1.1 Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation priority: medium The issue has medium priority
Projects
None yet
Development

No branches or pull requests

1 participant