-
-
Notifications
You must be signed in to change notification settings - Fork 804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ThrowsAsync
for non-generic ValueTask
#1235
Add ThrowsAsync
for non-generic ValueTask
#1235
Conversation
One of the goals of #1126 was to no longer have to maintain a separate bunch of mock.Setup(m => m.FooAsync()).Returns(async () =>
{
await Task.Delay(...);
throw new BarException(...);
}); I'm not sure I see the point of adding any further specialized methods if the same thing can already be easily done using the existing methods. |
Thanks @stakx, hadn't seen this change, will abandon this! |
@stakx what is the best way to setup throwing an exception for a non-generic |
Sorry for the late reply.
Gotcha. Right now, perhaps the "easiest" way to set up a non-generic task to throw once mock.Setup(m => m.DoSomethingAsync()).Returns(async () => throw ...); But obviously that isn't very nice. I think I previously made an error in reasoning where I thought that for non-generic (i.e. " I can see now that perhaps we do need I'll try to look into this soon. |
ThrowsAsync
for non-generic Task
and ValueTask
Hey @stakx, any update here, it would be great to use this functionality. |
@johnthcall, sorry for the very long radio silence. I needed to take some time off programming-related activities in my spare time due to my daytime work. I'm now going through everything that's accumulated since. I'd be happy to merge the
Any chance that you would be willing to reduce your PR to just that first method overload, and drop all the |
6a5c6e8
to
9014fef
Compare
@stakx I've removed everything but the |
@johnthcall, thank you, looks good to merge. It looks like the project wants you to sign that CLA since this is your first submission, so I'll wait & let you take care of that. |
ThrowsAsync
for non-generic Task
and ValueTask
ThrowsAsync
for non-generic ValueTask
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [Moq](https://github.com/moq/moq) | nuget | minor | `4.18.4` -> `4.20.0` | --- ### Release Notes <details> <summary>moq/moq (Moq)</summary> ### [`v4.20.0`](https://github.com/moq/moq/releases/tag/v4.20.0) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### ✨ Implemented enhancements - Add `setup.Verifiable(Times times, [string failMessage])` method by [@​stakx](https://github.com/stakx) in [https://github.com/moq/moq/pull/1319](https://github.com/moq/moq/pull/1319) ##### 🔨 Other - Add `Mock<T>.RaiseAsync` by [@​stakx](https://github.com/stakx) in [https://github.com/moq/moq/pull/1313](https://github.com/moq/moq/pull/1313) - Add `ThrowsAsync` for non-generic `ValueTask` by [@​johnthcall](https://github.com/johnthcall) in [https://github.com/moq/moq/pull/1235](https://github.com/moq/moq/pull/1235) - Use PackageLicenseExpression instead of PackageLicenseUrl by [@​wismann](https://github.com/wismann) in [https://github.com/moq/moq/pull/1322](https://github.com/moq/moq/pull/1322) - Don't throw away generic type arguments in one `mock.Protected().Verify<T>()` method overload by [@​stakx](https://github.com/stakx) in [https://github.com/moq/moq/pull/1325](https://github.com/moq/moq/pull/1325) - [#​1340](https://github.com/moq/moq/issues/1340) updated appveyor.yml with workaround to make builds work again by [@​david-kalbermatten](https://github.com/david-kalbermatten) in [https://github.com/moq/moq/pull/1346](https://github.com/moq/moq/pull/1346) - Revamp structure, apply oss template, cleanup projects/imports by [@​kzu](https://github.com/kzu) in [https://github.com/moq/moq/pull/1358](https://github.com/moq/moq/pull/1358) - Add 💜 SponsorLink support by [@​kzu](https://github.com/kzu) in [https://github.com/moq/moq/pull/1363](https://github.com/moq/moq/pull/1363) - fix website url by [@​tibel](https://github.com/tibel) in [https://github.com/moq/moq/pull/1364](https://github.com/moq/moq/pull/1364) #### New Contributors - [@​johnthcall](https://github.com/johnthcall) made their first contribution in [https://github.com/moq/moq/pull/1235](https://github.com/moq/moq/pull/1235) - [@​wismann](https://github.com/wismann) made their first contribution in [https://github.com/moq/moq/pull/1322](https://github.com/moq/moq/pull/1322) - [@​david-kalbermatten](https://github.com/david-kalbermatten) made their first contribution in [https://github.com/moq/moq/pull/1346](https://github.com/moq/moq/pull/1346) - [@​dependabot](https://github.com/dependabot) made their first contribution in [https://github.com/moq/moq/pull/1360](https://github.com/moq/moq/pull/1360) **Full Changelog**: moq/moq.spikes@v4.18.4...v4.20.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/Testably/Testably.Architecture.Rules). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4yNy4xIiwidXBkYXRlZEluVmVyIjoiMzYuMjcuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [Moq](https://github.com/moq/moq) | nuget | minor | `4.18.4` -> `4.20.0` | --- ### Release Notes <details> <summary>moq/moq (Moq)</summary> ### [`v4.20.0`](https://github.com/moq/moq/releases/tag/v4.20.0) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed ##### ✨ Implemented enhancements - Add `setup.Verifiable(Times times, [string failMessage])` method by [@​stakx](https://github.com/stakx) in [https://github.com/moq/moq/pull/1319](https://github.com/moq/moq/pull/1319) ##### 🔨 Other - Add `Mock<T>.RaiseAsync` by [@​stakx](https://github.com/stakx) in [https://github.com/moq/moq/pull/1313](https://github.com/moq/moq/pull/1313) - Add `ThrowsAsync` for non-generic `ValueTask` by [@​johnthcall](https://github.com/johnthcall) in [https://github.com/moq/moq/pull/1235](https://github.com/moq/moq/pull/1235) - Use PackageLicenseExpression instead of PackageLicenseUrl by [@​wismann](https://github.com/wismann) in [https://github.com/moq/moq/pull/1322](https://github.com/moq/moq/pull/1322) - Don't throw away generic type arguments in one `mock.Protected().Verify<T>()` method overload by [@​stakx](https://github.com/stakx) in [https://github.com/moq/moq/pull/1325](https://github.com/moq/moq/pull/1325) - [#​1340](https://github.com/moq/moq/issues/1340) updated appveyor.yml with workaround to make builds work again by [@​david-kalbermatten](https://github.com/david-kalbermatten) in [https://github.com/moq/moq/pull/1346](https://github.com/moq/moq/pull/1346) - Revamp structure, apply oss template, cleanup projects/imports by [@​kzu](https://github.com/kzu) in [https://github.com/moq/moq/pull/1358](https://github.com/moq/moq/pull/1358) - Add 💜 SponsorLink support by [@​kzu](https://github.com/kzu) in [https://github.com/moq/moq/pull/1363](https://github.com/moq/moq/pull/1363) - fix website url by [@​tibel](https://github.com/tibel) in [https://github.com/moq/moq/pull/1364](https://github.com/moq/moq/pull/1364) #### New Contributors - [@​johnthcall](https://github.com/johnthcall) made their first contribution in [https://github.com/moq/moq/pull/1235](https://github.com/moq/moq/pull/1235) - [@​wismann](https://github.com/wismann) made their first contribution in [https://github.com/moq/moq/pull/1322](https://github.com/moq/moq/pull/1322) - [@​david-kalbermatten](https://github.com/david-kalbermatten) made their first contribution in [https://github.com/moq/moq/pull/1346](https://github.com/moq/moq/pull/1346) - [@​dependabot](https://github.com/dependabot) made their first contribution in [https://github.com/moq/moq/pull/1360](https://github.com/moq/moq/pull/1360) **Full Changelog**: moq/moq.spikes@v4.18.4...v4.20.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/Testably/Testably.Abstractions). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4yNy4xIiwidXBkYXRlZEluVmVyIjoiMzYuMjcuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
There are scenarios where interface returning Task or ValueTask should mimic an exception with or without a delay. This change aligns the ThrowsAsync for Task and ValueTask with Task and ValueTask .