FakeItEasy Proxy methods calls to real implementation

北城以北 提交于 2019-12-04 05:24:40

Stealing from my response at the FakeItEasy github repository:

You can create a fake to wrap an existing object like so:

var wrapped = new FooClass("foo", "bar");
var foo = A.Fake<IFoo>(x => x.Wrapping(wrapped));

(example taken from Creating Fakes > Explicit Creation Options)

That should delegate all calls to the underlying object, with the usual caveat that any redirected calls have to be overrideable.

I hope this helps. If not, come back and explain again. Maybe I'll understand it better.

Oh, and beware the Configure mechanism. It's going away in FakeItEasy 2.0.0. The preferred idiom is

A.CallTo(fake).Invokes(…); // or
A.CallTo(fake).WithReturnType<bool>(…); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!