- Notifications
You must be signed in to change notification settings - Fork 324
/
Copy pathExceptionHelper.cs
38 lines (32 loc) · 1.2 KB
/
ExceptionHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
usingSystem;
usingMicrosoft.VisualStudio.TestTools.UnitTesting;
namespaceCommunityToolkit.Mvvm.UnitTests.Helpers;
/// <summary>
/// A helper class to validate scenarios related to <see cref="Exception"/>-s.
/// </summary>
internalstaticclassExceptionHelper
{
/// <summary>
/// Asserts that a given action throws an <see cref="ArgumentException"/> with a specific parameter name.
/// </summary>
/// <param name="action">The input <see cref="Action"/> to invoke.</param>
/// <param name="parameterName">The expected parameter name.</param>
publicstaticvoidThrowsArgumentExceptionWithParameterName(Actionaction,stringparameterName)
{
boolsuccess=false;
try
{
action();
}
catch(Exceptione)
{
Assert.IsTrue(e.GetType()==typeof(ArgumentException));
Assert.AreEqual(parameterName,((ArgumentException)e).ParamName);
success=true;
}
Assert.IsTrue(success);
}
}