{"action":"created","issue":{"url":"https://api.github.com/repos/xbehave/xbehave.net/issues/283","labels_url":"https://api.github.com/repos/xbehave/xbehave.net/issues/283/labels{/name}","comments_url":"https://api.github.com/repos/xbehave/xbehave.net/issues/283/comments","events_url":"https://api.github.com/repos/xbehave/xbehave.net/issues/283/events","html_url":"https://github.com/xbehave/xbehave.net/issues/283","id":116919309,"number":283,"title":".NET 4.6 lambda returns hang tests when you assign a Task","user":{"login":"chrisalexander","id":50909,"avatar_url":"https://avatars.githubusercontent.com/u/50909?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisalexander","html_url":"https://github.com/chrisalexander","followers_url":"https://api.github.com/users/chrisalexander/followers","following_url":"https://api.github.com/users/chrisalexander/following{/other_user}","gists_url":"https://api.github.com/users/chrisalexander/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisalexander/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisalexander/subscriptions","organizations_url":"https://api.github.com/users/chrisalexander/orgs","repos_url":"https://api.github.com/users/chrisalexander/repos","events_url":"https://api.github.com/users/chrisalexander/events{/privacy}","received_events_url":"https://api.github.com/users/chrisalexander/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/xbehave/xbehave.net/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-14T11:13:58Z","updated_at":"2015-11-19T12:19:17Z","closed_at":null,"body":"Hello everyone\r\n\r\nI just wrote a few basic xBehave tests under .NET 4.6 for the first time and noted that my tests were behaving unexpectedly. I am using the Visual Studio runner and I observed that the tests were all running to completion, but the test run was not actually completing. In the Test Explorer I had a \"cancel\" button and code coverage was not run, etc.\r\n\r\nI think I have narrowed this down to the following case. Obviously you would never write a test like this in real life but it behaves in the same way that the one I was writing did. I have put the whole thing in a Gist as it is a bit long: https://gist.github.com/chrisalexander/d4c4f93df05e9c0fd264\r\n\r\nThere is a change in .NET 4.6 where arrow lambdas return the result of the expression ([see here](http://www.kunal-chowdhury.com/2014/12/csharp-6-expression-bodied-method.html))\r\n\r\nWhen you write a test statement that looks like this:\r\n\r\n    \"And given a task from that completion source\"\r\n        ._(() => task = tcs.Task);\r\n\r\n(where `tcs` is a `TaskCompletionSource<T>` and  the purpose of the \"given\" is to assign a task in the method arguments) then you get the correct assignment, but the new language feature means it calls xBehave's `_(Action<Task> body)` method rather than `_(Action body)`, which results in xBehave waiting for the task to complete rather than actually continuing which is what we would expect.\r\n\r\nThe current workaround I have is to rephrase the test statement thus:\r\n\r\n    \"And given a task from that completion source\"\r\n        ._(() =>\r\n        {\r\n            task = tcs.Task;\r\n        });\r\n\r\nThis triggers the correct behaviour.\r\n\r\nIt should be said this isn't really the fault of xBehave, and I'm not even sure there is anything you can really do about it, but I thought it might be worth mentioning as it may confuse some people and it may  raise some questions for you, so I thought it would be worth mentioning. Given part of the point of the library is to help write tests that read nicely, this may cause a stumbling block for some people (especially when I think this test would have worked without hanging in 4.5)."},"comment":{"url":"https://api.github.com/repos/xbehave/xbehave.net/issues/comments/158042286","html_url":"https://github.com/xbehave/xbehave.net/issues/283#issuecomment-158042286","issue_url":"https://api.github.com/repos/xbehave/xbehave.net/issues/283","id":158042286,"user":{"login":"adamralph","id":677704,"avatar_url":"https://avatars.githubusercontent.com/u/677704?v=3","gravatar_id":"","url":"https://api.github.com/users/adamralph","html_url":"https://github.com/adamralph","followers_url":"https://api.github.com/users/adamralph/followers","following_url":"https://api.github.com/users/adamralph/following{/other_user}","gists_url":"https://api.github.com/users/adamralph/gists{/gist_id}","starred_url":"https://api.github.com/users/adamralph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamralph/subscriptions","organizations_url":"https://api.github.com/users/adamralph/orgs","repos_url":"https://api.github.com/users/adamralph/repos","events_url":"https://api.github.com/users/adamralph/events{/privacy}","received_events_url":"https://api.github.com/users/adamralph/received_events","type":"User","site_admin":false},"created_at":"2015-11-19T12:19:17Z","updated_at":"2015-11-19T12:19:17Z","body":"@chrisalexander thanks for raising this! I'm rather swamped right now but I'll take the time to digest this ASAP."}}