我有类似这样的测试代码:
Public Interface IDoSomething
Function DoSomething(index As Integer) As Integer
End Interface
<Test()>
Public Sub ShouldDoSomething()
Dim myMock As IDoSomething = MockRepository.GenerateMock(Of IDoSomething)()
myMock.Stub(Function(d) d.DoSomething(Arg(Of Integer).Is.Anything))
.WhenCalled(Function(invocation) invocation.ReturnValue = 99)
.Return(Integer.MinValue)
Dim result As Integer = myMock.DoSomething(808)
End Sub
这段代码的行为并不像预期的那样。正如预期的那样,该变量不result
包含Integer.MinValue
99。
如果我用 C# 编写等效代码,它会按预期工作:result
包含 99。
任何想法为什么?
C# 等价物:
public interface IDoSomething
{
int DoSomething(int index)
}
[test()]
public void ShouldDoSomething()
{
var myMock = MockRepository.GenerateMock<IDoSomething>();
myMock.Stub(d => d.DoSomething(Arg<int>.Is.Anything))
.WhenCalled(invocation => invocation.ReturnValue = 99)
.Return(int.MinValue);
var result = myMock.DoSomething(808);
}