{"action":"created","issue":{"url":"https://api.github.com/repos/moq/moq4/issues/105","repository_url":"https://api.github.com/repos/moq/moq4","labels_url":"https://api.github.com/repos/moq/moq4/issues/105/labels{/name}","comments_url":"https://api.github.com/repos/moq/moq4/issues/105/comments","events_url":"https://api.github.com/repos/moq/moq4/issues/105/events","html_url":"https://github.com/moq/moq4/issues/105","id":31174787,"number":105,"title":"How can I mock a function with ref parameter?","user":{"login":"danicomas","id":4038192,"avatar_url":"https://avatars1.githubusercontent.com/u/4038192?v=4","gravatar_id":"","url":"https://api.github.com/users/danicomas","html_url":"https://github.com/danicomas","followers_url":"https://api.github.com/users/danicomas/followers","following_url":"https://api.github.com/users/danicomas/following{/other_user}","gists_url":"https://api.github.com/users/danicomas/gists{/gist_id}","starred_url":"https://api.github.com/users/danicomas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danicomas/subscriptions","organizations_url":"https://api.github.com/users/danicomas/orgs","repos_url":"https://api.github.com/users/danicomas/repos","events_url":"https://api.github.com/users/danicomas/events{/privacy}","received_events_url":"https://api.github.com/users/danicomas/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/moq/moq4/milestones/4","html_url":"https://github.com/moq/moq4/milestone/4","labels_url":"https://api.github.com/repos/moq/moq4/milestones/4/labels","id":2802608,"number":4,"title":"v4.8.0","description":"","creator":{"login":"stakx","id":104481,"avatar_url":"https://avatars1.githubusercontent.com/u/104481?v=4","gravatar_id":"","url":"https://api.github.com/users/stakx","html_url":"https://github.com/stakx","followers_url":"https://api.github.com/users/stakx/followers","following_url":"https://api.github.com/users/stakx/following{/other_user}","gists_url":"https://api.github.com/users/stakx/gists{/gist_id}","starred_url":"https://api.github.com/users/stakx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stakx/subscriptions","organizations_url":"https://api.github.com/users/stakx/orgs","repos_url":"https://api.github.com/users/stakx/repos","events_url":"https://api.github.com/users/stakx/events{/privacy}","received_events_url":"https://api.github.com/users/stakx/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":1,"state":"open","created_at":"2017-09-29T11:24:45Z","updated_at":"2017-10-02T20:03:11Z","due_on":null,"closed_at":null},"comments":20,"created_at":"2014-04-09T16:55:21Z","updated_at":"2017-10-03T20:32:43Z","closed_at":null,"author_association":"NONE","body":"I have this simple code, but I can't do it work\n\n```\n[TestMethod]\n        public void TestMoq()\n        {\n            var mock = new Moq.Mock<Hola>();            \n\n            string o = \"1\";\n            mock.Setup(x => x.DoSomething(ref o)).Callback((string a) => o = \"2\");\n\n            mock.Object.DoSomething(ref o);\n\n        }\n```\n\n```\npublic class Hola\n    {\n        public Hola()\n        {\n\n        }\n\n        public virtual void DoSomething(ref string a)\n        {\n\n        }\n    }\n```\n\nThe error is this:\n![capturemoqbug](https://cloud.githubusercontent.com/assets/4038192/2658444/9575b96a-c008-11e3-92f9-04d589026f6f.PNG)\n\nI prefer to use the Moq library. But only I get it on the Rhino Mocks library, with the function **OutRef**:\n\n```\n[TestMethod]\n        public void TestRhinoMocks()\n        {\n            MockRepository mocker = new MockRepository();\n\n            Hola mock = mocker.StrictMock<Hola>();\n\n            string o = \"1\";\n\n            Expect.Call(() => mock.DoSomething(ref o)).OutRef(\"2\");\n\n            mocker.ReplayAll();\n\n            //i.Setup(x => x.DoSomething(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Callback((string a, string b, string c) => o = \"2\");\n\n            mock.DoSomething(ref o);\n        }\n```\n\nThanks in advance!\n"},"comment":{"url":"https://api.github.com/repos/moq/moq4/issues/comments/333969384","html_url":"https://github.com/moq/moq4/issues/105#issuecomment-333969384","issue_url":"https://api.github.com/repos/moq/moq4/issues/105","id":333969384,"user":{"login":"ohadschn","id":8555641,"avatar_url":"https://avatars1.githubusercontent.com/u/8555641?v=4","gravatar_id":"","url":"https://api.github.com/users/ohadschn","html_url":"https://github.com/ohadschn","followers_url":"https://api.github.com/users/ohadschn/followers","following_url":"https://api.github.com/users/ohadschn/following{/other_user}","gists_url":"https://api.github.com/users/ohadschn/gists{/gist_id}","starred_url":"https://api.github.com/users/ohadschn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ohadschn/subscriptions","organizations_url":"https://api.github.com/users/ohadschn/orgs","repos_url":"https://api.github.com/users/ohadschn/repos","events_url":"https://api.github.com/users/ohadschn/events{/privacy}","received_events_url":"https://api.github.com/users/ohadschn/received_events","type":"User","site_admin":false},"created_at":"2017-10-03T20:32:43Z","updated_at":"2017-10-03T20:32:43Z","author_association":"NONE","body":"Since this is essentially a new method, how about keeping the generics and simply changing the method name (e.g. `CallbackDelegate`/`ReturnsDelegate`)? \r\n\r\nAs for the constraint, IMO this would be good enough: https://stackoverflow.com/a/191949/67824 (basically have a `class` constraint and verify it's a delegate in reflection, no big deal here since reflection is used for validation anyway)."}}
{"actor":{"display_login":"ohadschn"}}