private CompraController CreateCompraController() { _mockCompraRepository.Setup(x => x.Criar(new Compra())); _mockPessoaRepository.Setup(x => x.ObterPorCodigo(1)).Returns(new Pessoa()); _mockFormaPagamentoRepository.Setup(x => x.ObterPorCodigo(1)).Returns(new FormaPagamento()); _mockCondicaoPagamentoRepository.Setup(x => x.ObterPorCodigo(1)).Returns(new CondicaoPagamento()); var compraService = new CompraService(_mockCompraRepository.Object, _mockItemCompraRepository.Object, _mockPessoaRepository.Object, _mockFormaPagamentoRepository.Object, _mockCondicaoPagamentoRepository.Object, _usuarioRepository.Object, _contaPagarRepository.Object, _estoqueRepository.Object, _produtoRepository.Object); var controller = new CompraController(compraService) { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; return controller; }
public void TesteCriarCompraMockCompraService() { var mockService = new Mock<ICompraService>(); mockService.Setup(x => x.CriarCompra(new Compra())); var controller = new CompraController(mockService.Object) { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; var response = controller.CriarCompra(new CompraModel() { StatusCompra = "Aberto" }); var data = response.Result.Content.ReadAsAsync<RetornoBase<object>>(); Assert.AreEqual(HttpStatusCode.OK, response.Result.StatusCode); Assert.AreEqual(null, data.Result.ObjetoRetorno); Assert.AreEqual(false, data.Result.TemErros); Assert.AreEqual(Mensagens.ReturnSuccess, data.Result.Mensagem); }