公共
类
ClassUsingRefReturns
{
私人
静态
int
[] array = {1,2,3,4};
公共
裁判
int
GetRefReturnInstanceWithArgs (
裁判
int
p)
{
裁判
int
当地的=
裁判
数组[0];
局部+= p;
返回
裁判
当地的;
}
}
…
(TestMethod)
公共
无效
MockRefReturnInstanceMethodWithArgs ()
{
var localRef = localRef . withvalue (12);
/ /安排
var sut = Mock.Create();
模拟。一个rrange(sut, s => s.GetRefReturnInstanceWithArgs(
裁判
Arg.Ref (Arg.AnyInt) value)))
.Returns (localRef.Handle)
.OccursOnce ();
/ /行为
int
参数= 10;
裁判
int
res =
裁判
sut。GetRefReturnInstance (
裁判
参数);
/ /维护
Mock.Assert (sut);
Assert.AreEqual (localRef。Ref, res);
}