{"action":"created","issue":{"url":"https://api.github.com/repos/nsubstitute/NSubstitute/issues/156","repository_url":"https://api.github.com/repos/nsubstitute/NSubstitute","labels_url":"https://api.github.com/repos/nsubstitute/NSubstitute/issues/156/labels{/name}","comments_url":"https://api.github.com/repos/nsubstitute/NSubstitute/issues/156/comments","events_url":"https://api.github.com/repos/nsubstitute/NSubstitute/issues/156/events","html_url":"https://github.com/nsubstitute/NSubstitute/pull/156","id":37938678,"number":156,"title":"Spike for #150 (Allow direct use of SubstituteFactory)","user":{"login":"alexandrnikitin","id":1798438,"avatar_url":"https://avatars.githubusercontent.com/u/1798438?v=3","gravatar_id":"","url":"https://api.github.com/users/alexandrnikitin","html_url":"https://github.com/alexandrnikitin","followers_url":"https://api.github.com/users/alexandrnikitin/followers","following_url":"https://api.github.com/users/alexandrnikitin/following{/other_user}","gists_url":"https://api.github.com/users/alexandrnikitin/gists{/gist_id}","starred_url":"https://api.github.com/users/alexandrnikitin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexandrnikitin/subscriptions","organizations_url":"https://api.github.com/users/alexandrnikitin/orgs","repos_url":"https://api.github.com/users/alexandrnikitin/repos","events_url":"https://api.github.com/users/alexandrnikitin/events{/privacy}","received_events_url":"https://api.github.com/users/alexandrnikitin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":14,"created_at":"2014-07-16T00:16:11Z","updated_at":"2016-10-26T22:40:51Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/nsubstitute/NSubstitute/pulls/156","html_url":"https://github.com/nsubstitute/NSubstitute/pull/156","diff_url":"https://github.com/nsubstitute/NSubstitute/pull/156.diff","patch_url":"https://github.com/nsubstitute/NSubstitute/pull/156.patch"},"body":"Hi everyone!\r\n\r\nThis is a quick spike for #150 (Allow direct use of SubstituteFactory).\r\n\r\nI added:\r\n- \"AllSubstitutesWide\" API wich looks like ```Substitute.Configure(params Func<ICall, RouteAction>[] customCallHandlers)```. Also can be \"oneSubstituteWide\" too.\r\n- ```Func<ICall, RouteAction>[] CustomCallHandlers``` to ```ISubstitutionContext``` which stores all custom handlers.\r\n- ```CustomCallHandlers``` as a new ```ICallHandler``` which handles calls and return values if needed.\r\n\r\nI don't like that ```RouteAction``` is exposed outside but it can be repaced with ```object```.\r\n\r\nUsage:\r\n```csharp\r\nSubstitute.Configure(call => call.GetReturnType() == typeof(int) ? RouteAction.Return(5) : RouteAction.Continue());\r\nvar sub = Substitute.For<IInterface>();\r\nAssert.AreEqual(5, sub.ReturnsInt());\r\n\r\npublic interface IInterface\r\n{\r\n    int ReturnsInt();\r\n}\r\n```\r\n\r\nLooking forward to your feedback."},"comment":{"url":"https://api.github.com/repos/nsubstitute/NSubstitute/issues/comments/256498416","html_url":"https://github.com/nsubstitute/NSubstitute/pull/156#issuecomment-256498416","issue_url":"https://api.github.com/repos/nsubstitute/NSubstitute/issues/156","id":256498416,"user":{"login":"dtchepak","id":70105,"avatar_url":"https://avatars.githubusercontent.com/u/70105?v=3","gravatar_id":"","url":"https://api.github.com/users/dtchepak","html_url":"https://github.com/dtchepak","followers_url":"https://api.github.com/users/dtchepak/followers","following_url":"https://api.github.com/users/dtchepak/following{/other_user}","gists_url":"https://api.github.com/users/dtchepak/gists{/gist_id}","starred_url":"https://api.github.com/users/dtchepak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dtchepak/subscriptions","organizations_url":"https://api.github.com/users/dtchepak/orgs","repos_url":"https://api.github.com/users/dtchepak/repos","events_url":"https://api.github.com/users/dtchepak/events{/privacy}","received_events_url":"https://api.github.com/users/dtchepak/received_events","type":"User","site_admin":false},"created_at":"2016-10-26T22:40:51Z","updated_at":"2016-10-26T22:40:51Z","body":"@Zvirja: thanks so much for this. I really appreciate the effort.\r\n\r\n> No way to refactor `ReturnForAll` to use this feature without introducing breaking changes. That is because currently it's placed [one router before](https://github.com/nsubstitute/NSubstitute/blob/master/Source/NSubstitute/Routing/RouteFactory.cs#L76) `AutoValues`. \r\n\r\nI this this is the location where the custom handler should go (if we go with that approach). Alexandr's original work had it [here](https://github.com/alexandrnikitin/NSubstitute/blob/bb4041dfd71c0b18eb7f1fa85b7709304db81a33/Source/NSubstitute/Routing/RouteFactory.cs#L76).\r\n\r\nI'm still leaning towards the simplest approach until we have clear use cases for the more advanced routing changes. That said I don't mind option 2, especially with your suggested simplifications of only supporting edits for record/replay for now. I don't understand the implications of option 3 -- I'm a bit reluctant to take on the higher complexity without clear use cases demonstrating where this would help (even though the basic idea sounds pretty awesome :) ).\r\n\r\nSo my vote is for option 1, but happy to be guided by you and @alexandrnikitin as to what is best in this case.\r\n"}}
{"actor":{"display_login":"dtchepak"}}