|
1 | 1 | using System; |
2 | 2 | using Xunit; |
3 | | -using async_enumerable_dotnet; |
4 | | -using System.Threading.Tasks; |
| 3 | +using async_enumerable_dotnet.impl; |
5 | 4 |
|
6 | 5 | namespace async_enumerable_dotnet_test |
7 | 6 | { |
8 | | - public class UnitTest1 |
| 7 | + public class ExceptionHelperTest |
9 | 8 | { |
| 9 | + private Exception _error; |
| 10 | + |
10 | 11 | [Fact] |
11 | | - public async void Test1() |
| 12 | + public void AddException() |
12 | 13 | { |
13 | | - await Task.CompletedTask; |
| 14 | + var ex = new InvalidOperationException(); |
| 15 | + Assert.True(ExceptionHelper.AddException(ref _error, ex)); |
| 16 | + |
| 17 | + Assert.Same(ex, _error); |
14 | 18 | } |
| 19 | + |
| 20 | + [Fact] |
| 21 | + public void AddException_Existing() |
| 22 | + { |
| 23 | + _error = new IndexOutOfRangeException(); |
| 24 | + var ex = new InvalidOperationException(); |
| 25 | + Assert.True(ExceptionHelper.AddException(ref _error, ex)); |
| 26 | + |
| 27 | + Assert.True(_error is AggregateException); |
| 28 | + |
| 29 | + var g = (AggregateException)_error; |
| 30 | + |
| 31 | + Assert.Equal(2, g.InnerExceptions.Count); |
| 32 | + |
| 33 | + Assert.True(g.InnerExceptions[0] is IndexOutOfRangeException); |
| 34 | + Assert.True(g.InnerExceptions[1] is InvalidOperationException); |
| 35 | + } |
| 36 | + |
| 37 | + [Fact] |
| 38 | + public void AddException_Terminated() |
| 39 | + { |
| 40 | + var ex = new InvalidOperationException(); |
| 41 | + |
| 42 | + Assert.True(ExceptionHelper.AddException(ref _error, ex)); |
| 43 | + |
| 44 | + Assert.Same(ExceptionHelper.Terminate(ref _error), ex); |
| 45 | + } |
| 46 | + |
| 47 | + [Fact] |
| 48 | + public void AddException_Terminated_2() |
| 49 | + { |
| 50 | + Assert.Same(ExceptionHelper.Terminate(ref _error), null); |
| 51 | + |
| 52 | + var ex = new InvalidOperationException(); |
| 53 | + |
| 54 | + Assert.False(ExceptionHelper.AddException(ref _error, ex)); |
| 55 | + } |
| 56 | + |
| 57 | + [Fact] |
| 58 | + public void Terminate() |
| 59 | + { |
| 60 | + Assert.Same(ExceptionHelper.Terminate(ref _error), null); |
| 61 | + |
| 62 | + Assert.Same(ExceptionHelper.Terminate(ref _error), ExceptionHelper.Terminated); |
| 63 | + } |
| 64 | + |
| 65 | + [Fact] |
| 66 | + public void Unaggregate_Aggregated_Solo() |
| 67 | + { |
| 68 | + var ex = new InvalidOperationException(); |
| 69 | + |
| 70 | + Assert.Same(ExceptionHelper.Unaggregate(new AggregateException(ex)), ex); |
| 71 | + } |
| 72 | + |
| 73 | + [Fact] |
| 74 | + public void Unaggregate_Aggregated_Not_Solo() |
| 75 | + { |
| 76 | + var ex = new InvalidOperationException(); |
| 77 | + var ex2 = new IndexOutOfRangeException(); |
| 78 | + |
| 79 | + var g = new AggregateException(ex, ex2); |
| 80 | + |
| 81 | + Assert.Same(ExceptionHelper.Unaggregate(g), g); |
| 82 | + } |
| 83 | + |
| 84 | + [Fact] |
| 85 | + public void Unaggregate_Not_Aggregated() |
| 86 | + { |
| 87 | + var ex = new InvalidOperationException(); |
| 88 | + |
| 89 | + Assert.Same(ExceptionHelper.Unaggregate(ex), ex); |
| 90 | + } |
| 91 | + |
15 | 92 | } |
16 | 93 | } |
0 commit comments