FromAsyncPatternTest.cs 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT License.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. using System.Linq;
  6. using System.Reactive;
  7. using System.Reactive.Linq;
  8. using System.Threading.Tasks;
  9. using Microsoft.Reactive.Testing;
  10. using Microsoft.VisualStudio.TestTools.UnitTesting;
  11. using Assert = Xunit.Assert;
  12. namespace ReactiveTests.Tests
  13. {
  14. #pragma warning disable IDE0039 // Use local function
  15. [TestClass]
  16. public class FromAsyncPatternTest : ReactiveTest
  17. {
  18. [TestMethod]
  19. public void FromAsyncPattern_ArgumentChecking()
  20. {
  21. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern(null, iar => { }));
  22. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern(null, iar => 0));
  23. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int>(null, iar => { }));
  24. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int>(null, iar => 0));
  25. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int>(null, iar => { }));
  26. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int>(null, iar => 0));
  27. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int>(null, iar => { }));
  28. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int>(null, iar => 0));
  29. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int>(null, iar => { }));
  30. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int>(null, iar => 0));
  31. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int>(null, iar => { }));
  32. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int>(null, iar => 0));
  33. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int>(null, iar => { }));
  34. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int>(null, iar => 0));
  35. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int>(null, iar => { }));
  36. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int>(null, iar => 0));
  37. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int>(null, iar => { }));
  38. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int>(null, iar => 0));
  39. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int>(null, iar => { }));
  40. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int>(null, iar => 0));
  41. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int>(null, iar => { }));
  42. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int>(null, iar => 0));
  43. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int>(null, iar => { }));
  44. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int, int>(null, iar => 0));
  45. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int, int>(null, iar => { }));
  46. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int, int, int>(null, iar => 0));
  47. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int, int, int>(null, iar => { }));
  48. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int, int, int, int>(null, iar => 0));
  49. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int, int, int, int>(null, iar => { }));
  50. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int, int, int, int, int>(null, iar => 0));
  51. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern((cb, o) => null, default));
  52. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int>((cb, o) => null, default));
  53. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int>((a, cb, o) => null, default));
  54. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int>((a, cb, o) => null, default));
  55. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int>((a, b, cb, o) => null, default));
  56. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int>((a, b, cb, o) => null, default));
  57. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int>((a, b, c, cb, o) => null, default));
  58. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int>((a, b, c, cb, o) => null, default));
  59. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int>((a, b, c, d, cb, o) => null, default));
  60. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int>((a, b, c, d, cb, o) => null, default));
  61. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int>((a, b, c, d, e, cb, o) => null, default));
  62. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int>((a, b, c, d, e, cb, o) => null, default));
  63. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int>((a, b, c, d, e, f, cb, o) => null, default));
  64. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int>((a, b, c, d, e, f, cb, o) => null, default));
  65. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int>((a, b, c, d, e, f, g, cb, o) => null, default));
  66. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, cb, o) => null, default));
  67. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, cb, o) => null, default));
  68. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, cb, o) => null, default));
  69. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, i, cb, o) => null, default));
  70. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, i, cb, o) => null, default));
  71. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, i, j, cb, o) => null, default));
  72. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, i, j, cb, o) => null, default));
  73. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, i, j, k, cb, o) => null, default));
  74. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, i, j, k, cb, o) => null, default));
  75. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, i, j, k, l, cb, o) => null, default));
  76. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, i, j, k, l, cb, o) => null, default));
  77. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, i, j, k, l, m, cb, o) => null, default));
  78. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, i, j, k, l, m, cb, o) => null, default));
  79. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, i, j, k, l, m, n, cb, o) => null, default));
  80. ReactiveAssert.Throws<ArgumentNullException>(() => Observable.FromAsyncPattern<int, int, int, int, int, int, int, int, int, int, int, int, int, int, int>((a, b, c, d, e, f, g, h, i, j, k, l, m, n, cb, o) => null, default));
  81. }
  82. [TestMethod]
  83. public void FromAsyncPattern0()
  84. {
  85. var x = new Result();
  86. Func<AsyncCallback, object, IAsyncResult> begin = (cb, _) => { cb(x); return x; };
  87. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 1; };
  88. var res = Observable.FromAsyncPattern(begin, end)().Materialize().ToEnumerable().ToArray();
  89. Assert.True(res.SequenceEqual([Notification.CreateOnNext(1), Notification.CreateOnCompleted<int>()]));
  90. }
  91. [TestMethod]
  92. public void FromAsyncPatternAction0()
  93. {
  94. var x = new Result();
  95. Func<AsyncCallback, object, IAsyncResult> begin = (cb, _) => { cb(x); return x; };
  96. Action<IAsyncResult> end = iar => { Assert.Same(x, iar); };
  97. var res = Observable.FromAsyncPattern(begin, end)().ToEnumerable().ToArray();
  98. Assert.True(res.SequenceEqual([new Unit()]));
  99. }
  100. [TestMethod]
  101. public void FromAsyncPattern0_Error()
  102. {
  103. var x = new Result();
  104. var ex = new Exception();
  105. Func<AsyncCallback, object, IAsyncResult> begin = (cb, _) => { cb(x); return x; };
  106. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); throw ex; };
  107. var res = Observable.FromAsyncPattern(begin, end)().Materialize().ToEnumerable().ToArray();
  108. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  109. }
  110. [TestMethod]
  111. public void FromAsyncPattern0_ErrorBegin()
  112. {
  113. var x = new Result();
  114. var ex = new Exception();
  115. Func<AsyncCallback, object, IAsyncResult> begin = (cb, _) => { cb(x); throw ex; };
  116. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 0; };
  117. var res = Observable.FromAsyncPattern(begin, end)().Materialize().ToEnumerable().ToArray();
  118. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  119. }
  120. [TestMethod]
  121. public void FromAsyncPattern1()
  122. {
  123. var x = new Result();
  124. Func<int, AsyncCallback, object, IAsyncResult> begin = (a, cb, _) =>
  125. {
  126. Assert.Equal(a, 2);
  127. cb(x);
  128. return x;
  129. };
  130. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 1; };
  131. var res = Observable.FromAsyncPattern(begin, end)(2).Materialize().ToEnumerable().ToArray();
  132. Assert.True(res.SequenceEqual([Notification.CreateOnNext(1), Notification.CreateOnCompleted<int>()]));
  133. }
  134. [TestMethod]
  135. public void FromAsyncPatternAction1()
  136. {
  137. var x = new Result();
  138. Func<int, AsyncCallback, object, IAsyncResult> begin = (a, cb, _) =>
  139. {
  140. Assert.Equal(a, 2);
  141. cb(x);
  142. return x;
  143. };
  144. Action<IAsyncResult> end = iar => { Assert.Same(x, iar); };
  145. var res = Observable.FromAsyncPattern(begin, end)(2).ToEnumerable().ToArray();
  146. Assert.True(res.SequenceEqual([new Unit()]));
  147. }
  148. [TestMethod]
  149. public void FromAsyncPattern1_Error()
  150. {
  151. var x = new Result();
  152. var ex = new Exception();
  153. Func<int, AsyncCallback, object, IAsyncResult> begin = (a, cb, o) => { cb(x); return x; };
  154. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); throw ex; };
  155. var res = Observable.FromAsyncPattern(begin, end)(2).Materialize().ToEnumerable().ToArray();
  156. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  157. }
  158. [TestMethod]
  159. public void FromAsyncPattern1_ErrorBegin()
  160. {
  161. var x = new Result();
  162. var ex = new Exception();
  163. Func<int, AsyncCallback, object, IAsyncResult> begin = (a, cb, o) => { cb(x); throw ex; };
  164. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 0; };
  165. var res = Observable.FromAsyncPattern(begin, end)(2).Materialize().ToEnumerable().ToArray();
  166. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  167. }
  168. [TestMethod]
  169. public void FromAsyncPattern2()
  170. {
  171. var x = new Result();
  172. Func<int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, cb, _) =>
  173. {
  174. Assert.Equal(a, 2);
  175. Assert.Equal(b, 3);
  176. cb(x);
  177. return x;
  178. };
  179. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 1; };
  180. var res = Observable.FromAsyncPattern(begin, end)(2, 3).Materialize().ToEnumerable().ToArray();
  181. Assert.True(res.SequenceEqual([Notification.CreateOnNext(1), Notification.CreateOnCompleted<int>()]));
  182. }
  183. [TestMethod]
  184. public void FromAsyncPatternAction2()
  185. {
  186. var x = new Result();
  187. Func<int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, cb, _) =>
  188. {
  189. Assert.Equal(a, 2);
  190. Assert.Equal(b, 3);
  191. cb(x);
  192. return x;
  193. };
  194. Action<IAsyncResult> end = iar => { Assert.Same(x, iar); };
  195. var res = Observable.FromAsyncPattern(begin, end)(2, 3).ToEnumerable().ToArray();
  196. Assert.True(res.SequenceEqual([new Unit()]));
  197. }
  198. [TestMethod]
  199. public void FromAsyncPattern2_Error()
  200. {
  201. var x = new Result();
  202. var ex = new Exception();
  203. Func<int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, cb, o) => { cb(x); return x; };
  204. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); throw ex; };
  205. var res = Observable.FromAsyncPattern(begin, end)(2, 3).Materialize().ToEnumerable().ToArray();
  206. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  207. }
  208. [TestMethod]
  209. public void FromAsyncPattern2_ErrorBegin()
  210. {
  211. var x = new Result();
  212. var ex = new Exception();
  213. Func<int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, cb, o) => { cb(x); throw ex; };
  214. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 0; };
  215. var res = Observable.FromAsyncPattern(begin, end)(2, 3).Materialize().ToEnumerable().ToArray();
  216. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  217. }
  218. [TestMethod]
  219. public void FromAsyncPattern3()
  220. {
  221. var x = new Result();
  222. Func<int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, cb, _) =>
  223. {
  224. Assert.Equal(a, 2);
  225. Assert.Equal(b, 3);
  226. Assert.Equal(c, 4);
  227. cb(x);
  228. return x;
  229. };
  230. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 1; };
  231. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4).Materialize().ToEnumerable().ToArray();
  232. Assert.True(res.SequenceEqual([Notification.CreateOnNext(1), Notification.CreateOnCompleted<int>()]));
  233. }
  234. [TestMethod]
  235. public void FromAsyncPatternAction3()
  236. {
  237. var x = new Result();
  238. Func<int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, cb, _) =>
  239. {
  240. Assert.Equal(a, 2);
  241. Assert.Equal(b, 3);
  242. Assert.Equal(c, 4);
  243. cb(x);
  244. return x;
  245. };
  246. Action<IAsyncResult> end = iar => { Assert.Same(x, iar); };
  247. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4).ToEnumerable().ToArray();
  248. Assert.True(res.SequenceEqual([new Unit()]));
  249. }
  250. [TestMethod]
  251. public void FromAsyncPattern3_Error()
  252. {
  253. var x = new Result();
  254. var ex = new Exception();
  255. Func<int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, cb, o) => { cb(x); return x; };
  256. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); throw ex; };
  257. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4).Materialize().ToEnumerable().ToArray();
  258. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  259. }
  260. [TestMethod]
  261. public void FromAsyncPattern3_ErrorBegin()
  262. {
  263. var x = new Result();
  264. var ex = new Exception();
  265. Func<int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, cb, o) => { cb(x); throw ex; };
  266. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 0; };
  267. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4).Materialize().ToEnumerable().ToArray();
  268. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  269. }
  270. [TestMethod]
  271. public void FromAsyncPattern4()
  272. {
  273. var x = new Result();
  274. Func<int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, cb, _) =>
  275. {
  276. Assert.Equal(a, 2);
  277. Assert.Equal(b, 3);
  278. Assert.Equal(c, 4);
  279. Assert.Equal(d, 5);
  280. cb(x);
  281. return x;
  282. };
  283. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 1; };
  284. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5).Materialize().ToEnumerable().ToArray();
  285. Assert.True(res.SequenceEqual([Notification.CreateOnNext(1), Notification.CreateOnCompleted<int>()]));
  286. }
  287. [TestMethod]
  288. public void FromAsyncPatternAction4()
  289. {
  290. var x = new Result();
  291. Func<int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, cb, _) =>
  292. {
  293. Assert.Equal(a, 2);
  294. Assert.Equal(b, 3);
  295. Assert.Equal(c, 4);
  296. Assert.Equal(d, 5);
  297. cb(x);
  298. return x;
  299. };
  300. Action<IAsyncResult> end = iar => { Assert.Same(x, iar); };
  301. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5).ToEnumerable().ToArray();
  302. Assert.True(res.SequenceEqual([new Unit()]));
  303. }
  304. [TestMethod]
  305. public void FromAsyncPattern4_Error()
  306. {
  307. var x = new Result();
  308. var ex = new Exception();
  309. Func<int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, cb, o) => { cb(x); return x; };
  310. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); throw ex; };
  311. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5).Materialize().ToEnumerable().ToArray();
  312. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  313. }
  314. [TestMethod]
  315. public void FromAsyncPattern4_ErrorBegin()
  316. {
  317. var x = new Result();
  318. var ex = new Exception();
  319. Func<int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, cb, o) => { cb(x); throw ex; };
  320. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 0; };
  321. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5).Materialize().ToEnumerable().ToArray();
  322. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  323. }
  324. [TestMethod]
  325. public void FromAsyncPattern5()
  326. {
  327. var x = new Result();
  328. Func<int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, cb, _) =>
  329. {
  330. Assert.Equal(a, 2);
  331. Assert.Equal(b, 3);
  332. Assert.Equal(c, 4);
  333. Assert.Equal(d, 5);
  334. Assert.Equal(e, 6);
  335. cb(x);
  336. return x;
  337. };
  338. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 1; };
  339. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6).Materialize().ToEnumerable().ToArray();
  340. Assert.True(res.SequenceEqual([Notification.CreateOnNext(1), Notification.CreateOnCompleted<int>()]));
  341. }
  342. [TestMethod]
  343. public void FromAsyncPatternAction5()
  344. {
  345. var x = new Result();
  346. Func<int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, cb, _) =>
  347. {
  348. Assert.Equal(a, 2);
  349. Assert.Equal(b, 3);
  350. Assert.Equal(c, 4);
  351. Assert.Equal(d, 5);
  352. Assert.Equal(e, 6);
  353. cb(x);
  354. return x;
  355. };
  356. Action<IAsyncResult> end = iar => { Assert.Same(x, iar); };
  357. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6).ToEnumerable().ToArray();
  358. Assert.True(res.SequenceEqual([new Unit()]));
  359. }
  360. [TestMethod]
  361. public void FromAsyncPattern5_Error()
  362. {
  363. var x = new Result();
  364. var ex = new Exception();
  365. Func<int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, cb, o) => { cb(x); return x; };
  366. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); throw ex; };
  367. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6).Materialize().ToEnumerable().ToArray();
  368. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  369. }
  370. [TestMethod]
  371. public void FromAsyncPattern5_ErrorBegin()
  372. {
  373. var x = new Result();
  374. var ex = new Exception();
  375. Func<int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, cb, o) => { cb(x); throw ex; };
  376. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 0; };
  377. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6).Materialize().ToEnumerable().ToArray();
  378. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  379. }
  380. [TestMethod]
  381. public void FromAsyncPattern6()
  382. {
  383. var x = new Result();
  384. Func<int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, cb, _) =>
  385. {
  386. Assert.Equal(a, 2);
  387. Assert.Equal(b, 3);
  388. Assert.Equal(c, 4);
  389. Assert.Equal(d, 5);
  390. Assert.Equal(e, 6);
  391. Assert.Equal(f, 7);
  392. cb(x);
  393. return x;
  394. };
  395. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 1; };
  396. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7).Materialize().ToEnumerable().ToArray();
  397. Assert.True(res.SequenceEqual([Notification.CreateOnNext(1), Notification.CreateOnCompleted<int>()]));
  398. }
  399. [TestMethod]
  400. public void FromAsyncPatternAction6()
  401. {
  402. var x = new Result();
  403. Func<int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, cb, _) =>
  404. {
  405. Assert.Equal(a, 2);
  406. Assert.Equal(b, 3);
  407. Assert.Equal(c, 4);
  408. Assert.Equal(d, 5);
  409. Assert.Equal(e, 6);
  410. Assert.Equal(f, 7);
  411. cb(x);
  412. return x;
  413. };
  414. Action<IAsyncResult> end = iar => { Assert.Same(x, iar); };
  415. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7).ToEnumerable().ToArray();
  416. Assert.True(res.SequenceEqual([new Unit()]));
  417. }
  418. [TestMethod]
  419. public void FromAsyncPattern6_Error()
  420. {
  421. var x = new Result();
  422. var ex = new Exception();
  423. Func<int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, cb, o) => { cb(x); return x; };
  424. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); throw ex; };
  425. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7).Materialize().ToEnumerable().ToArray();
  426. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  427. }
  428. [TestMethod]
  429. public void FromAsyncPattern6_ErrorBegin()
  430. {
  431. var x = new Result();
  432. var ex = new Exception();
  433. Func<int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, cb, o) => { cb(x); throw ex; };
  434. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 0; };
  435. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7).Materialize().ToEnumerable().ToArray();
  436. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  437. }
  438. [TestMethod]
  439. public void FromAsyncPattern7()
  440. {
  441. var x = new Result();
  442. Func<int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, cb, _) =>
  443. {
  444. Assert.Equal(a, 2);
  445. Assert.Equal(b, 3);
  446. Assert.Equal(c, 4);
  447. Assert.Equal(d, 5);
  448. Assert.Equal(e, 6);
  449. Assert.Equal(f, 7);
  450. Assert.Equal(g, 8);
  451. cb(x);
  452. return x;
  453. };
  454. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 1; };
  455. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8).Materialize().ToEnumerable().ToArray();
  456. Assert.True(res.SequenceEqual([Notification.CreateOnNext(1), Notification.CreateOnCompleted<int>()]));
  457. }
  458. [TestMethod]
  459. public void FromAsyncPatternAction7()
  460. {
  461. var x = new Result();
  462. Func<int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, cb, _) =>
  463. {
  464. Assert.Equal(a, 2);
  465. Assert.Equal(b, 3);
  466. Assert.Equal(c, 4);
  467. Assert.Equal(d, 5);
  468. Assert.Equal(e, 6);
  469. Assert.Equal(f, 7);
  470. Assert.Equal(g, 8);
  471. cb(x);
  472. return x;
  473. };
  474. Action<IAsyncResult> end = iar => { Assert.Same(x, iar); };
  475. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8).ToEnumerable().ToArray();
  476. Assert.True(res.SequenceEqual([new Unit()]));
  477. }
  478. [TestMethod]
  479. public void FromAsyncPattern7_Error()
  480. {
  481. var x = new Result();
  482. var ex = new Exception();
  483. Func<int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, cb, o) => { cb(x); return x; };
  484. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); throw ex; };
  485. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8).Materialize().ToEnumerable().ToArray();
  486. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  487. }
  488. [TestMethod]
  489. public void FromAsyncPattern7_ErrorBegin()
  490. {
  491. var x = new Result();
  492. var ex = new Exception();
  493. Func<int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, cb, o) => { cb(x); throw ex; };
  494. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 0; };
  495. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8).Materialize().ToEnumerable().ToArray();
  496. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  497. }
  498. [TestMethod]
  499. public void FromAsyncPattern8()
  500. {
  501. var x = new Result();
  502. Func<int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, cb, _) =>
  503. {
  504. Assert.Equal(a, 2);
  505. Assert.Equal(b, 3);
  506. Assert.Equal(c, 4);
  507. Assert.Equal(d, 5);
  508. Assert.Equal(e, 6);
  509. Assert.Equal(f, 7);
  510. Assert.Equal(g, 8);
  511. Assert.Equal(h, 9);
  512. cb(x);
  513. return x;
  514. };
  515. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 1; };
  516. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9).Materialize().ToEnumerable().ToArray();
  517. Assert.True(res.SequenceEqual([Notification.CreateOnNext(1), Notification.CreateOnCompleted<int>()]));
  518. }
  519. [TestMethod]
  520. public void FromAsyncPatternAction8()
  521. {
  522. var x = new Result();
  523. Func<int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, cb, _) =>
  524. {
  525. Assert.Equal(a, 2);
  526. Assert.Equal(b, 3);
  527. Assert.Equal(c, 4);
  528. Assert.Equal(d, 5);
  529. Assert.Equal(e, 6);
  530. Assert.Equal(f, 7);
  531. Assert.Equal(g, 8);
  532. Assert.Equal(h, 9);
  533. cb(x);
  534. return x;
  535. };
  536. Action<IAsyncResult> end = iar => { Assert.Same(x, iar); };
  537. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9).ToEnumerable().ToArray();
  538. Assert.True(res.SequenceEqual([new Unit()]));
  539. }
  540. [TestMethod]
  541. public void FromAsyncPattern8_Error()
  542. {
  543. var x = new Result();
  544. var ex = new Exception();
  545. Func<int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, cb, o) => { cb(x); return x; };
  546. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); throw ex; };
  547. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9).Materialize().ToEnumerable().ToArray();
  548. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  549. }
  550. [TestMethod]
  551. public void FromAsyncPattern8_ErrorBegin()
  552. {
  553. var x = new Result();
  554. var ex = new Exception();
  555. Func<int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, cb, o) => { cb(x); throw ex; };
  556. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 0; };
  557. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9).Materialize().ToEnumerable().ToArray();
  558. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  559. }
  560. [TestMethod]
  561. public void FromAsyncPattern9()
  562. {
  563. var x = new Result();
  564. Func<int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, cb, _) =>
  565. {
  566. Assert.Equal(a, 2);
  567. Assert.Equal(b, 3);
  568. Assert.Equal(c, 4);
  569. Assert.Equal(d, 5);
  570. Assert.Equal(e, 6);
  571. Assert.Equal(f, 7);
  572. Assert.Equal(g, 8);
  573. Assert.Equal(h, 9);
  574. Assert.Equal(i, 10);
  575. cb(x);
  576. return x;
  577. };
  578. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 1; };
  579. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10).Materialize().ToEnumerable().ToArray();
  580. Assert.True(res.SequenceEqual([Notification.CreateOnNext(1), Notification.CreateOnCompleted<int>()]));
  581. }
  582. [TestMethod]
  583. public void FromAsyncPatternAction9()
  584. {
  585. var x = new Result();
  586. Func<int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, cb, _) =>
  587. {
  588. Assert.Equal(a, 2);
  589. Assert.Equal(b, 3);
  590. Assert.Equal(c, 4);
  591. Assert.Equal(d, 5);
  592. Assert.Equal(e, 6);
  593. Assert.Equal(f, 7);
  594. Assert.Equal(g, 8);
  595. Assert.Equal(h, 9);
  596. Assert.Equal(i, 10);
  597. cb(x);
  598. return x;
  599. };
  600. Action<IAsyncResult> end = iar => { Assert.Same(x, iar); };
  601. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10).ToEnumerable().ToArray();
  602. Assert.True(res.SequenceEqual([new Unit()]));
  603. }
  604. [TestMethod]
  605. public void FromAsyncPattern9_Error()
  606. {
  607. var x = new Result();
  608. var ex = new Exception();
  609. Func<int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, cb, o) => { cb(x); return x; };
  610. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); throw ex; };
  611. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10).Materialize().ToEnumerable().ToArray();
  612. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  613. }
  614. [TestMethod]
  615. public void FromAsyncPattern9_ErrorBegin()
  616. {
  617. var x = new Result();
  618. var ex = new Exception();
  619. Func<int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, cb, o) => { cb(x); throw ex; };
  620. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 0; };
  621. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10).Materialize().ToEnumerable().ToArray();
  622. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  623. }
  624. [TestMethod]
  625. public void FromAsyncPattern10()
  626. {
  627. var x = new Result();
  628. Func<int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, cb, _) =>
  629. {
  630. Assert.Equal(a, 2);
  631. Assert.Equal(b, 3);
  632. Assert.Equal(c, 4);
  633. Assert.Equal(d, 5);
  634. Assert.Equal(e, 6);
  635. Assert.Equal(f, 7);
  636. Assert.Equal(g, 8);
  637. Assert.Equal(h, 9);
  638. Assert.Equal(i, 10);
  639. Assert.Equal(j, 11);
  640. cb(x);
  641. return x;
  642. };
  643. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 1; };
  644. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11).Materialize().ToEnumerable().ToArray();
  645. Assert.True(res.SequenceEqual([Notification.CreateOnNext(1), Notification.CreateOnCompleted<int>()]));
  646. }
  647. [TestMethod]
  648. public void FromAsyncPatternAction10()
  649. {
  650. var x = new Result();
  651. Func<int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, cb, _) =>
  652. {
  653. Assert.Equal(a, 2);
  654. Assert.Equal(b, 3);
  655. Assert.Equal(c, 4);
  656. Assert.Equal(d, 5);
  657. Assert.Equal(e, 6);
  658. Assert.Equal(f, 7);
  659. Assert.Equal(g, 8);
  660. Assert.Equal(h, 9);
  661. Assert.Equal(i, 10);
  662. Assert.Equal(j, 11);
  663. cb(x);
  664. return x;
  665. };
  666. Action<IAsyncResult> end = iar => { Assert.Same(x, iar); };
  667. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11).ToEnumerable().ToArray();
  668. Assert.True(res.SequenceEqual([new Unit()]));
  669. }
  670. [TestMethod]
  671. public void FromAsyncPattern10_Error()
  672. {
  673. var x = new Result();
  674. var ex = new Exception();
  675. Func<int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, cb, o) => { cb(x); return x; };
  676. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); throw ex; };
  677. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11).Materialize().ToEnumerable().ToArray();
  678. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  679. }
  680. [TestMethod]
  681. public void FromAsyncPattern10_ErrorBegin()
  682. {
  683. var x = new Result();
  684. var ex = new Exception();
  685. Func<int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, cb, o) => { cb(x); throw ex; };
  686. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 0; };
  687. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11).Materialize().ToEnumerable().ToArray();
  688. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  689. }
  690. [TestMethod]
  691. public void FromAsyncPattern11()
  692. {
  693. var x = new Result();
  694. Func<int, int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, k, cb, _) =>
  695. {
  696. Assert.Equal(a, 2);
  697. Assert.Equal(b, 3);
  698. Assert.Equal(c, 4);
  699. Assert.Equal(d, 5);
  700. Assert.Equal(e, 6);
  701. Assert.Equal(f, 7);
  702. Assert.Equal(g, 8);
  703. Assert.Equal(h, 9);
  704. Assert.Equal(i, 10);
  705. Assert.Equal(j, 11);
  706. Assert.Equal(k, 12);
  707. cb(x);
  708. return x;
  709. };
  710. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 1; };
  711. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12).Materialize().ToEnumerable().ToArray();
  712. Assert.True(res.SequenceEqual([Notification.CreateOnNext(1), Notification.CreateOnCompleted<int>()]));
  713. }
  714. [TestMethod]
  715. public void FromAsyncPatternAction11()
  716. {
  717. var x = new Result();
  718. Func<int, int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, k, cb, _) =>
  719. {
  720. Assert.Equal(a, 2);
  721. Assert.Equal(b, 3);
  722. Assert.Equal(c, 4);
  723. Assert.Equal(d, 5);
  724. Assert.Equal(e, 6);
  725. Assert.Equal(f, 7);
  726. Assert.Equal(g, 8);
  727. Assert.Equal(h, 9);
  728. Assert.Equal(i, 10);
  729. Assert.Equal(j, 11);
  730. Assert.Equal(k, 12);
  731. cb(x);
  732. return x;
  733. };
  734. Action<IAsyncResult> end = iar => { Assert.Same(x, iar); };
  735. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12).ToEnumerable().ToArray();
  736. Assert.True(res.SequenceEqual([new Unit()]));
  737. }
  738. [TestMethod]
  739. public void FromAsyncPattern11_Error()
  740. {
  741. var x = new Result();
  742. var ex = new Exception();
  743. Func<int, int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, k, cb, o) => { cb(x); return x; };
  744. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); throw ex; };
  745. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12).Materialize().ToEnumerable().ToArray();
  746. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  747. }
  748. [TestMethod]
  749. public void FromAsyncPattern11_ErrorBegin()
  750. {
  751. var x = new Result();
  752. var ex = new Exception();
  753. Func<int, int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, k, cb, o) => { cb(x); throw ex; };
  754. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 0; };
  755. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12).Materialize().ToEnumerable().ToArray();
  756. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  757. }
  758. [TestMethod]
  759. public void FromAsyncPattern12()
  760. {
  761. var x = new Result();
  762. Func<int, int, int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, k, l, cb, _) =>
  763. {
  764. Assert.Equal(a, 2);
  765. Assert.Equal(b, 3);
  766. Assert.Equal(c, 4);
  767. Assert.Equal(d, 5);
  768. Assert.Equal(e, 6);
  769. Assert.Equal(f, 7);
  770. Assert.Equal(g, 8);
  771. Assert.Equal(h, 9);
  772. Assert.Equal(i, 10);
  773. Assert.Equal(j, 11);
  774. Assert.Equal(k, 12);
  775. Assert.Equal(l, 13);
  776. cb(x);
  777. return x;
  778. };
  779. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 1; };
  780. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13).Materialize().ToEnumerable().ToArray();
  781. Assert.True(res.SequenceEqual([Notification.CreateOnNext(1), Notification.CreateOnCompleted<int>()]));
  782. }
  783. [TestMethod]
  784. public void FromAsyncPatternAction12()
  785. {
  786. var x = new Result();
  787. Func<int, int, int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, k, l, cb, _) =>
  788. {
  789. Assert.Equal(a, 2);
  790. Assert.Equal(b, 3);
  791. Assert.Equal(c, 4);
  792. Assert.Equal(d, 5);
  793. Assert.Equal(e, 6);
  794. Assert.Equal(f, 7);
  795. Assert.Equal(g, 8);
  796. Assert.Equal(h, 9);
  797. Assert.Equal(i, 10);
  798. Assert.Equal(j, 11);
  799. Assert.Equal(k, 12);
  800. Assert.Equal(l, 13);
  801. cb(x);
  802. return x;
  803. };
  804. Action<IAsyncResult> end = iar => { Assert.Same(x, iar); };
  805. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13).ToEnumerable().ToArray();
  806. Assert.True(res.SequenceEqual([new Unit()]));
  807. }
  808. [TestMethod]
  809. public void FromAsyncPattern12_Error()
  810. {
  811. var x = new Result();
  812. var ex = new Exception();
  813. Func<int, int, int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, k, l, cb, o) => { cb(x); return x; };
  814. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); throw ex; };
  815. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13).Materialize().ToEnumerable().ToArray();
  816. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  817. }
  818. [TestMethod]
  819. public void FromAsyncPattern12_ErrorBegin()
  820. {
  821. var x = new Result();
  822. var ex = new Exception();
  823. Func<int, int, int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, k, l, cb, o) => { cb(x); throw ex; };
  824. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 0; };
  825. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13).Materialize().ToEnumerable().ToArray();
  826. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  827. }
  828. [TestMethod]
  829. public void FromAsyncPattern13()
  830. {
  831. var x = new Result();
  832. Func<int, int, int, int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, k, l, m, cb, _) =>
  833. {
  834. Assert.Equal(a, 2);
  835. Assert.Equal(b, 3);
  836. Assert.Equal(c, 4);
  837. Assert.Equal(d, 5);
  838. Assert.Equal(e, 6);
  839. Assert.Equal(f, 7);
  840. Assert.Equal(g, 8);
  841. Assert.Equal(h, 9);
  842. Assert.Equal(i, 10);
  843. Assert.Equal(j, 11);
  844. Assert.Equal(k, 12);
  845. Assert.Equal(l, 13);
  846. Assert.Equal(m, 14);
  847. cb(x);
  848. return x;
  849. };
  850. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 1; };
  851. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14).Materialize().ToEnumerable().ToArray();
  852. Assert.True(res.SequenceEqual([Notification.CreateOnNext(1), Notification.CreateOnCompleted<int>()]));
  853. }
  854. [TestMethod]
  855. public void FromAsyncPatternAction13()
  856. {
  857. var x = new Result();
  858. Func<int, int, int, int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, k, l, m, cb, _) =>
  859. {
  860. Assert.Equal(a, 2);
  861. Assert.Equal(b, 3);
  862. Assert.Equal(c, 4);
  863. Assert.Equal(d, 5);
  864. Assert.Equal(e, 6);
  865. Assert.Equal(f, 7);
  866. Assert.Equal(g, 8);
  867. Assert.Equal(h, 9);
  868. Assert.Equal(i, 10);
  869. Assert.Equal(j, 11);
  870. Assert.Equal(k, 12);
  871. Assert.Equal(l, 13);
  872. Assert.Equal(m, 14);
  873. cb(x);
  874. return x;
  875. };
  876. Action<IAsyncResult> end = iar => { Assert.Same(x, iar); };
  877. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14).ToEnumerable().ToArray();
  878. Assert.True(res.SequenceEqual([new Unit()]));
  879. }
  880. [TestMethod]
  881. public void FromAsyncPattern13_Error()
  882. {
  883. var x = new Result();
  884. var ex = new Exception();
  885. Func<int, int, int, int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, k, l, m, cb, o) => { cb(x); return x; };
  886. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); throw ex; };
  887. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14).Materialize().ToEnumerable().ToArray();
  888. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  889. }
  890. [TestMethod]
  891. public void FromAsyncPattern13_ErrorBegin()
  892. {
  893. var x = new Result();
  894. var ex = new Exception();
  895. Func<int, int, int, int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, k, l, m, cb, o) => { cb(x); throw ex; };
  896. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 0; };
  897. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14).Materialize().ToEnumerable().ToArray();
  898. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  899. }
  900. [TestMethod]
  901. public void FromAsyncPattern14()
  902. {
  903. var x = new Result();
  904. Func<int, int, int, int, int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, k, l, m, n, cb, _) =>
  905. {
  906. Assert.Equal(a, 2);
  907. Assert.Equal(b, 3);
  908. Assert.Equal(c, 4);
  909. Assert.Equal(d, 5);
  910. Assert.Equal(e, 6);
  911. Assert.Equal(f, 7);
  912. Assert.Equal(g, 8);
  913. Assert.Equal(h, 9);
  914. Assert.Equal(i, 10);
  915. Assert.Equal(j, 11);
  916. Assert.Equal(k, 12);
  917. Assert.Equal(l, 13);
  918. Assert.Equal(m, 14);
  919. Assert.Equal(n, 15);
  920. cb(x);
  921. return x;
  922. };
  923. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 1; };
  924. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).Materialize().ToEnumerable().ToArray();
  925. Assert.True(res.SequenceEqual([Notification.CreateOnNext(1), Notification.CreateOnCompleted<int>()]));
  926. }
  927. [TestMethod]
  928. public void FromAsyncPatternAction14()
  929. {
  930. var x = new Result();
  931. Func<int, int, int, int, int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, k, l, m, n, cb, _) =>
  932. {
  933. Assert.Equal(a, 2);
  934. Assert.Equal(b, 3);
  935. Assert.Equal(c, 4);
  936. Assert.Equal(d, 5);
  937. Assert.Equal(e, 6);
  938. Assert.Equal(f, 7);
  939. Assert.Equal(g, 8);
  940. Assert.Equal(h, 9);
  941. Assert.Equal(i, 10);
  942. Assert.Equal(j, 11);
  943. Assert.Equal(k, 12);
  944. Assert.Equal(l, 13);
  945. Assert.Equal(m, 14);
  946. Assert.Equal(n, 15);
  947. cb(x);
  948. return x;
  949. };
  950. Action<IAsyncResult> end = iar => { Assert.Same(x, iar); };
  951. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).ToEnumerable().ToArray();
  952. Assert.True(res.SequenceEqual([new Unit()]));
  953. }
  954. [TestMethod]
  955. public void FromAsyncPattern14_Error()
  956. {
  957. var x = new Result();
  958. var ex = new Exception();
  959. Func<int, int, int, int, int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, k, l, m, n, cb, o) => { cb(x); return x; };
  960. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); throw ex; };
  961. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).Materialize().ToEnumerable().ToArray();
  962. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  963. }
  964. [TestMethod]
  965. public void FromAsyncPattern14_ErrorBegin()
  966. {
  967. var x = new Result();
  968. var ex = new Exception();
  969. Func<int, int, int, int, int, int, int, int, int, int, int, int, int, int, AsyncCallback, object, IAsyncResult> begin = (a, b, c, d, e, f, g, h, i, j, k, l, m, n, cb, o) => { cb(x); throw ex; };
  970. Func<IAsyncResult, int> end = iar => { Assert.Same(x, iar); return 0; };
  971. var res = Observable.FromAsyncPattern(begin, end)(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).Materialize().ToEnumerable().ToArray();
  972. Assert.True(res.SequenceEqual([Notification.CreateOnError<int>(ex)]));
  973. }
  974. private class Result : IAsyncResult
  975. {
  976. public object AsyncState
  977. {
  978. get { throw new NotImplementedException(); }
  979. }
  980. public System.Threading.WaitHandle AsyncWaitHandle
  981. {
  982. get { throw new NotImplementedException(); }
  983. }
  984. public bool CompletedSynchronously
  985. {
  986. get { throw new NotImplementedException(); }
  987. }
  988. public bool IsCompleted
  989. {
  990. get { throw new NotImplementedException(); }
  991. }
  992. }
  993. }
  994. #pragma warning restore IDE0039 // Use local function
  995. }