gpt4 book ai didi

vb.net - 在 VB.NET 中使用 Rhino Mocks 的 Expect.Call 来模拟属性

转载 作者:行者123 更新时间:2023-12-02 06:55:28 24 4
gpt4 key购买 nike

以下 C# 代码运行良好,测试按预期通过。

using NUnit.Framework;
using Rhino.Mocks;

namespace RhinoMocksTesting
{
public interface ITesting
{
string Test { get; }
}

[TestFixture]
public class MocksTest
{

[Test]
public void TestMockExpect()
{
var mocks = new MockRepository();
var testMock = mocks.StrictMock<ITesting>();
Expect.Call(testMock.Test).Return("testing");
mocks.ReplayAll();
Assert.AreEqual("testing", testMock.Test);
}
}
}

但是,尝试在 VB.NET 中执行相同的操作甚至无法编译!

Imports NUnit.Framework
Imports Rhino.Mocks

Public Interface ITesting
ReadOnly Property Test() As String
End Interface

<TestFixture()> _
Public Class MocksTest

<Test()> _
Public Sub TestMockExpect()
Dim mocks = New MockRepository
Dim testMock = mocks.StrictMock(Of ITesting)()
Expect.Call(testMock.Test).Return("testing")
mocks.ReplayAll()
Assert.AreEqual("testing", testMock.Test)
End Sub

End Class

Expect.Call 行产生以下构建错误:“重载解析失败,因为没有可访问的“Expect”接受此数量的参数。”

在 VB.NET 中将 Expect.Call 与模拟属性一起使用的正确方法是什么?我看过几篇文章,说 Rhino Mocks 在 VB10 中工作得更好,但对于当前的项目,我坚持使用 Visual Studio 2008。

最佳答案

尝试

Rhino.Mocks.Expect.Call(testMock.Test).Return("testing")

Source

Now we switch to Rhino mocks 3.5 and see that we get an error on Expect saying that the signature is not correct. No worry this is because it is choosing the wrong Expect. It is namely trying to use the extension method there. Just add Rhino.Mocks. before the Expect and all is well again. Look how the imports doesn't do the same thing.

关于vb.net - 在 VB.NET 中使用 Rhino Mocks 的 Expect.Call 来模拟属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6446354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com