public void Deve_Salvar_Um_Chamado() { var mockAplicacao = new Mock<IAplicacao<Dominio.Chamada.Chamada>>(); mockAplicacao.Setup(x => x.Salvar(It.IsAny<Dominio.Chamada.Chamada>())) .Returns(new Dominio.Chamada.Chamada {Codigo = 34}); var controller = new ChamadaController(mockAplicacao.Object); var result = controller.Salvar(new Dominio.Chamada.Chamada()); Assert.AreEqual(34, ((Dominio.Chamada.Chamada) result.Data).Codigo); }
public void Deve_Tratar_Exception_Ao_Salvar_Uma_Chamada() { var mockAplicacao = new Mock<IAplicacao<Dominio.Chamada.Chamada>>(); mockAplicacao.Setup(x => x.Salvar(It.IsAny<Dominio.Chamada.Chamada>())) .Throws(new Exception("erro interno do servidor")); var controller = new ChamadaController(mockAplicacao.Object); var result = controller.Salvar(new Dominio.Chamada.Chamada()); Assert.AreEqual("erro interno do servidor", result.Data.GetType().GetProperty("erro").GetValue(result.Data)); }
public void Deve_Retornar_Todas_As_Chamadas() { var chamadas = Builder<Dominio.Chamada.Chamada>.CreateListOfSize(2).Build(); var mockAplicacao = new Mock<IAplicacao<Dominio.Chamada.Chamada>>(); mockAplicacao.Setup(x => x.RetornarTodos()) .Returns(chamadas); var controller = new ChamadaController(mockAplicacao.Object); var result = controller.RetornarChamadas(); Assert.AreEqual(2, ((List<Dominio.Chamada.Chamada>) result.Data).Count); }