public void AddNotas_WhenCalledWithWithInValidModel_ReturnsBadRequestObjectResult() { //Arrange _controller = new SectionController(_logger, _sectionInfoRepository); _controller.ModelState.AddModelError("error", "some error"); var section = new everisapi.API.Models.SectionWithNotasDto { EvaluacionId = 1, SectionId = 1, Notas = "Notas_1" }; var returnsSection = new everisapi.API.Entities.SectionEntity { Id = 1 }; mockRepository.Setup(r => r.GetSection(It.IsAny <int>(), It.IsAny <bool>())).Returns(returnsSection); mockRepository.Setup(r => r.AddNotasSection(It.IsAny <everisapi.API.Models.SectionWithNotasDto>())).Returns(true); //Act var okResult = _controller.AddNotas(section); //Assert Assert.IsType <BadRequestObjectResult>(okResult); }
public void AddNotas_WhenCalledThrowException_ReturnsStatusCodeResult() { //Arrange _controller = new SectionController(_logger, _sectionInfoRepository); var section = new everisapi.API.Models.SectionWithNotasDto { EvaluacionId = 1, SectionId = 1, Notas = "Notas_1" }; var returnsSection = new everisapi.API.Entities.SectionEntity { Id = 1 }; mockRepository.Setup(r => r.GetSection(It.IsAny <int>(), It.IsAny <bool>())).Returns(returnsSection); mockRepository.Setup(r => r.AddNotasSection(It.IsAny <everisapi.API.Models.SectionWithNotasDto>())).Throws(new Exception()); //Act var okResult = _controller.AddNotas(section); //Assert Assert.IsType <ObjectResult>(okResult); }
public void AddNotas_WhenCalledWithNull__ReturnsBadRequestResult() { //Arrange _controller = new SectionController(_logger, _sectionInfoRepository); everisapi.API.Models.SectionWithNotasDto section = null; var returnsSection = new everisapi.API.Entities.SectionEntity { Id = 1 }; mockRepository.Setup(r => r.GetSection(It.IsAny <int>(), It.IsAny <bool>())).Returns(returnsSection); mockRepository.Setup(r => r.AddNotasSection(It.IsAny <everisapi.API.Models.SectionWithNotasDto>())).Returns(true); //Act var okResult = _controller.AddNotas(section); //Assert Assert.IsType <BadRequestResult>(okResult); }