Geeks With Blogs

News Please visit me at my new blog!!

profile for Aligned at Stack Overflow, Q&A for professional and enthusiast programmers
"free in Christ Jesus from the law of sin and death." Romans 8:2 (ESV) Check out the Falling Plates video on YouTube.
more about the Gospel
And then listen to Francis Chan speaking at LifeLight in SD.

Programming and Learning from SD
I was trying to do a partial mock in FakeItEasy and kept getting "The current proxy generator can not intercept the specified method for the following reason: - Sealed methods can not be intercepted".

The fix is to make the method virtual. (notice the A.Fake<LayoutManager>, not A.Fake<ILayoutManager> for the partial mock)
var layoutManagerFake = A.Fake<LayoutManager>();
A.CallTo(() => layoutManagerFake.UpdateAssigned(1, assigned, "user")).CallsBaseMethod();
In LayoutManager (note the virtual)
public virtual void UpdateAssigned(int layoutId, List<int> assignedList, string updateType)
 // do stuff
Then the exception goes away
Posted on Tuesday, March 12, 2013 3:09 PM Unit Testing , Mocking | Back to top

Comments on this post: FakeItEasy - Sealed Methods can not be intercepted exception

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Aligned | Powered by: