public void ReturnsOrderedResults()
            {
                var query = new FindPeopleWithLastNameQuery
                {
                    Term = "t",
                    TermMatchStrategy = StringMatchStrategy.Contains,
                    OrderBy = new Dictionary<Expression<Func<Person, object>>, OrderByDirection>
                    {
                        { p => p.LastName, OrderByDirection.Descending },
                        { p => p.FirstName, OrderByDirection.Ascending },
                    }
                };
                var fakes = FakePeople();
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict);
                entities.Setup(p => p.Query<Person>()).Returns(fakes);
                entities.Setup(m => m.EagerLoad(fakes,
                    It.IsAny<Expression<Func<Person, object>>>())).Returns(fakes);
                var handler = new FindPeopleWithLastNameHandler(entities.Object);

                var results = handler.Handle(query);

                results.ShouldNotBeNull();
                results.Count().ShouldEqual(4);
                results.Skip(0).First().LastName.ShouldEqual(fakes.Skip(3).First().LastName);
                results.Skip(1).First().LastName.ShouldEqual(fakes.Skip(2).First().LastName);
                results.Skip(2).First().LastName.ShouldEqual(fakes.Skip(1).First().LastName);
                results.Skip(3).First().LastName.ShouldEqual(fakes.Skip(0).First().LastName);
            }
            public void DoesNotFindPeopleWithLastName_NotContainingTerm()
            {
                var query = new FindPeopleWithLastNameQuery
                {
                    Term = "th",
                    TermMatchStrategy = StringMatchStrategy.Contains,
                };
                var fakes = FakePeople();
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict);
                entities.Setup(p => p.Query<Person>()).Returns(fakes);
                entities.Setup(m => m.EagerLoad(fakes,
                    It.IsAny<Expression<Func<Person, object>>>())).Returns(fakes);
                var handler = new FindPeopleWithLastNameHandler(entities.Object);

                var results = handler.Handle(query);

                results.ShouldNotBeNull();
                results.Count().ShouldEqual(2);
                results.ToList().ForEach(i => i.LastName.ShouldNotEqual("West"));
            }
            public void QueriesPeople_WithEagerLoading()
            {
                var query = new FindPeopleWithLastNameQuery
                {
                    Term = "test",
                    EagerLoad = new Expression<Func<Person, object>>[]
                    {
                        p => p.Emails.Select(e => e.Confirmations),
                        p => p.Messages,
                    },
                };
                var fakes = FakePeople();
                var entities = new Mock<IQueryEntities>(MockBehavior.Strict);
                entities.Setup(p => p.Query<Person>()).Returns(fakes);
                entities.Setup(m => m.EagerLoad(fakes,
                    It.IsAny<Expression<Func<Person, object>>>())).Returns(fakes);
                var handler = new FindPeopleWithLastNameHandler(entities.Object);

                handler.Handle(query);

                entities.Verify(p => p.Query<Person>(), Times.Once());
                entities.Verify(m => m.EagerLoad(fakes,
                    It.IsAny<Expression<Func<Person, object>>>()),
                        Times.Exactly(query.EagerLoad.Count()));
            }