Add an async-compatible Assert.ThrowsException
Win8 replaced ExpectedExceptionAttribute with Assert.ThrowsException. This is good, but there isn't an equivalent Assert.ThrowsExceptionAsync for async delegates.
Something like this would be fine:
public static async Task ThrowsExceptionAsync<TException>(Func<Task> action, bool allowDerivedTypes = true)
Assert.Fail("Delegate did not throw expected exception " + typeof(TException).Name + ".");
catch (Exception ex)
if (allowDerivedTypes && !(ex is TException))
Assert.Fail("Delegate threw exception of type " + ex.GetType().Name + ", but " + typeof(TException).Name + " or a derived type was expected.");
if (!allowDerivedTypes && ex.GetType() != typeof(TException))
Assert.Fail("Delegate threw exception of type " + ex.GetType().Name + ", but " + typeof(TException).Name + " was expected.");
Thanks for taking the time to share this suggestion. This item has been around for a couple of versions of Visual Studio and we haven’t acted on it. Looking at the VS “15” plans, we’re not going to take action on this item, so we’re going to close it. If the suggestion is still relevant, please either take a look to see if there’s another suggestion that’s similar that you can vote on, or open a new suggestion.
- The Visual Studio Team
Chris McClellan commented
Broken as all get out for UWP. No wonder no one's developing for UWP. MS is treating it like a second class citizen. If I can't test my code, there's no point in writing it to begin with.
Stephen Cleary commented
The update only affects Windows Store test projects. All other unit test projects still do not have this capability.
Howard Richards commented
Microsoft was listening- this being fixed in update 2: see http://support.microsoft.com/kb/2797912