Mocking Extension Methods?

3 posts, 0 answers
  1. Imaji
    Imaji avatar
    15 posts
    Member since:
    Apr 2007

    Posted 25 Jun 2010 Link to this post

    Hi,

    Is there any specific syntax I should be mocking Extension Methods?

    Currently I'm trying to mock that an extension method called AddToRegion on RegionManager from PRISM is mocked.  The code looks a bit like this:

    var stubRegionManager = Mock.Create<IRegionManager>();

    Mock.Arrange(() => stubRegionManager.AddToRegion(Arg.Any<string>(), Arg.Any<object>()).Returns(stubRegionManager);

    Then I inject regionManager into the class in question.  The problem is the method isn't mocked and the original is called.

    Any ideas?

    Cheers,
    John
  2. Imaji
    Imaji avatar
    15 posts
    Member since:
    Apr 2007

    Posted 25 Jun 2010 Link to this post

    Ignore this one, I spotted that I wasn't checking the parameters in the Assert, which was actually causing the method to be called!
  3. DevCraft R3 2016 release webinar banner
  4. Chris
    Admin
    Chris avatar
    221 posts

    Posted 01 Jul 2010 Link to this post

    Hi Imaji,
    Should you have any additional questions or problems, please do not hesitate to contact us.

    Kind regards,
    Chris
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top