示例#1
0
        public void SearchPerson_ValidParameters_ReturnsCorrectResults(PeopleServiceSearchTestData testData)
        {
            //Arrange
            var expectedResult = testData.ExpectedResult;

            foreach (var person in testData.EnforcedParentResults)
            {
                _peopleRepo.Get(Arg.Is <int>(id => id == person.Id)).Returns(person);
            }

            _peopleRepo.Search(Arg.Is <PersonSearchCriteria>(c => c.Name == testData.SearchCriteria.Name))
            .Returns(testData.EnforcedResult);

            //Act
            var actualResult = _peopleService.Search(testData.SearchCriteria.Name, testData.SearchCriteria.Gender, 0, 10);

            //Assert
            Assert.True(expectedResult.Count == actualResult.TotalCount);

            for (int i = 0; i < expectedResult.Count; i++)
            {
                Assert.True(expectedResult.Results[i].Name == actualResult?.Results[i]?.Name);
                Assert.True(expectedResult.Results[i].Father.Name == actualResult?.Results[i]?.Father?.Name);
                Assert.True(expectedResult.Results[i].Mother.Name == actualResult?.Results[i]?.Mother?.Name);
            }
        }
示例#2
0
        public void SearchPerson_IncorrectName_returnsNull()
        {
            //Arrange
            SearchResult <Person> expectedResult = null;

            _peopleStore.Data.Returns(new EditableList <Person>
            {
                new Person
                {
                    Name = "Test Person Name"
                }
            });

            //Act
            var result = _peopleRepo.Search(new PersonSearchCriteria
            {
                Name = "Test Name"
            });

            //Assert
            Assert.True(result == expectedResult);
        }
示例#3
0
        public SearchResultDto <PersonDto> Search(string name, string gender, int index, int count)
        {
            //todo - Use a mapper
            var result = _peopleRepo.Search(new PersonSearchCriteria
            {
                Name   = name,
                Gender = gender,
                Index  = index,
                Count  = count
            });

            return(new SearchResultDto <PersonDto>
            {
                Results = result.Results.Select(person =>
                {
                    var mother = person.MotherId != null
                        ? _peopleRepo.Get(person.MotherId.Value)
                        : null;

                    var father = person.FatherId != null
                        ?_peopleRepo.Get(person.FatherId.Value)
                        :null;

                    var place = _placeRepo.Get(person.PlaceId);

                    return new PersonDto
                    {
                        Name = person.Name,
                        Id = person.Id,
                        Gender = person.Gender,
                        Level = person.Level,
                        Place = new PlaceDto
                        {
                            Name = place?.Name
                        },
                        Father = new PersonDto
                        {
                            Name = father?.Name
                        },
                        Mother = new PersonDto
                        {
                            Name = mother?.Name
                        }
                    };
                }).ToList(),
                TotalCount = result.Count
            });
        }