-
-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Capture with ProtectedSetup #934
Comments
Thanks for reporting. Looks like we're missing something like |
If you're happy with Otherwise, I'll leave it to you |
I can't say that I am (see my post above). I'd first like to check for alternative solutions. If there aren't any better solutions, I'll get back to you about |
@cheng93, sorry for the long silence. I've been busy. It's a shame I didn't think of this before, but there's actually already a way to use Say this is the type you're going to mock: public abstract class Foo
{
public void InvokeMethod(string arg) => Method(arg);
protected abstract void Method(string arg);
} You want to set up the protected method, public interface FooProtectedMembers
{
void Method(string arg);
} Note that the type to be mocked ( Now you can set up var fooMock = new Mock<Foo>();
var capturedArgs = new List<string>();
fooMock.Protected().As<FooProtectedMembers>().Setup(foo => foo.Method(Capture.In(capturedArgs))); That is, Let's verify that it actually works: fooMock.Object.InvokeMethod("hello");
fooMock.Object.InvokeMethod("bye");
Assert.Equal(new[] { "hello", "bye" }, capturedArgs); Let me know if this solution is sufficient. If I don't hear back from you sometime during the next two weeks or so, I'm going to assume it is & I'll close this as resolved. |
Wow, this is a very neet trick! I was suggesting to add this to the quick start guide, but I just noticed that the information was mentioned there, but not as easily accessible as it was done in the above example. So I extended the quick start wiki examples make it more accessible. |
Works quite well |
Capture's with ProtectedSetup does not work.
For example
throws the following exception
Expected outcome
request
is capturedThe text was updated successfully, but these errors were encountered: