我想做类似下面的事情,但似乎无法完全正确地获得 Do 方法的语法。
var sqr = new _mocks.CreateRenderer<ShapeRenderer>();
Expect.Call(sqr.CanRender(null)).IgnoreArguments().Do(x =>x.GetType() == typeof(Square)).Repeat.Any();
所以基本上,我想设置 sqr.CanRender() 方法,如果输入是 Square 类型,则返回 true,否则返回 false。
最佳答案
你在找这个吗?
Expect.Call(sqr.CanRender(null)).IgnoreArguments()
.Do((Func<Shape, bool>) delegate(Agent x){return x.GetType() == typeof(Square);})
.Repeat.Any();
编辑:答案在精神上是正确的,但原始语法不太有效。
关于c# - 犀牛模拟 : How to return conditional result from a mock object method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/313030/