Example #1
0
        public async Task GetPerson_Success()
        {
            //Arrange
            var fakePersonId  = 1L;
            var fakePerson    = GetPersonFake(fakePersonId);
            var fakePersonDto = GetPersonResponseDtoFake(fakePerson);

            _personRepositoryMock.Setup(x => x.GetPersonAsync(It.IsAny <long>()))
            .Returns(Task.FromResult(fakePerson));

            //Act
            var personsController = new PersonsController(_loggerMock.Object, _personRepositoryMock.Object);
            var actionResult      = await personsController.GetPersonAsync(fakePersonId);

            //Assert
            var result      = actionResult.Result as OkObjectResult;
            var resultValue = (PersonResponseDTO)result.Value;

            Assert.Equal(result.StatusCode, (int)HttpStatusCode.OK);
            Assert.Equal(resultValue.Id, fakePersonDto.Id);
            Assert.Equal(resultValue.Name, fakePersonDto.Name);
            Assert.Equal(resultValue.DisplayName, fakePersonDto.DisplayName);

            for (int i = 0; i < fakePersonDto.Skills.Count; i++)
            {
                Assert.Equal(fakePersonDto.Skills[i].Name, resultValue.Skills[i].Name);
                Assert.Equal(fakePersonDto.Skills[i].Level, resultValue.Skills[i].Level);
            }
        }
Example #2
0
        public async Task GetPerson_When_User_Is_Not_Found_Will_Return_Not_Found()
        {
            //Arrange
            var fakePersonId = 0;

            _personRepositoryMock.Setup(e => e.GetPersonAsync(fakePersonId))
            .Returns(Task.FromResult <Person>(null));

            //Act
            var personsController = new PersonsController(_loggerMock.Object, _personRepositoryMock.Object);
            var actionResult      = await personsController.GetPersonAsync(fakePersonId);

            //Assert
            Assert.IsType <NotFoundObjectResult>(actionResult.Result);
        }