public void GetPorIdOk() { var logicMock = new Mock <IUsuario>(MockBehavior.Strict); UsuariosController controller = new UsuariosController(logicMock.Object); DatosUsuario datos = new DatosUsuario() { Apellido = "Asd", Mail = "[email protected]", Nombre = "Juan", }; Usuario usuario = new Usuario() { IsAdmin = false, Datos = datos, Id = 0, Token = "Recien Creado", Contrasenia = "ContraseƱa", }; logicMock.Setup(x => x.ObtenerPorId(usuario.Id)).Returns(usuario); var result = controller.GetPorId(usuario.Id); var okResult = result as OkObjectResult; logicMock.VerifyAll(); }
public void GetPorIdNoExiste() { var logicMock = new Mock <IUsuario>(MockBehavior.Strict); UsuariosController controller = new UsuariosController(logicMock.Object); logicMock.Setup(x => x.ObtenerPorId(It.IsAny <int>())).Throws(new EntidadNoExisteExcepcion()); var result = controller.GetPorId(It.IsAny <int>()); var okResult = result as NotFoundObjectResult; logicMock.VerifyAll(); }