RhinoMocks Stub 返回真实实例

发布于 2024-08-26 07:55:36 字数 864 浏览 1 评论 0原文

我正在尝试使用 RhinoMocks 来删除第三方组件。第三方组件如下所示。

public class connection
{
    public connection(string host,int port)
    {}

    public void Submit(message msg)
    {}
}

public class message
{
    public message(string recipient)
    {}
{

当我尝试使用存根时,它会返回对象的实际实例,并且如果我使用有效的主机和端口,我的消息将实际发送。如果我不使用有效的主机或端口,连接对象上的构造函数将引发异常。我不想要一个真实的物体,我只想要一个存根。我缺少什么?下面是我的代码。

        Connection con = MockRepository.GenerateStub<Connection>("host", 25);
        Message msg = new Message("[email protected]");
        msg.AddRecipient(new Recipient("[email protected]"));
        con.Submit(msg);

I'm trying to use RhinoMocks to stub out a third party component. The third party component looks like the following.

public class connection
{
    public connection(string host,int port)
    {}

    public void Submit(message msg)
    {}
}

public class message
{
    public message(string recipient)
    {}
{

When I attempt to use a stub it instead returns an actual instance of the object and my message will actually be sent if I use a valid host and port. If I don't use a valid host or port the constructor on the connection object throws an exception. I don't want a real object I just want a stub. What am I missing? Below is my code.

        Connection con = MockRepository.GenerateStub<Connection>("host", 25);
        Message msg = new Message("[email protected]");
        msg.AddRecipient(new Recipient("[email protected]"));
        con.Submit(msg);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文