This is a migrated thread and some comments may be shown as answers.

Mocking Extension Methods?

2 Answers 73 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Imaji
Top achievements
Rank 1
Imaji asked on 25 Jun 2010, 08:39 AM
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 Answers, 1 is accepted

Sort by
0
Imaji
Top achievements
Rank 1
answered on 25 Jun 2010, 08:44 AM
Ignore this one, I spotted that I wasn't checking the parameters in the Assert, which was actually causing the method to be called!
0
Chris
Telerik team
answered on 01 Jul 2010, 01:26 PM
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
Tags
General Discussions
Asked by
Imaji
Top achievements
Rank 1
Answers by
Imaji
Top achievements
Rank 1
Chris
Telerik team
Share this question
or