Exemplo n.º 1
0
            public void ReturnsOrderedResults()
            {
                var query = new FindPeopleWithEmailQuery
                {
                    Term = ".tld",
                    TermMatchStrategy = StringMatchStrategy.Contains,
                    OrderBy           = new Dictionary <Expression <Func <Person, object> >, OrderByDirection>
                    {
                        { p => p.LastName, OrderByDirection.Ascending },
                        { p => p.FirstName, OrderByDirection.Descending },
                    }
                };
                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 FindPeopleWithEmailHandler(entities.Object);

                var results = handler.Handle(query);

                results.ShouldNotBeNull();
                results.Count().ShouldEqual(4);
                results.Skip(0).First().FirstName.ShouldEqual(fakes.Skip(3).First().FirstName);
                results.Skip(1).First().FirstName.ShouldEqual(fakes.Skip(2).First().FirstName);
                results.Skip(2).First().FirstName.ShouldEqual(fakes.Skip(1).First().FirstName);
                results.Skip(3).First().FirstName.ShouldEqual(fakes.Skip(0).First().FirstName);
            }
Exemplo n.º 2
0
            public void QueriesPeople_WithEagerLoading()
            {
                var query = new FindPeopleWithEmailQuery
                {
                    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 FindPeopleWithEmailHandler(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()));
            }
Exemplo n.º 3
0
            public void DoesNotFindPeopleWithEmail_NotContainingTerm()
            {
                var query = new FindPeopleWithEmailQuery
                {
                    Term = "site",
                    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 FindPeopleWithEmailHandler(entities.Object);

                var results = handler.Handle(query);

                results.ShouldNotBeNull();
                results.Count().ShouldEqual(2);
                results.ToList().ForEach(i => i.LastName.ShouldNotEqual("North"));
            }