public void QuandoOcorrerErroAoAtualizarUmaListaDeIvaDeveRetornarStatusDeErro() { var cadastroIvaMock = new Mock <ICadastroIva>(MockBehavior.Strict); cadastroIvaMock.Setup(x => x.AtualizarIvas(It.IsAny <IList <IvaCadastroVm> >())) .Throws(new Exception("Ocorreu um erro ao atualizar os Ivas")); var ivaApiController = new IvaApiController(cadastroIvaMock.Object); var ivaCadastroVm = new IvaCadastroVm() { Codigo = "FORNEC0001", Descricao = "FORNECEDOR 0001" }; ivaApiController.Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/IvaApi/PostMultiplo"); ivaApiController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); var resposta = ivaApiController.PostMultiplo(new ListaIva() { ivaCadastroVm }); var apiResponseMessage = (ApiResponseMessage)((ObjectContent)(resposta.Content)).Value; Assert.AreEqual(HttpStatusCode.OK, resposta.StatusCode); Assert.AreEqual("500", apiResponseMessage.Retorno.Codigo); cadastroIvaMock.Verify(x => x.AtualizarIvas(It.IsAny <IList <IvaCadastroVm> >()), Times.Once()); }
public void QuandoAtualizarUmaListaDeIvasComSucessoDeveRetornarStatusOk() { var cadastroIvaMock = new Mock <ICadastroIva>(MockBehavior.Strict); cadastroIvaMock.Setup(x => x.AtualizarIvas(It.IsAny <IList <IvaCadastroVm> >())); var ivaApiController = new IvaApiController(cadastroIvaMock.Object); var ivaCadastroVm = new IvaCadastroVm() { Codigo = "01", Descricao = "IVA 01" }; ivaApiController.Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/IvaApi/PostMultiplo"); ivaApiController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); var resposta = ivaApiController.PostMultiplo(new ListaIva() { ivaCadastroVm }); Assert.AreEqual(HttpStatusCode.OK, resposta.StatusCode); cadastroIvaMock.Verify(x => x.AtualizarIvas(It.IsAny <IList <IvaCadastroVm> >()), Times.Once()); }