|
| 1 | +// Copyright (c) David Karnok & Contributors. |
| 2 | +// Licensed under the Apache 2.0 License. |
| 3 | +// See LICENSE file in the project root for full license information. |
| 4 | + |
| 5 | +using Xunit; |
| 6 | +using async_enumerable_dotnet; |
| 7 | +using System; |
| 8 | + |
| 9 | +namespace async_enumerable_dotnet_test |
| 10 | +{ |
| 11 | + public class ReplayTest |
| 12 | + { |
| 13 | + [Fact] |
| 14 | + public async void All_Direct() |
| 15 | + { |
| 16 | + await AsyncEnumerable.Range(1, 5) |
| 17 | + .Replay(v => v) |
| 18 | + .AssertResult(1, 2, 3, 4, 5); |
| 19 | + } |
| 20 | + |
| 21 | + [Fact] |
| 22 | + public async void All_Simple() |
| 23 | + { |
| 24 | + await AsyncEnumerable.Range(1, 5) |
| 25 | + .Replay(v => v.Map(w => w + 1)) |
| 26 | + .AssertResult(2, 3, 4, 5, 6); |
| 27 | + } |
| 28 | + |
| 29 | + [Fact] |
| 30 | + public async void All_Take() |
| 31 | + { |
| 32 | + await AsyncEnumerable.Range(1, 5) |
| 33 | + .Replay(v => v.Take(3)) |
| 34 | + .AssertResult(1, 2, 3); |
| 35 | + } |
| 36 | + |
| 37 | + [Fact] |
| 38 | + public async void All_Recombine() |
| 39 | + { |
| 40 | + await AsyncEnumerable.Range(1, 5) |
| 41 | + .Replay(v => v.Take(3).ConcatWith(v.Skip(3))) |
| 42 | + .AssertResult(1, 2, 3, 4, 5); |
| 43 | + } |
| 44 | + |
| 45 | + [Fact] |
| 46 | + public async void All_Twice() |
| 47 | + { |
| 48 | + await AsyncEnumerable.Range(1, 5) |
| 49 | + .Replay(v => v.ConcatWith(v)) |
| 50 | + .AssertResult(1, 2, 3, 4, 5, 1, 2, 3, 4, 5); |
| 51 | + } |
| 52 | + |
| 53 | + [Fact] |
| 54 | + public async void All_Handler_Crash() |
| 55 | + { |
| 56 | + await AsyncEnumerable.Range(1, 5) |
| 57 | + .Replay<int, int>(v => throw new InvalidOperationException()) |
| 58 | + .AssertFailure(typeof(InvalidOperationException)); |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments