예제 #1
0
        public PersonDto Get(int id)
        {
            var person = _peopleRepo.Get(id);

            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);

            //Todo - use a mapper
            return(new PersonDto()
            {
                Id = person.Id,
                Gender = person.Gender,
                Father = new PersonDto
                {
                    Name = father?.Name
                },
                Mother = new PersonDto
                {
                    Name = mother?.Name
                },
                Name = person.Name,
                Place = new PlaceDto
                {
                    Name = place?.Name
                },
                Level = person.Level
            });
        }
예제 #2
0
        public void GetPerson_IncorrectInput_ReturnsNull()
        {
            //Arrange
            _peopleStore.Data.Returns(new EditableList <Person>
            {
                new Person
                {
                    Id = 2
                }
            });

            //Act
            var result = _peopleRepo.Get(1);

            //Assert
            Assert.True(result == null);
        }
예제 #3
0
 public async Task <ActionResult <ICollection <Person> > > GetTasks()
 {
     return(Ok(await _repository.Get()));
 }
예제 #4
0
        public void GetPerson_ValidId_ReturnsCorrectObject()
        {
            //Arrange
            var expectedResult = new PersonDto
            {
                Name   = "Harry Potter",
                Id     = 3,
                Father = new PersonDto()
                {
                    Name = "James Potter",
                    Id   = 1
                },
                Mother = new PersonDto()
                {
                    Name = "Lily Potter",
                    Id   = 2
                },
                Place = new PlaceDto()
                {
                    Name = "Hogwarths",
                    Id   = 1
                }
            };

            _peopleRepo.Get(Arg.Is <int>(id => id == 1)).Returns(new Person
            {
                Name = "James Potter",
                Id   = 1
            });

            _peopleRepo.Get(Arg.Is <int>(id => id == 2)).Returns(new Person
            {
                Name = "Lily Potter",
                Id   = 2
            });

            _peopleRepo.Get(Arg.Is <int>(id => id == 3)).Returns(new Person
            {
                Name     = "Harry Potter",
                Id       = 3,
                FatherId = 1,
                MotherId = 2,
                PlaceId  = 1
            });

            _placeRepo.Get(Arg.Is <int>(id => id == 1)).Returns(new Place
            {
                Name = "Hogwarths",
                Id   = 1
            });

            //Act

            var result = _peopleService.Get(expectedResult.Id);

            //Assert

            Assert.True(result?.Name == expectedResult.Name);
            Assert.True(result?.Id == expectedResult.Id);

            Assert.True(result?.Father?.Name == expectedResult.Father.Name);
            Assert.True(result?.Mother?.Name == expectedResult.Mother.Name);
        }