Ejemplo n.º 1
0
            public void DoesNotFindPeopleWithFirstName_NotContainingTerm()
            {
                var query = new FindPeopleWithFirstNameQuery
                {
                    Term = "am",
                    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 FindPeopleWithFirstNameHandler(entities.Object);

                var results = handler.Handle(query);

                results.ShouldNotBeNull();
                results.Count().ShouldEqual(2);
                results.ToList().ForEach(i => new[]
                {
                    fakes.ToArray()[1].FirstName,
                    fakes.ToArray()[2].FirstName
                }.ShouldNotContain(i.FirstName));
            }
Ejemplo n.º 2
0
            public void ReturnsOrderedResults()
            {
                var query = new FindPeopleWithFirstNameQuery
                {
                    Term = "a",
                    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 FindPeopleWithFirstNameHandler(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);
            }
Ejemplo n.º 3
0
            public void QueriesPeople_WithEagerLoading()
            {
                var query = new FindPeopleWithFirstNameQuery
                {
                    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 FindPeopleWithFirstNameHandler(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()));
            }
Ejemplo n.º 4
0
            public void FindsPeopleWithFirstName_StartingWithTerm()
            {
                var query = new FindPeopleWithFirstNameQuery
                {
                    Term = "daniel",
                    TermMatchStrategy = StringMatchStrategy.StartsWith,
                };
                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 FindPeopleWithFirstNameHandler(entities.Object);

                var results = handler.Handle(query);

                results.ShouldNotBeNull();
                results.Count().ShouldEqual(2);
                results.ToList().ForEach(i => i.FirstName.ShouldStartWith("Daniel"));
            }