{"action":"created","issue":{"url":"https://api.github.com/repos/nunit/nunit/issues/1190","labels_url":"https://api.github.com/repos/nunit/nunit/issues/1190/labels{/name}","comments_url":"https://api.github.com/repos/nunit/nunit/issues/1190/comments","events_url":"https://api.github.com/repos/nunit/nunit/issues/1190/events","html_url":"https://github.com/nunit/nunit/issues/1190","id":126091505,"number":1190,"title":"Assert.Throws does not work with async delegates","user":{"login":"yaakov-h","id":426009,"avatar_url":"https://avatars.githubusercontent.com/u/426009?v=3","gravatar_id":"","url":"https://api.github.com/users/yaakov-h","html_url":"https://github.com/yaakov-h","followers_url":"https://api.github.com/users/yaakov-h/followers","following_url":"https://api.github.com/users/yaakov-h/following{/other_user}","gists_url":"https://api.github.com/users/yaakov-h/gists{/gist_id}","starred_url":"https://api.github.com/users/yaakov-h/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yaakov-h/subscriptions","organizations_url":"https://api.github.com/users/yaakov-h/orgs","repos_url":"https://api.github.com/users/yaakov-h/repos","events_url":"https://api.github.com/users/yaakov-h/events{/privacy}","received_events_url":"https://api.github.com/users/yaakov-h/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nunit/nunit/labels/is:bug","name":"is:bug","color":"fc2929"},{"url":"https://api.github.com/repos/nunit/nunit/labels/pri:high","name":"pri:high","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/nunit/nunit/milestones/21","html_url":"https://github.com/nunit/nunit/milestones/Backlog","labels_url":"https://api.github.com/repos/nunit/nunit/milestones/21/labels","id":1444615,"number":21,"title":"Backlog","description":"This pseudo-milestone contains all items accepted for implementation but not assigned to a specific milestone. Developers should give priority to work on the current milestone, but may also chose items from the backlog to work on.","creator":{"login":"CharliePoole","id":2678661,"avatar_url":"https://avatars.githubusercontent.com/u/2678661?v=3","gravatar_id":"","url":"https://api.github.com/users/CharliePoole","html_url":"https://github.com/CharliePoole","followers_url":"https://api.github.com/users/CharliePoole/followers","following_url":"https://api.github.com/users/CharliePoole/following{/other_user}","gists_url":"https://api.github.com/users/CharliePoole/gists{/gist_id}","starred_url":"https://api.github.com/users/CharliePoole/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CharliePoole/subscriptions","organizations_url":"https://api.github.com/users/CharliePoole/orgs","repos_url":"https://api.github.com/users/CharliePoole/repos","events_url":"https://api.github.com/users/CharliePoole/events{/privacy}","received_events_url":"https://api.github.com/users/CharliePoole/received_events","type":"User","site_admin":false},"open_issues":115,"closed_issues":0,"state":"open","created_at":"2015-12-04T17:34:57Z","updated_at":"2016-01-15T15:45:43Z","due_on":"2020-12-31T08:00:00Z","closed_at":null},"comments":1,"created_at":"2016-01-12T03:51:39Z","updated_at":"2016-01-15T15:57:10Z","closed_at":null,"body":"With this test case:\r\n\r\n```\r\nusing System;\r\nusing System.Threading.Tasks;\r\nusing NUnit.Framework;\r\n\r\nnamespace NUnitAsync\r\n{\r\n\t[TestFixture]\r\n\tpublic class Class1\r\n\t{\r\n\t\t[Test]\r\n\t\tpublic void MyAsyncThingTest()\r\n\t\t{\r\n\t\t\tvar ioe = Assert.Throws<InvalidOperationException>(async () => await DelayedFailureAsync());\r\n\t\t\tAssert.That(ioe.Message, Is.EqualTo(\"ABC\"));\r\n\t\t}\r\n\r\n\t\t[Test]\r\n\t\tpublic void MyAsyncThingFluentTest()\r\n\t\t{\r\n\t\t\tAssert.That(async () => await DelayedFailureAsync(), Throws.Exception.TypeOf<InvalidOperationException>().And.Message.EqualTo(\"ABC\"));\r\n\t\t}\r\n\r\n\t\tstatic async Task DelayedFailureAsync()\r\n\t\t{\r\n\t\t\tawait Task.Delay(TimeSpan.FromSeconds(2)).ConfigureAwait(false);\r\n\t\t\tthrow new InvalidOperationException(\"ABC\");\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n:negative_squared_cross_mark:  `MyAsyncThingTest` fails with this exception:\r\n```\r\nTest Name:\tMyAsyncThingTest\r\nTest FullName:\tNUnitAsync.Class1.MyAsyncThingTest\r\nTest Source:\tC:\\Temp\\NUnitAsync\\NUnitAsync\\Class1.cs : line 15\r\nTest Outcome:\tFailed\r\nTest Duration:\t0:00:00.004\r\n\r\nResult StackTrace:\t\r\nat NUnit.Framework.Internal.AsyncInvocationRegion.Create(MethodInfo method)\r\n   at NUnit.Framework.Assert.Throws(IResolveConstraint expression, TestDelegate code, String message, Object[] args)\r\n   at NUnit.Framework.Assert.Throws[TActual](TestDelegate code, String message, Object[] args)\r\n   at NUnit.Framework.Assert.Throws[TActual](TestDelegate code)\r\n   at NUnitAsync.Class1.MyAsyncThingTest() in C:\\Temp\\NUnitAsync\\NUnitAsync\\Class1.cs:line 16\r\nResult Message:\tSystem.ArgumentException : 'async void' methods are not supported, please use 'async Task' instead\r\n```\r\n\r\n:white_check_mark:  `MyAsyncThingFluentTest` passes.\r\n\r\nWhy the difference? `Assert.Throws` returns the exception for further testing, which is useful functionality that the `Assert.That` style does not provide."},"comment":{"url":"https://api.github.com/repos/nunit/nunit/issues/comments/171999430","html_url":"https://github.com/nunit/nunit/issues/1190#issuecomment-171999430","issue_url":"https://api.github.com/repos/nunit/nunit/issues/1190","id":171999430,"user":{"login":"rprouse","id":493828,"avatar_url":"https://avatars.githubusercontent.com/u/493828?v=3","gravatar_id":"","url":"https://api.github.com/users/rprouse","html_url":"https://github.com/rprouse","followers_url":"https://api.github.com/users/rprouse/followers","following_url":"https://api.github.com/users/rprouse/following{/other_user}","gists_url":"https://api.github.com/users/rprouse/gists{/gist_id}","starred_url":"https://api.github.com/users/rprouse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rprouse/subscriptions","organizations_url":"https://api.github.com/users/rprouse/orgs","repos_url":"https://api.github.com/users/rprouse/repos","events_url":"https://api.github.com/users/rprouse/events{/privacy}","received_events_url":"https://api.github.com/users/rprouse/received_events","type":"User","site_admin":false},"created_at":"2016-01-15T15:57:10Z","updated_at":"2016-01-15T15:57:10Z","body":"Thanks for the report. I have confirmed and assigned this as a high priority issue. Both instances take a TestDelegate, so they should behave the same.\r\n\r\nAs for why Assert.That does not return the exception, it is because we don't know which constraint you are going to use based on the signature. It is common to write fluent asserts like `Assert.That(async () => await One(), Is.EqualTo(1)));` which is the same method that you are calling."}}