-
Notifications
You must be signed in to change notification settings - Fork 735
/
AssertEx.cs
45 lines (38 loc) · 1.04 KB
/
AssertEx.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
39
40
41
42
43
44
45
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
using Xunit;
using System;
namespace Tests
{
internal class AssertEx
{
internal static void Throws<T>(Action action, Func<T, bool> assert)
where T : Exception
{
var failed = false;
try
{
action();
}
catch (T ex)
{
Assert.True(assert(ex));
failed = true;
}
Assert.True(failed);
}
internal static void SucceedOrFailProper(Action action)
{
try
{
action();
}
catch (AggregateException ex)
{
_ = ex.Flatten().InnerException;
// TODO: proper assert; unfortunately there's not always a good call stack
}
}
}
}