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 ValueTaskThrowsAsync for non-generic ValueTask
[](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [Moq](https://togithub.com/moq/moq) | nuget | minor | `4.18.4` -> `4.20.0` | --- ### Release Notes <details> <summary>moq/moq (Moq)</summary> ### [`v4.20.0`](https://togithub.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://togithub.com/stakx) in [https://github.com/moq/moq/pull/1319](https://togithub.com/moq/moq/pull/1319) ##### 🔨 Other - Add `Mock<T>.RaiseAsync` by [@​stakx](https://togithub.com/stakx) in [https://github.com/moq/moq/pull/1313](https://togithub.com/moq/moq/pull/1313) - Add `ThrowsAsync` for non-generic `ValueTask` by [@​johnthcall](https://togithub.com/johnthcall) in [https://github.com/moq/moq/pull/1235](https://togithub.com/moq/moq/pull/1235) - Use PackageLicenseExpression instead of PackageLicenseUrl by [@​wismann](https://togithub.com/wismann) in [https://github.com/moq/moq/pull/1322](https://togithub.com/moq/moq/pull/1322) - Don't throw away generic type arguments in one `mock.Protected().Verify<T>()` method overload by [@​stakx](https://togithub.com/stakx) in [https://github.com/moq/moq/pull/1325](https://togithub.com/moq/moq/pull/1325) - [#​1340](https://togithub.com/moq/moq/issues/1340) updated appveyor.yml with workaround to make builds work again by [@​david-kalbermatten](https://togithub.com/david-kalbermatten) in [https://github.com/moq/moq/pull/1346](https://togithub.com/moq/moq/pull/1346) - Revamp structure, apply oss template, cleanup projects/imports by [@​kzu](https://togithub.com/kzu) in [https://github.com/moq/moq/pull/1358](https://togithub.com/moq/moq/pull/1358) - Add 💜 SponsorLink support by [@​kzu](https://togithub.com/kzu) in [https://github.com/moq/moq/pull/1363](https://togithub.com/moq/moq/pull/1363) - fix website url by [@​tibel](https://togithub.com/tibel) in [https://github.com/moq/moq/pull/1364](https://togithub.com/moq/moq/pull/1364) #### New Contributors - [@​johnthcall](https://togithub.com/johnthcall) made their first contribution in [https://github.com/moq/moq/pull/1235](https://togithub.com/moq/moq/pull/1235) - [@​wismann](https://togithub.com/wismann) made their first contribution in [https://github.com/moq/moq/pull/1322](https://togithub.com/moq/moq/pull/1322) - [@​david-kalbermatten](https://togithub.com/david-kalbermatten) made their first contribution in [https://github.com/moq/moq/pull/1346](https://togithub.com/moq/moq/pull/1346) - [@​dependabot](https://togithub.com/dependabot) made their first contribution in [https://github.com/moq/moq/pull/1360](https://togithub.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>
[](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [Moq](https://togithub.com/moq/moq) | nuget | minor | `4.18.4` -> `4.20.0` | --- ### Release Notes <details> <summary>moq/moq (Moq)</summary> ### [`v4.20.0`](https://togithub.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://togithub.com/stakx) in [https://github.com/moq/moq/pull/1319](https://togithub.com/moq/moq/pull/1319) ##### 🔨 Other - Add `Mock<T>.RaiseAsync` by [@​stakx](https://togithub.com/stakx) in [https://github.com/moq/moq/pull/1313](https://togithub.com/moq/moq/pull/1313) - Add `ThrowsAsync` for non-generic `ValueTask` by [@​johnthcall](https://togithub.com/johnthcall) in [https://github.com/moq/moq/pull/1235](https://togithub.com/moq/moq/pull/1235) - Use PackageLicenseExpression instead of PackageLicenseUrl by [@​wismann](https://togithub.com/wismann) in [https://github.com/moq/moq/pull/1322](https://togithub.com/moq/moq/pull/1322) - Don't throw away generic type arguments in one `mock.Protected().Verify<T>()` method overload by [@​stakx](https://togithub.com/stakx) in [https://github.com/moq/moq/pull/1325](https://togithub.com/moq/moq/pull/1325) - [#​1340](https://togithub.com/moq/moq/issues/1340) updated appveyor.yml with workaround to make builds work again by [@​david-kalbermatten](https://togithub.com/david-kalbermatten) in [https://github.com/moq/moq/pull/1346](https://togithub.com/moq/moq/pull/1346) - Revamp structure, apply oss template, cleanup projects/imports by [@​kzu](https://togithub.com/kzu) in [https://github.com/moq/moq/pull/1358](https://togithub.com/moq/moq/pull/1358) - Add 💜 SponsorLink support by [@​kzu](https://togithub.com/kzu) in [https://github.com/moq/moq/pull/1363](https://togithub.com/moq/moq/pull/1363) - fix website url by [@​tibel](https://togithub.com/tibel) in [https://github.com/moq/moq/pull/1364](https://togithub.com/moq/moq/pull/1364) #### New Contributors - [@​johnthcall](https://togithub.com/johnthcall) made their first contribution in [https://github.com/moq/moq/pull/1235](https://togithub.com/moq/moq/pull/1235) - [@​wismann](https://togithub.com/wismann) made their first contribution in [https://github.com/moq/moq/pull/1322](https://togithub.com/moq/moq/pull/1322) - [@​david-kalbermatten](https://togithub.com/david-kalbermatten) made their first contribution in [https://github.com/moq/moq/pull/1346](https://togithub.com/moq/moq/pull/1346) - [@​dependabot](https://togithub.com/dependabot) made their first contribution in [https://github.com/moq/moq/pull/1360](https://togithub.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 .