Example #1
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 DeletePersonInfo_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.DeletePersonInfo(fakeId);

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

            Assert.Equal(404, notFoundResult.StatusCode);
        }
Example #2
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);
        }
Example #3
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>()));
        }
Example #4
0
        public async Task DeletePersonInfo_return_PersonInfo_wrapped_OkObjectResault_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);

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

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

            Assert.IsAssignableFrom <PersonInfo>(okObjectResult.Value);
        }
Example #5
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"
                );
        }