You could write something like this lovely code to verify the expression
tree:

((MemberExpression)((MethodCallExpression)exp.Body).Arguments[0]).Member ==
typeof(View).GetProperty("Keyword");

But that seems... less than ideal.

If I were tackling this, I would abandon the idea of inspecting the lambda
to verify its correct and instead execute it and verify that it behaves as
expected. So instead of mocking the repository stub it, have it contain a
list of a few dummy items, do a FindAll on the list using the lambda, and
verify that it only returned items with "foo" in the description.

Paul Batum

On Fri, Sep 12, 2008 at 9:19 PM, Lee <[EMAIL PROTECTED]> wrote:

>
> I am writing a test (TDD) for an MVP app. I want to test that the
> presenter gets the proper values from the
> view and passes them in a lambda to the model. For Example:
>
> the view has a "Keyword" property that returns the value the user
> typed in. I am mocking that and passing back "foo". The presenter
> should build a lambda with that value and pass it to an NHibernate
> repository's Search<Item>(Expression) method like so:
>
>  repository.Search<Item>(x=>x.Description.Contains(view.Keyword));
>
> In my test, I mock the repository and the view, so the SUT is the
> presenter. All I want to verify is that the lambda tha the presenter
> sent is "x=>x.Description.Contains("foo")" but It never matches.
>
> I create the lambda:
>
>  Expression<Func<Item, bool>> expr = x =>
> x.Description.Contains("foo");
>
> When I Console.WriteLine it out, the Lambda coming from the presenter
> looks like this:
>
>
>
> x=>x.Description.Contains(value(Project.Presentation.SearchPresenter).view.Keyword))
>
> and the lambda in my test looks like:
>
>  x=>x.Description.Contains("foo")
>
> so they are never going to match up.
>
> Any ideas how I can test that my lambda is good?
>
> Thanks in advance.
>
> ~Lee
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to