What would this Moq code look like in RhinoMocks

Hey people ... trying to figure out asp.net MVC.

I found this example on the net using Moq, basically I understand what it says: when ApplyAppPathModifier is called, return the value that was passed to it.

I can’t figure out how to do this in Rhino Mocks, any thoughts?

var response = new Mock<HttpResponseBase>(); response.Expect(res => res.ApplyAppPathModifier(It.IsAny<string>())) .Returns((string virtualPath) => virtualPath); 
+6
c # asp.net-mvc moq mocking rhino-mocks
source share
3 answers

As I mentioned above, it keeps the law, after you post it for reference, you will find it in 5 minutes (even after some searching). In any case, in the interests of others, this works:

 SetupResult .For<string>(response.ApplyAppPathModifier(Arg<String>.Is.Anything)).IgnoreArguments() .Do((Func<string, string>)((arg) => { return arg; })); 
+3
source share

If you use the stub method as opposed to the SetupResult method, the syntax for this is below:

 response.Stub(res => res.ApplyAppPathModifier(Arg<String>.Is.Anything)) .Do(new Func<string, string>(s => s)); 
+8
source share

If I read the code incorrectly, I think you can simplify this a bit. Try the following:

 var response = MockRepository.GenerateMock<HttpResponseBase>(); response.Stub(res => res.ApplyAppPathModifier(Arg<String>.Is.Anything)) .IgnoreArguments() .Return(virtualPath); 
+1
source share

All Articles