这个Moq代码在RhinoMocks中会是什么样子

Kei*_*ith 8 c# asp.net-mvc rhino-mocks moq mocking

嘿人...试图让我的模拟与asp.net MVC分类.

我在网上使用Moq找到了这个例子,基本上我理解它说:当调用ApplyAppPathModifier时,返回传递给它的值.

我无法弄清楚如何在Rhino Mocks中做到这一点,有什么想法吗?

var response = new Mock<HttpResponseBase>();
response.Expect(res => res.ApplyAppPathModifier(It.IsAny<string>()))
            .Returns((string virtualPath) => virtualPath);
Run Code Online (Sandbox Code Playgroud)

Dow*_*pel 10

如果您使用的是stub方法而不是SetupResult方法,那么语法如下:

response.Stub(res => res.ApplyAppPathModifier(Arg<String>.Is.Anything))
                .Do(new Func<string, string>(s => s));
Run Code Online (Sandbox Code Playgroud)


Kei*_*ith 3

正如我上面提到的,草皮法则,一旦你发帖寻求帮助,你会在 5 分钟后找到它(即使是在搜索了一段时间之后)。无论如何,为了他人的利益,这是有效的:

SetupResult
    .For<string>(response.ApplyAppPathModifier(Arg<String>.Is.Anything)).IgnoreArguments()
    .Do((Func<string, string>)((arg) => { return arg; }));
Run Code Online (Sandbox Code Playgroud)