示例#1
0
        public async Task PutPersonInfo_BadRequestResult_400_When_Id_not_equal_PersonInfo_Id()
        {
            //Arrange
            var testPersonInfo = GetTestPersonInfoAsync().Result;
            var otherId        = 0;
            var _contextMock   = new Mock <PeopleDWContext>();

            //Act
            var personInfoesController = new PersonInfoesController(_contextMock.Object);
            var actionResult           = await personInfoesController
                                         .PutPersonInfo(otherId, testPersonInfo);

            //Assert
            var badRequestResult = Assert.IsType <BadRequestResult>(actionResult);

            Assert.Equal(400, badRequestResult.StatusCode);
        }
示例#2
0
        //The Method checks the returned result is NotFoundReult 404, when PersonInfo is not found
        //The Method under test calls FindAsync(fake id) gets null and returns NotFoundResult
        public async Task GetPersonInfo_NotFoundResult_404_When_PersonInfo_not_found()
        {
            //Arrange
            var fakeId       = 88;
            var _contextMock = new Mock <PeopleDWContext>();

            _contextMock
            .Setup(context => context.PersonInfo.FindAsync(It.IsAny <long>()))
            .Returns(Task.FromResult((PersonInfo)null));

            //Act
            var personInfoesController = new PersonInfoesController(_contextMock.Object);
            var actionResult           = await personInfoesController.GetPersonInfo(fakeId);

            //Assert
            var notFoundResult = Assert.IsType <NotFoundResult>(actionResult);

            Assert.Equal(404, notFoundResult.StatusCode);
        }
示例#3
0
        public async Task DeletePersonInfo_BadRequestObjectResult_400_When_ModelState_not_valid()
        {
            //Arrange
            //var testPersonInfo = GetTestPersonInfoAsync().Result;
            var trueId       = 1;
            var _contextMock = new Mock <PeopleDWContext>();

            //Act
            var personInfoesController = new PersonInfoesController(_contextMock.Object);

            personInfoesController.ModelState.AddModelError("Key", "Test_Error");
            var actionResult = await personInfoesController
                               .DeletePersonInfo(trueId);

            //Assert
            var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(actionResult);

            Assert.Equal(400, badRequestObjectResult.StatusCode);
        }
示例#4
0
        //The Method checks the returned result on success. it should be OkObjectResault
        //The Method checks the returned object wrapped in the result. it should be PersonInfo
        //The Method under test calls FindAsync(long) and returns PersonInfo wrapped in the ActionResult
        public async Task GetPersonInfo_return_PersonInfo_wrapped_OkObjectResault_When_Success()
        {
            //Arrange
            var trueId         = 1;
            var testPersonInfo = GetTestPersonInfoAsync();
            var _contextMock   = new Mock <PeopleDWContext>();

            _contextMock
            .Setup(context => context.PersonInfo.FindAsync(It.IsAny <long>()))
            .Returns(testPersonInfo);

            //Act
            var personInfoesController = new PersonInfoesController(_contextMock.Object);
            var actionResult           = await personInfoesController.GetPersonInfo(trueId);

            //Assert
            var okObjectResult = Assert.IsType <OkObjectResult>(actionResult);

            Assert.IsAssignableFrom <PersonInfo>(okObjectResult.Value);
        }
示例#5
0
        public async Task DeletePersonInfo_Call_SaveChangesAsync_When_Success()
        {
            //Arrange
            var testPersonInfo = GetTestPersonInfoAsync();
            var trueId         = testPersonInfo.Result.IdPeople;
            var _contextMock   = new Mock <PeopleDWContext>();

            _contextMock
            .Setup(context => context.SaveChangesAsync(It.IsAny <CancellationToken>()));
            _contextMock
            .Setup(context => context.PersonInfo.FindAsync(It.IsAny <long>()))
            .Returns(testPersonInfo);

            //Act
            var personInfoesController = new PersonInfoesController(_contextMock.Object);
            await personInfoesController.DeletePersonInfo(trueId);

            //Assert
            _contextMock.Verify(c => c.SaveChangesAsync(It.IsAny <CancellationToken>()));
        }
示例#6
0
        //The Method checks the returned result is BadRequestObjectResult 400, when ControllerBase.ModelState has an error
        public async Task GetPersonInfo_BadRequestObjectResult_400_When_ModelState_not_valid()
        {
            //Arrange
            var anyId        = 1;
            var _contextMock = new Mock <PeopleDWContext>();
            //_contextMock
            //	.Setup(context => context.PersonInfo.FindAsync(It.IsAny<long>()))
            //	.Returns(GetTestPersonInfoAsync());

            //Act
            var personInfoesController = new PersonInfoesController(_contextMock.Object);

            personInfoesController.ModelState.AddModelError("Key", "Test_Error");
            var actionResult = await personInfoesController.GetPersonInfo(anyId);

            //Assert
            var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(actionResult);

            Assert.Equal(400, badRequestObjectResult.StatusCode);
        }
示例#7
0
        //The Method checks the found id must be equal to the id of the returned object
        //The Method under test calls FindAsync(long) and returns PersonInfo wrapped in the ActionResult
        public async Task GetPersonInfo_returned_Id_people_equals_Id_people_found_When_Success()
        {
            //Arrange
            var trueId         = 1;
            var testPersonInfo = GetTestPersonInfoAsync();
            var _contextMock   = new Mock <PeopleDWContext>();

            _contextMock
            .Setup(context => context.PersonInfo.FindAsync(It.IsAny <long>()))
            .Returns(testPersonInfo);

            //Act
            var personInfoesController = new PersonInfoesController(_contextMock.Object);
            var returnPersonInfo       =
                (PersonInfo)
                ((OkObjectResult)await personInfoesController.GetPersonInfo(trueId))
                .Value;

            //Assert
            Assert.True(testPersonInfo.Result.IdPeople.Equals(returnPersonInfo.IdPeople));
        }
示例#8
0
        public async Task DeletePersonInfo_Removed_Id_people_equals_Id_people_found_When_Success()
        {
            //Arrange
            var testPersonInfo = GetTestPersonInfoAsync();
            var trueId         = testPersonInfo.Result.IdPeople;
            var _contextMock   = new Mock <PeopleDWContext>();

            _contextMock
            .Setup(context => context.PersonInfo.FindAsync(It.IsAny <long>()))
            .Returns(testPersonInfo);
            _contextMock
            .Setup(context => context.PersonInfo.Remove(It.IsAny <PersonInfo>()));

            //Act
            var personInfoesController = new PersonInfoesController(_contextMock.Object);
            await personInfoesController.DeletePersonInfo(trueId);

            _contextMock.Verify(
                c => c.PersonInfo.Remove(It.Is <PersonInfo>(el => el.IdPeople == trueId)),
                "The object being removed is different from the object found by identifier"
                );
        }