如何在 VB.Net 中使用 RhinoMocks 模拟一种方法?我找到的参考是在 C# 中:
Expect.Call(delegate{list.Add(0);}).IgnoreArguments()
.Do((Action<int>)delegate(int item) {
if (item < 0) throw new ArgumentOutOfRangeException();
});
SharpDevelop 将其转换为:
Expect.Call(Function() Do
list.Add(0)
End Function).IgnoreArguments().Do(DirectCast(Function(item As Integer) Do
If item < 0 Then
Throw New ArgumentOutOfRangeException()
End If
End Function, Action(Of Integer)))
但这也不起作用(它无法编译)。
这就是我想要做的:创建一个新对象并调用一个方法来设置该方法的一些属性。在现实生活中,此方法将使用在数据库中找到的值填充属性。在测试中,我想使用自定义方法/委托来模拟此方法,以便我可以自己设置属性(无需访问数据库)。
在伪代码中,这就是我想要做的:
Dim _lookup As LookUp = MockRepository.GenerateMock(Of LookUp)()
_luvalue.Expect(Function(l As LookUp) l.GetLookUpByName("test")).Do(Function(l As LookUp) l.Property = "value")