コード例 #1
0
        public void NameSearchNotFound_Test()
        {
            // Generate persons
            var persons = new List <Person>
            {
                new Person {
                    FirstName = "Anne", LastName = "Arnette"
                },
                new Person {
                    FirstName = "Belle", LastName = "Brook"
                },
            };

            // Configure DAL
            var personsQuery = persons.AsQueryable();

            _dal.Stub(x => x.GetList(Arg <Func <IQueryable <Person>, IQueryable <PersonDto> > > .Is.Anything))
            .Do((GetListTranformationDelegate <Person, PersonDto>)(transformBy => transformBy(personsQuery).ToList()));

            // Configure criteria
            var criteria = new PersonSearchCriteriaDto {
                Name = "xxx"
            };

            // Execute test
            var result = _manager.Search(criteria);

            // Verify results
            Assert.AreEqual(0, result.Count);
        }
コード例 #2
0
        public IHttpActionResult Search(PersonSearchCriteriaDto criteria)
        {
            // Simulated wait
            if (criteria != null)
            {
                System.Threading.Thread.Sleep(2000);
            }

            // Execute search
            var result = _personManager.Search(criteria);

            // Return results
            return(Ok(result));
        }
コード例 #3
0
ファイル: PersonManager.cs プロジェクト: m-paul/People-Search
        public List <PersonDto> Search(PersonSearchCriteriaDto criteria)
        {
            // Init criteria if not specified
            if (criteria == null)
            {
                criteria = new PersonSearchCriteriaDto();
            }

            // Clean up criteria name
            criteria.Name = criteria?.Name?.Trim() ?? "";
            if (criteria.Name.Length == 0)
            {
                criteria.Name = null;
            }

            // Execute search
            var result = _dal.GetList <Person, PersonDto>(t =>
                                                          from p in t
                                                          where (criteria.Name == null || (p.FirstName.Contains(criteria.Name) || p.LastName.Contains(criteria.Name)))
                                                          select new PersonDto
            {
                PersonId     = p.PersonId,
                ImageUrl     = p.ImageUrl,
                DateOfBirth  = p.DateOfBirth,
                FirstName    = p.FirstName,
                LastName     = p.LastName,
                AddressLine1 = p.AddressLine1,
                AddressLine2 = p.AddressLine2,
                City         = p.City,
                State        = p.State,
                ZipCode      = p.ZipCode,
                Interests    = p.Interests.Select(j => j.Interest).ToList()
            }
                                                          );

            // Return results
            return(result);
        }
コード例 #4
0
        public void NameSearchFound_Test()
        {
            // Generate persons
            var persons = new List <Person>
            {
                new Person {
                    FirstName = "Anne", LastName = "Arnette"
                },
                new Person {
                    FirstName = "Belle", LastName = "Brook"
                },
            };

            // Configure DAL
            var personsQuery = persons.AsQueryable();

            _dal.Stub(x => x.GetList(Arg <Func <IQueryable <Person>, IQueryable <PersonDto> > > .Is.Anything))
            .Do((GetListTranformationDelegate <Person, PersonDto>)(transformBy => transformBy(personsQuery).ToList()));

            // Configure criteria
            // Special Note: Linq to SQL will, by default, perform a case-insensitive search if the table is using
            //               default collation. Linq to Objects, on the otherhand, will not. Keep that in mind when testing.
            var criteria = new PersonSearchCriteriaDto {
                Name = " ll  "
            };

            // Execute test
            var result = _manager.Search(criteria);

            // Verify results
            Assert.AreEqual(1, result.Count);

            var match = result.First();

            Assert.AreEqual("Belle", match.FirstName);
            Assert.AreEqual("Brook", match.LastName);
        }