Aggregate.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. using System.Linq;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using Xunit;
  9. namespace Tests
  10. {
  11. public class Aggregate : AsyncEnumerableTests
  12. {
  13. [Fact]
  14. public async Task AggregateAsync_Null()
  15. {
  16. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAsync<int>(default, (x, y) => x + y).AsTask());
  17. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAsync(Return42, default).AsTask());
  18. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAsync<int, int>(default, 0, (x, y) => x + y).AsTask());
  19. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAsync(Return42, 0, default).AsTask());
  20. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAsync<int, int, int>(default, 0, (x, y) => x + y, z => z).AsTask());
  21. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAsync(Return42, 0, default, z => z).AsTask());
  22. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAsync<int, int, int>(Return42, 0, (x, y) => x + y, default).AsTask());
  23. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAsync<int>(default, (x, y) => x + y, CancellationToken.None).AsTask());
  24. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAsync(Return42, default, CancellationToken.None).AsTask());
  25. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAsync<int, int>(default, 0, (x, y) => x + y, CancellationToken.None).AsTask());
  26. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAsync(Return42, 0, default, CancellationToken.None).AsTask());
  27. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAsync<int, int, int>(default, 0, (x, y) => x + y, z => z, CancellationToken.None).AsTask());
  28. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAsync(Return42, 0, default, z => z, CancellationToken.None).AsTask());
  29. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAsync<int, int, int>(Return42, 0, (x, y) => x + y, default, CancellationToken.None).AsTask());
  30. }
  31. [Fact]
  32. public async Task AggregateAsync_Simple()
  33. {
  34. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  35. var ys = xs.AggregateAsync((x, y) => x * y);
  36. Assert.Equal(24, await ys);
  37. }
  38. [Fact]
  39. public async Task AggregateAsync_Empty()
  40. {
  41. var xs = new int[0].ToAsyncEnumerable();
  42. var ys = xs.AggregateAsync((x, y) => x * y);
  43. await AssertThrowsAsync<InvalidOperationException>(ys.AsTask());
  44. }
  45. [Fact]
  46. public async Task AggregateAsync_Throw_Source()
  47. {
  48. var ex = new Exception("Bang!");
  49. var xs = Throw<int>(ex);
  50. var ys = xs.AggregateAsync((x, y) => x * y);
  51. await AssertThrowsAsync(ys, ex);
  52. }
  53. [Fact]
  54. public async Task AggregateAsync_Throw_Selector()
  55. {
  56. var ex = new Exception("Bang!");
  57. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  58. var ys = xs.AggregateAsync(new Func<int, int, int>((x, y) => { throw ex; }));
  59. await AssertThrowsAsync(ys, ex);
  60. }
  61. [Fact]
  62. public async Task AggregateAsync_Seed_Simple()
  63. {
  64. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  65. var ys = xs.AggregateAsync(1, (x, y) => x * y);
  66. Assert.Equal(24, await ys);
  67. }
  68. [Fact]
  69. public async Task AggregateAsync_Seed_Emtpy()
  70. {
  71. var xs = new int[0].ToAsyncEnumerable();
  72. var ys = xs.AggregateAsync(1, (x, y) => x * y);
  73. Assert.Equal(1, await ys);
  74. }
  75. [Fact]
  76. public async Task AggregateAsync_Seed_Throw_Source()
  77. {
  78. var ex = new Exception("Bang!");
  79. var xs = Throw<int>(ex);
  80. var ys = xs.AggregateAsync(1, (x, y) => x * y);
  81. await AssertThrowsAsync(ys, ex);
  82. }
  83. [Fact]
  84. public async Task AggregateAsync_Seed_Throw_Selector()
  85. {
  86. var ex = new Exception("Bang!");
  87. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  88. var ys = xs.AggregateAsync(1, new Func<int, int, int>((x, y) => { throw ex; }));
  89. await AssertThrowsAsync(ys, ex);
  90. }
  91. [Fact]
  92. public async Task AggregateAsync_Seed_Result_Simple()
  93. {
  94. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  95. var ys = xs.AggregateAsync(1, (x, y) => x * y, x => x + 1);
  96. Assert.Equal(25, await ys);
  97. }
  98. [Fact]
  99. public async Task AggregateAsync_Seed_Result_Empty()
  100. {
  101. var xs = new int[0].ToAsyncEnumerable();
  102. var ys = xs.AggregateAsync(1, (x, y) => x * y, x => x + 1);
  103. Assert.Equal(2, await ys);
  104. }
  105. [Fact]
  106. public async Task AggregateAsync_Seed_Result_Throw_Source()
  107. {
  108. var ex = new Exception("Bang!");
  109. var xs = Throw<int>(ex);
  110. var ys = xs.AggregateAsync(1, (x, y) => x * y, x => x + 1);
  111. await AssertThrowsAsync(ys, ex);
  112. }
  113. [Fact]
  114. public async Task AggregateAsync_Seed_Result_Throw_Selector()
  115. {
  116. var ex = new Exception("Bang!");
  117. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  118. var ys = xs.AggregateAsync(1, (x, y) => { throw ex; }, x => x + 1);
  119. await AssertThrowsAsync(ys, ex);
  120. }
  121. [Fact]
  122. public async Task AggregateAsync_Seed_Result_Throw_ResultSelector()
  123. {
  124. var ex = new Exception("Bang!");
  125. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  126. var ys = xs.AggregateAsync<int, int, int>(1, (x, y) => x * y, x => { throw ex; });
  127. await AssertThrowsAsync(ys, ex);
  128. }
  129. [Fact]
  130. public async Task AggregateAwaitAsync_Null()
  131. {
  132. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitAsync<int>(default, (x, y) => new ValueTask<int>(x + y)).AsTask());
  133. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitAsync(Return42, default).AsTask());
  134. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitAsync<int, int>(default, 0, (x, y) => new ValueTask<int>(x + y)).AsTask());
  135. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitAsync(Return42, 0, default).AsTask());
  136. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitAsync<int, int, int>(default, 0, (x, y) => new ValueTask<int>(x + y), z => new ValueTask<int>(z)).AsTask());
  137. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitAsync(Return42, 0, default, z => new ValueTask<int>(z)).AsTask());
  138. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitAsync<int, int, int>(Return42, 0, (x, y) => new ValueTask<int>(x + y), default).AsTask());
  139. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitAsync<int>(default, (x, y) => new ValueTask<int>(x + y), CancellationToken.None).AsTask());
  140. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitAsync(Return42, default, CancellationToken.None).AsTask());
  141. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitAsync<int, int>(default, 0, (x, y) => new ValueTask<int>(x + y), CancellationToken.None).AsTask());
  142. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitAsync(Return42, 0, default, CancellationToken.None).AsTask());
  143. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitAsync<int, int, int>(default, 0, (x, y) => new ValueTask<int>(x + y), z => new ValueTask<int>(z), CancellationToken.None).AsTask());
  144. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitAsync(Return42, 0, default, z => new ValueTask<int>(z), CancellationToken.None).AsTask());
  145. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitAsync<int, int, int>(Return42, 0, (x, y) => new ValueTask<int>(x + y), default, CancellationToken.None).AsTask());
  146. }
  147. [Fact]
  148. public async Task AggregateAwaitAsync_Simple()
  149. {
  150. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  151. var ys = xs.AggregateAwaitAsync((x, y) => new ValueTask<int>(x * y));
  152. Assert.Equal(24, await ys);
  153. }
  154. [Fact]
  155. public async Task AggregateAwaitAsync_Empty()
  156. {
  157. var xs = new int[0].ToAsyncEnumerable();
  158. var ys = xs.AggregateAwaitAsync((x, y) => new ValueTask<int>(x * y));
  159. await AssertThrowsAsync<InvalidOperationException>(ys.AsTask());
  160. }
  161. [Fact]
  162. public async Task AggregateAwaitAsync_Throw_Source()
  163. {
  164. var ex = new Exception("Bang!");
  165. var xs = Throw<int>(ex);
  166. var ys = xs.AggregateAwaitAsync((x, y) => new ValueTask<int>(x * y));
  167. await AssertThrowsAsync(ys, ex);
  168. }
  169. [Fact]
  170. public async Task AggregateAwaitAsync_Throw_Selector()
  171. {
  172. var ex = new Exception("Bang!");
  173. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  174. var ys = xs.AggregateAwaitAsync(new Func<int, int, ValueTask<int>>((x, y) => { throw ex; }));
  175. await AssertThrowsAsync(ys, ex);
  176. }
  177. [Fact]
  178. public async Task AggregateAwaitAsync_Seed_Simple()
  179. {
  180. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  181. var ys = xs.AggregateAwaitAsync(1, (x, y) => new ValueTask<int>(x * y));
  182. Assert.Equal(24, await ys);
  183. }
  184. [Fact]
  185. public async Task AggregateAwaitAsync_Seed_Emtpy()
  186. {
  187. var xs = new int[0].ToAsyncEnumerable();
  188. var ys = xs.AggregateAwaitAsync(1, (x, y) => new ValueTask<int>(x * y));
  189. Assert.Equal(1, await ys);
  190. }
  191. [Fact]
  192. public async Task AggregateAwaitAsync_Seed_Throw_Source()
  193. {
  194. var ex = new Exception("Bang!");
  195. var xs = Throw<int>(ex);
  196. var ys = xs.AggregateAwaitAsync(1, (x, y) => new ValueTask<int>(x * y));
  197. await AssertThrowsAsync(ys, ex);
  198. }
  199. [Fact]
  200. public async Task AggregateAwaitAsync_Seed_Throw_Selector()
  201. {
  202. var ex = new Exception("Bang!");
  203. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  204. var ys = xs.AggregateAwaitAsync(1, new Func<int, int, ValueTask<int>>((x, y) => { throw ex; }));
  205. await AssertThrowsAsync(ys, ex);
  206. }
  207. [Fact]
  208. public async Task AggregateAwaitAsync_Seed_Result_Simple()
  209. {
  210. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  211. var ys = xs.AggregateAwaitAsync(1, (x, y) => new ValueTask<int>(x * y), x => new ValueTask<int>(x + 1));
  212. Assert.Equal(25, await ys);
  213. }
  214. [Fact]
  215. public async Task AggregateAwaitAsync_Seed_Result_Empty()
  216. {
  217. var xs = new int[0].ToAsyncEnumerable();
  218. var ys = xs.AggregateAwaitAsync(1, (x, y) => new ValueTask<int>(x * y), x => new ValueTask<int>(x + 1));
  219. Assert.Equal(2, await ys);
  220. }
  221. [Fact]
  222. public async Task AggregateAwaitAsync_Seed_Result_Throw_Source()
  223. {
  224. var ex = new Exception("Bang!");
  225. var xs = Throw<int>(ex);
  226. var ys = xs.AggregateAwaitAsync(1, (x, y) => new ValueTask<int>(x * y), x => new ValueTask<int>(x + 1));
  227. await AssertThrowsAsync(ys, ex);
  228. }
  229. [Fact]
  230. public async Task AggregateAwaitAsync_Seed_Result_Throw_Selector()
  231. {
  232. var ex = new Exception("Bang!");
  233. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  234. var ys = xs.AggregateAwaitAsync(1, new Func<int, int, ValueTask<int>>((x, y) => { throw ex; }), x => new ValueTask<int>(x + 1));
  235. await AssertThrowsAsync(ys, ex);
  236. }
  237. [Fact]
  238. public async Task AggregateAwaitAsync_Seed_Result_Throw_ResultSelector()
  239. {
  240. var ex = new Exception("Bang!");
  241. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  242. var ys = xs.AggregateAwaitAsync<int, int, int>(1, (x, y) => new ValueTask<int>(x * y), x => { throw ex; });
  243. await AssertThrowsAsync(ys, ex);
  244. }
  245. #if !NO_DEEP_CANCELLATION
  246. [Fact]
  247. public async Task AggregateAwaitWithCancellationAsync_Null()
  248. {
  249. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitWithCancellationAsync<int>(default, (x, y, ct) => new ValueTask<int>(x + y)).AsTask());
  250. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitWithCancellationAsync(Return42, default).AsTask());
  251. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitWithCancellationAsync<int, int>(default, 0, (x, y, ct) => new ValueTask<int>(x + y)).AsTask());
  252. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitWithCancellationAsync(Return42, 0, default).AsTask());
  253. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitWithCancellationAsync<int, int, int>(default, 0, (x, y, ct) => new ValueTask<int>(x + y), (z, ct) => new ValueTask<int>(z)).AsTask());
  254. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitWithCancellationAsync(Return42, 0, default, (z, ct) => new ValueTask<int>(z)).AsTask());
  255. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitWithCancellationAsync<int, int, int>(Return42, 0, (x, y, ct) => new ValueTask<int>(x + y), default).AsTask());
  256. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitWithCancellationAsync<int>(default, (x, y, ct) => new ValueTask<int>(x + y), CancellationToken.None).AsTask());
  257. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitWithCancellationAsync(Return42, default, CancellationToken.None).AsTask());
  258. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitWithCancellationAsync<int, int>(default, 0, (x, y, ct) => new ValueTask<int>(x + y), CancellationToken.None).AsTask());
  259. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitWithCancellationAsync(Return42, 0, default, CancellationToken.None).AsTask());
  260. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitWithCancellationAsync<int, int, int>(default, 0, (x, y, ct) => new ValueTask<int>(x + y), (z, ct) => new ValueTask<int>(z), CancellationToken.None).AsTask());
  261. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitWithCancellationAsync(Return42, 0, default, (z, ct) => new ValueTask<int>(z), CancellationToken.None).AsTask());
  262. await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AggregateAwaitWithCancellationAsync<int, int, int>(Return42, 0, (x, y, ct) => new ValueTask<int>(x + y), default, CancellationToken.None).AsTask());
  263. }
  264. [Fact]
  265. public async Task AggregateAwaitWithCancellationAsync_Simple()
  266. {
  267. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  268. var ys = xs.AggregateAwaitWithCancellationAsync((x, y, ct) => new ValueTask<int>(x * y));
  269. Assert.Equal(24, await ys);
  270. }
  271. [Fact]
  272. public async Task AggregateAwaitWithCancellationAsync_Empty()
  273. {
  274. var xs = new int[0].ToAsyncEnumerable();
  275. var ys = xs.AggregateAwaitWithCancellationAsync((x, y, ct) => new ValueTask<int>(x * y));
  276. await AssertThrowsAsync<InvalidOperationException>(ys.AsTask());
  277. }
  278. [Fact]
  279. public async Task AggregateAwaitWithCancellationAsync_Throw_Source()
  280. {
  281. var ex = new Exception("Bang!");
  282. var xs = Throw<int>(ex);
  283. var ys = xs.AggregateAwaitWithCancellationAsync((x, y, ct) => new ValueTask<int>(x * y));
  284. await AssertThrowsAsync(ys, ex);
  285. }
  286. [Fact]
  287. public async Task AggregateAwaitWithCancellationAsync_Throw_Selector()
  288. {
  289. var ex = new Exception("Bang!");
  290. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  291. var ys = xs.AggregateAwaitWithCancellationAsync(new Func<int, int, CancellationToken, ValueTask<int>>((x, y, ct) => { throw ex; }));
  292. await AssertThrowsAsync(ys, ex);
  293. }
  294. [Fact]
  295. public async Task AggregateAwaitWithCancellationAsync_Seed_Simple()
  296. {
  297. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  298. var ys = xs.AggregateAwaitWithCancellationAsync(1, (x, y, ct) => new ValueTask<int>(x * y));
  299. Assert.Equal(24, await ys);
  300. }
  301. [Fact]
  302. public async Task AggregateAwaitWithCancellationAsync_Seed_Emtpy()
  303. {
  304. var xs = new int[0].ToAsyncEnumerable();
  305. var ys = xs.AggregateAwaitWithCancellationAsync(1, (x, y, ct) => new ValueTask<int>(x * y));
  306. Assert.Equal(1, await ys);
  307. }
  308. [Fact]
  309. public async Task AggregateAwaitWithCancellationAsync_Seed_Throw_Source()
  310. {
  311. var ex = new Exception("Bang!");
  312. var xs = Throw<int>(ex);
  313. var ys = xs.AggregateAwaitWithCancellationAsync(1, (x, y, ct) => new ValueTask<int>(x * y));
  314. await AssertThrowsAsync(ys, ex);
  315. }
  316. [Fact]
  317. public async Task AggregateAwaitWithCancellationAsync_Seed_Throw_Selector()
  318. {
  319. var ex = new Exception("Bang!");
  320. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  321. var ys = xs.AggregateAwaitWithCancellationAsync(1, new Func<int, int, CancellationToken, ValueTask<int>>((x, y, ct) => { throw ex; }));
  322. await AssertThrowsAsync(ys, ex);
  323. }
  324. [Fact]
  325. public async Task AggregateAwaitWithCancellationAsync_Seed_Result_Simple()
  326. {
  327. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  328. var ys = xs.AggregateAwaitWithCancellationAsync(1, (x, y, ct) => new ValueTask<int>(x * y), (x, ct) => new ValueTask<int>(x + 1));
  329. Assert.Equal(25, await ys);
  330. }
  331. [Fact]
  332. public async Task AggregateAwaitWithCancellationAsync_Seed_Result_Empty()
  333. {
  334. var xs = new int[0].ToAsyncEnumerable();
  335. var ys = xs.AggregateAwaitWithCancellationAsync(1, (x, y, ct) => new ValueTask<int>(x * y), (x, ct) => new ValueTask<int>(x + 1));
  336. Assert.Equal(2, await ys);
  337. }
  338. [Fact]
  339. public async Task AggregateAwaitWithCancellationAsync_Seed_Result_Throw_Source()
  340. {
  341. var ex = new Exception("Bang!");
  342. var xs = Throw<int>(ex);
  343. var ys = xs.AggregateAwaitWithCancellationAsync(1, (x, y, ct) => new ValueTask<int>(x * y), (x, ct) => new ValueTask<int>(x + 1));
  344. await AssertThrowsAsync(ys, ex);
  345. }
  346. [Fact]
  347. public async Task AggregateAwaitWithCancellationAsync_Seed_Result_Throw_Selector()
  348. {
  349. var ex = new Exception("Bang!");
  350. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  351. var ys = xs.AggregateAwaitWithCancellationAsync(1, new Func<int, int, CancellationToken, ValueTask<int>>((x, y, ct) => { throw ex; }), (x, ct) => new ValueTask<int>(x + 1));
  352. await AssertThrowsAsync(ys, ex);
  353. }
  354. [Fact]
  355. public async Task AggregateAwaitWithCancellationAsync_Seed_Result_Throw_ResultSelector()
  356. {
  357. var ex = new Exception("Bang!");
  358. var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable();
  359. var ys = xs.AggregateAwaitWithCancellationAsync<int, int, int>(1, (x, y, ct) => new ValueTask<int>(x * y), (x, ct) => { throw ex; });
  360. await AssertThrowsAsync(ys, ex);
  361. }
  362. #endif
  363. }
  364. }