Skip to content
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

Query model for received calls #18

Closed
dtchepak opened this issue Jul 15, 2010 · 3 comments
Closed

Query model for received calls #18

dtchepak opened this issue Jul 15, 2010 · 3 comments

Comments

@dtchepak
Copy link
Member

Adding this as a placeholder for the feature while it is being planned.

Rather than expanding the API to support things like "received 4 times", it might be better to encapsulate that in a nice query model. Currently have ReceivedCalls() : IEnumerable as a starting point, but will need to add some convenience methods for selecting calls to particular members (probably using lambdas/expressions).

@Saulis
Copy link

Saulis commented Mar 11, 2012

Is this something you were thinking of?

Saulis@5a019d6

Something like _engine.ReceivedCalls(x => x.Rev()) which returns IEnumerable ?

I'm planning on using the IsSatisfiedBy(ICall) method in ICallSpecification inside the CallRouter. What do you think?

I just need to figure out what would be the best way of creating a CallSpecification object from an expression tree. The MethodInfo was easy but now I need to create the ArgumentSpecifications from the arguments.

@Saulis
Copy link

Saulis commented Mar 11, 2012

Added more stuff to my branch: https://github.com/Saulis/NSubstitute/tree/QueryModel

I extended the CallSpecFactory to create specifications from a expression tree, which turned out to be much simpler than I originally thought. It currently supports only expressions with constant and method call parameters.

With method call parameters I had to actually compile and invoke the methods in order to get the value evaluated.
Invoking the argument specs adds them to the argument specs queue from which they can be then dequeued and returned.

object result = InvokeMethod(methodCall);

var argumentSpecifications = _context.DequeueAllArgumentSpecifications();
                
if (argumentSpecifications.Any())
{
    yield return argumentSpecifications.Single();
}
else
{
    yield return new ArgumentSpecification(result.GetType(), new EqualsArgumentMatcher(result));
}

Comments? Anything I'm missing here?

@dtchepak
Copy link
Member Author

dtchepak commented Feb 3, 2013

Basis for queries implemented in v1.5. Currently only used for Received.InOrder.

@dtchepak dtchepak closed this as completed Feb 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants