示例#1
0
            public void ThrowsValidationException_WhenQueryTermIsWhiteSpace()
            {
                var handler = new FindPeopleWithEmailHandler(null);
                ValidationException exception = null;

                try
                {
                    handler.Handle(new FindPeopleWithEmailQuery
                    {
                        Term = "\n"
                    });
                }
                catch (ValidationException ex)
                {
                    exception = ex;
                }

                exception.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                exception.Errors.ShouldNotBeNull();
                // ReSharper restore PossibleNullReferenceException
                exception.Errors.Count().ShouldEqual(1);
                var exceptionError = exception.Errors.Single();

                exceptionError.PropertyName.ShouldEqual("Term");
                exceptionError.ErrorMessage.ShouldEqual("Term cannot be null or white space string");
                exceptionError.AttemptedValue.ShouldEqual("\n");
            }
示例#2
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);
            }
示例#3
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()));
            }
示例#4
0
            public void ThrowsArgumentNullException_WhenQueryArgIsNull()
            {
                var handler = new FindPeopleWithEmailHandler(null);
                ArgumentNullException exception = null;

                try
                {
                    handler.Handle(null);
                }
                catch (ArgumentNullException ex)
                {
                    exception = ex;
                }

                exception.ShouldNotBeNull();
                // ReSharper disable PossibleNullReferenceException
                exception.ParamName.ShouldEqual("query");
                // ReSharper restore PossibleNullReferenceException
            }
示例#5
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"));
            }