//[Authorize(Policy = "CanWritePermissao")] public IActionResult TipoPermissaoAdd(TipoPermissaoViewModel model) { if (!ModelState.IsValid) { NotificarErroModelInvalida(); return(Response(model)); } _tipoPermissaoService.Adicionar(_mapper.Map <TipoPermissaoModel>(model)); return(Response()); }
public void TipoPermissao_Add_RetornarComSucesso() { // Arrange var tipoPermissaoViewModel = new TipoPermissaoViewModel(); var tipoPermissaoModel = new TipoPermissaoModel("Teste"); mockMapper.Setup(m => m.Map <TipoPermissaoModel>(tipoPermissaoViewModel)).Returns(tipoPermissaoModel); mockNotification.Setup(m => m.GetNotifications()).Returns(new List <DomainNotification>()); // Act var result = permissaoController.TipoPermissaoAdd(tipoPermissaoViewModel); // Assert mockTipoPermissaoService.Verify(m => m.Adicionar(tipoPermissaoModel), Times.Once); Assert.IsType <OkObjectResult>(result); }
public void TipoPermissaoAdd_RetornarComErrosDeDominio() { var tipoPermissaoViewModel = new TipoPermissaoViewModel(); var tipoPermissaoModel = new TipoPermissaoModel("Teste"); mockMapper.Setup(m => m.Map <TipoPermissaoModel>(tipoPermissaoViewModel)).Returns(tipoPermissaoModel); var notficationList = new List <DomainNotification> { new DomainNotification("Erro", "Erro ao adicionar novo Tipo de Permissao") }; mockNotification.Setup(m => m.GetNotifications()).Returns(notficationList); mockNotification.Setup(m => m.HasNotifications()).Returns(true); // Act var result = permissaoController.TipoPermissaoAdd(tipoPermissaoViewModel); // Assert mockTipoPermissaoService.Verify(m => m.Adicionar(tipoPermissaoModel), Times.Once); Assert.IsType <BadRequestObjectResult>(result); }