/ToMigrate/Raven.Tests.Issues/1379/RavenDB_1379_Client_Lazy.cs

https://github.com/fitzchak/ravendb · C# · 654 lines · 539 code · 115 blank · 0 comment · 0 complexity · 9ee39eed6aa9b4b7227d27b70dbe83a0 MD5 · raw file

  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Raven.Client;
  4. using Raven.Json.Linq;
  5. using Raven.Tests.Common;
  6. using Xunit;
  7. using Xunit.Extensions;
  8. namespace Raven.Tests.Issues
  9. {
  10. public class RavenDB_1379_Client_Lazy : RavenTest
  11. {
  12. public class SomeEntity
  13. {
  14. public string Id { get; set; }
  15. }
  16. [Theory]
  17. [PropertyData("Storages")]
  18. public void PagingWithoutFilters(string requestedStorage)
  19. {
  20. using (var documentStore = NewDocumentStore(requestedStorage: requestedStorage))
  21. {
  22. using (var session = documentStore.OpenSession())
  23. {
  24. session.Store(new SomeEntity { Id = "FooBar1" });
  25. session.Store(new SomeEntity { Id = "BarFoo2" });
  26. session.Store(new SomeEntity { Id = "FooBar3" });
  27. session.Store(new SomeEntity { Id = "FooBar11" });
  28. session.Store(new SomeEntity { Id = "FooBar12" });
  29. session.Store(new SomeEntity { Id = "FooBar21" });
  30. session.Store(new SomeEntity { Id = "FooBar5" });
  31. session.Store(new SomeEntity { Id = "BarFoo7" });
  32. session.Store(new SomeEntity { Id = "FooBar111" });
  33. session.Store(new SomeEntity { Id = "BarFoo6" });
  34. session.Store(new SomeEntity { Id = "FooBar6" });
  35. session.Store(new SomeEntity { Id = "FooBar8" });
  36. session.SaveChanges();
  37. }
  38. using (var session = documentStore.OpenSession())
  39. {
  40. var fetchedDocuments = session.Advanced.Lazily
  41. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 0, 4, string.Empty)
  42. .Value
  43. .ToList();
  44. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  45. Assert.Equal(4, foundDocKeys.Count);
  46. Assert.Contains("FooBar1", foundDocKeys);
  47. Assert.Contains("FooBar11", foundDocKeys);
  48. Assert.Contains("FooBar111", foundDocKeys);
  49. Assert.Contains("FooBar12", foundDocKeys);
  50. }
  51. using (var session = documentStore.OpenSession())
  52. {
  53. var fetchedDocuments = session.Advanced.Lazily
  54. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 4, 4, string.Empty)
  55. .Value
  56. .ToList();
  57. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  58. Assert.Equal(4, foundDocKeys.Count);
  59. Assert.Contains("FooBar21", foundDocKeys);
  60. Assert.Contains("FooBar3", foundDocKeys);
  61. Assert.Contains("FooBar5", foundDocKeys);
  62. Assert.Contains("FooBar6", foundDocKeys);
  63. }
  64. using (var session = documentStore.OpenSession())
  65. {
  66. var fetchedDocuments = session.Advanced.Lazily
  67. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 8, 4, string.Empty)
  68. .Value
  69. .ToList();
  70. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  71. Assert.Equal(1, foundDocKeys.Count);
  72. Assert.Contains("FooBar8", foundDocKeys);
  73. }
  74. }
  75. }
  76. [Theory]
  77. [PropertyData("Storages")]
  78. public void PagingWithoutFilters_Remote(string requestedStorage)
  79. {
  80. using (var documentStore = NewRemoteDocumentStore(requestedStorage: requestedStorage))
  81. {
  82. using (var session = documentStore.OpenSession())
  83. {
  84. session.Store(new SomeEntity { Id = "FooBar1" });
  85. session.Store(new SomeEntity { Id = "BarFoo2" });
  86. session.Store(new SomeEntity { Id = "FooBar3" });
  87. session.Store(new SomeEntity { Id = "FooBar11" });
  88. session.Store(new SomeEntity { Id = "FooBar12" });
  89. session.Store(new SomeEntity { Id = "FooBar21" });
  90. session.Store(new SomeEntity { Id = "FooBar5" });
  91. session.Store(new SomeEntity { Id = "BarFoo7" });
  92. session.Store(new SomeEntity { Id = "FooBar111" });
  93. session.Store(new SomeEntity { Id = "BarFoo6" });
  94. session.Store(new SomeEntity { Id = "FooBar6" });
  95. session.Store(new SomeEntity { Id = "FooBar8" });
  96. session.SaveChanges();
  97. }
  98. using (var session = documentStore.OpenSession())
  99. {
  100. var fetchedDocuments = session.Advanced.Lazily
  101. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 0, 4, string.Empty)
  102. .Value
  103. .ToList();
  104. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  105. Assert.Equal(4, foundDocKeys.Count);
  106. Assert.Contains("FooBar1", foundDocKeys);
  107. Assert.Contains("FooBar11", foundDocKeys);
  108. Assert.Contains("FooBar111", foundDocKeys);
  109. Assert.Contains("FooBar12", foundDocKeys);
  110. }
  111. using (var session = documentStore.OpenSession())
  112. {
  113. var fetchedDocuments = session.Advanced.Lazily
  114. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 4, 4, string.Empty)
  115. .Value
  116. .ToList();
  117. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  118. Assert.Equal(4, foundDocKeys.Count);
  119. Assert.Contains("FooBar21", foundDocKeys);
  120. Assert.Contains("FooBar3", foundDocKeys);
  121. Assert.Contains("FooBar5", foundDocKeys);
  122. Assert.Contains("FooBar6", foundDocKeys);
  123. }
  124. using (var session = documentStore.OpenSession())
  125. {
  126. var fetchedDocuments = session.Advanced.Lazily
  127. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 8, 4, string.Empty)
  128. .Value
  129. .ToList();
  130. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  131. Assert.Equal(1, foundDocKeys.Count);
  132. Assert.Contains("FooBar8", foundDocKeys);
  133. }
  134. }
  135. }
  136. [Theory]
  137. [PropertyData("Storages")]
  138. public void PagingWithoutFiltersWithPagingInformation(string requestedStorage)
  139. {
  140. using (var documentStore = NewDocumentStore(requestedStorage: requestedStorage))
  141. {
  142. using (var session = documentStore.OpenSession())
  143. {
  144. session.Store(new SomeEntity { Id = "FooBar1" });
  145. session.Store(new SomeEntity { Id = "BarFoo2" });
  146. session.Store(new SomeEntity { Id = "FooBar3" });
  147. session.Store(new SomeEntity { Id = "FooBar11" });
  148. session.Store(new SomeEntity { Id = "FooBar12" });
  149. session.Store(new SomeEntity { Id = "FooBar21" });
  150. session.Store(new SomeEntity { Id = "FooBar5" });
  151. session.Store(new SomeEntity { Id = "BarFoo7" });
  152. session.Store(new SomeEntity { Id = "FooBar111" });
  153. session.Store(new SomeEntity { Id = "BarFoo6" });
  154. session.Store(new SomeEntity { Id = "FooBar6" });
  155. session.Store(new SomeEntity { Id = "FooBar8" });
  156. session.SaveChanges();
  157. }
  158. var pagingInformation = new RavenPagingInformation();
  159. using (var session = documentStore.OpenSession())
  160. {
  161. var fetchedDocuments = session.Advanced.Lazily
  162. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 0, 4, string.Empty, pagingInformation: pagingInformation)
  163. .Value
  164. .ToList();
  165. Assert.Equal(4, pagingInformation.PageSize);
  166. Assert.Equal(0, pagingInformation.Start);
  167. Assert.Equal(4, pagingInformation.NextPageStart);
  168. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  169. Assert.Equal(4, foundDocKeys.Count);
  170. Assert.Contains("FooBar1", foundDocKeys);
  171. Assert.Contains("FooBar11", foundDocKeys);
  172. Assert.Contains("FooBar111", foundDocKeys);
  173. Assert.Contains("FooBar12", foundDocKeys);
  174. }
  175. using (var session = documentStore.OpenSession())
  176. {
  177. var fetchedDocuments = session.Advanced.Lazily
  178. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 4, 4, string.Empty, pagingInformation: pagingInformation)
  179. .Value
  180. .ToList();
  181. Assert.Equal(4, pagingInformation.PageSize);
  182. Assert.Equal(4, pagingInformation.Start);
  183. Assert.Equal(8, pagingInformation.NextPageStart);
  184. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  185. Assert.Equal(4, foundDocKeys.Count);
  186. Assert.Contains("FooBar21", foundDocKeys);
  187. Assert.Contains("FooBar3", foundDocKeys);
  188. Assert.Contains("FooBar5", foundDocKeys);
  189. Assert.Contains("FooBar6", foundDocKeys);
  190. }
  191. using (var session = documentStore.OpenSession())
  192. {
  193. var fetchedDocuments = session.Advanced.Lazily
  194. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 8, 4, string.Empty, pagingInformation: pagingInformation)
  195. .Value
  196. .ToList();
  197. Assert.Equal(4, pagingInformation.PageSize);
  198. Assert.Equal(8, pagingInformation.Start);
  199. Assert.Equal(8, pagingInformation.NextPageStart);
  200. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  201. Assert.Equal(1, foundDocKeys.Count);
  202. Assert.Contains("FooBar8", foundDocKeys);
  203. }
  204. }
  205. }
  206. [Theory]
  207. [PropertyData("Storages")]
  208. public void PagingWithoutFiltersWithPagingInformation_Remote(string requestedStorage)
  209. {
  210. using (var documentStore = NewRemoteDocumentStore(requestedStorage: requestedStorage))
  211. {
  212. using (var session = documentStore.OpenSession())
  213. {
  214. session.Store(new SomeEntity { Id = "FooBar1" });
  215. session.Store(new SomeEntity { Id = "BarFoo2" });
  216. session.Store(new SomeEntity { Id = "FooBar3" });
  217. session.Store(new SomeEntity { Id = "FooBar11" });
  218. session.Store(new SomeEntity { Id = "FooBar12" });
  219. session.Store(new SomeEntity { Id = "FooBar21" });
  220. session.Store(new SomeEntity { Id = "FooBar5" });
  221. session.Store(new SomeEntity { Id = "BarFoo7" });
  222. session.Store(new SomeEntity { Id = "FooBar111" });
  223. session.Store(new SomeEntity { Id = "BarFoo6" });
  224. session.Store(new SomeEntity { Id = "FooBar6" });
  225. session.Store(new SomeEntity { Id = "FooBar8" });
  226. session.SaveChanges();
  227. }
  228. var pagingInformation = new RavenPagingInformation();
  229. using (var session = documentStore.OpenSession())
  230. {
  231. var fetchedDocuments = session.Advanced.Lazily
  232. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 0, 4, string.Empty, pagingInformation: pagingInformation)
  233. .Value
  234. .ToList();
  235. Assert.Equal(4, pagingInformation.PageSize);
  236. Assert.Equal(0, pagingInformation.Start);
  237. Assert.Equal(4, pagingInformation.NextPageStart);
  238. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  239. Assert.Equal(4, foundDocKeys.Count);
  240. Assert.Contains("FooBar1", foundDocKeys);
  241. Assert.Contains("FooBar11", foundDocKeys);
  242. Assert.Contains("FooBar111", foundDocKeys);
  243. Assert.Contains("FooBar12", foundDocKeys);
  244. }
  245. using (var session = documentStore.OpenSession())
  246. {
  247. var fetchedDocuments = session.Advanced.Lazily
  248. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 4, 4, string.Empty, pagingInformation: pagingInformation)
  249. .Value
  250. .ToList();
  251. Assert.Equal(4, pagingInformation.PageSize);
  252. Assert.Equal(4, pagingInformation.Start);
  253. Assert.Equal(8, pagingInformation.NextPageStart);
  254. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  255. Assert.Equal(4, foundDocKeys.Count);
  256. Assert.Contains("FooBar21", foundDocKeys);
  257. Assert.Contains("FooBar3", foundDocKeys);
  258. Assert.Contains("FooBar5", foundDocKeys);
  259. Assert.Contains("FooBar6", foundDocKeys);
  260. }
  261. using (var session = documentStore.OpenSession())
  262. {
  263. var fetchedDocuments = session.Advanced.Lazily
  264. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 8, 4, string.Empty, pagingInformation: pagingInformation)
  265. .Value
  266. .ToList();
  267. Assert.Equal(4, pagingInformation.PageSize);
  268. Assert.Equal(8, pagingInformation.Start);
  269. Assert.Equal(8, pagingInformation.NextPageStart);
  270. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  271. Assert.Equal(1, foundDocKeys.Count);
  272. Assert.Contains("FooBar8", foundDocKeys);
  273. }
  274. }
  275. }
  276. [Theory]
  277. [PropertyData("Storages")]
  278. public void PagingWithExcludesWithPagingInformation(string requestedStorage)
  279. {
  280. using (var documentStore = NewDocumentStore(requestedStorage: requestedStorage))
  281. {
  282. using (var session = documentStore.OpenSession())
  283. {
  284. session.Store(new SomeEntity { Id = "FooBar1" });
  285. session.Store(new SomeEntity { Id = "BarFoo2" });
  286. session.Store(new SomeEntity { Id = "FooBar3" });
  287. session.Store(new SomeEntity { Id = "FooBar11" });
  288. session.Store(new SomeEntity { Id = "FooBar12" });
  289. session.Store(new SomeEntity { Id = "FooBar21" });
  290. session.Store(new SomeEntity { Id = "FooBar5" });
  291. session.Store(new SomeEntity { Id = "BarFoo7" });
  292. session.Store(new SomeEntity { Id = "FooBar111" });
  293. session.Store(new SomeEntity { Id = "BarFoo6" });
  294. session.Store(new SomeEntity { Id = "FooBar6" });
  295. session.Store(new SomeEntity { Id = "FooBar8" });
  296. session.SaveChanges();
  297. }
  298. var pagingInformation = new RavenPagingInformation();
  299. using (var session = documentStore.OpenSession())
  300. {
  301. var fetchedDocuments = session.Advanced.Lazily
  302. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 0, 2, pagingInformation: pagingInformation, exclude: "1*")
  303. .Value
  304. .ToList();
  305. Assert.Equal(0, pagingInformation.Start);
  306. Assert.Equal(2, pagingInformation.PageSize);
  307. Assert.Equal(6, pagingInformation.NextPageStart);
  308. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  309. Assert.Equal(2, foundDocKeys.Count);
  310. Assert.Contains("FooBar21", foundDocKeys);
  311. Assert.Contains("FooBar3", foundDocKeys);
  312. }
  313. using (var session = documentStore.OpenSession())
  314. {
  315. var fetchedDocuments = session.Advanced.Lazily
  316. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 2, 2, pagingInformation: pagingInformation, exclude: "1*")
  317. .Value
  318. .ToList();
  319. Assert.Equal(2, pagingInformation.Start);
  320. Assert.Equal(2, pagingInformation.PageSize);
  321. Assert.Equal(8, pagingInformation.NextPageStart);
  322. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  323. Assert.Equal(2, foundDocKeys.Count);
  324. Assert.Contains("FooBar5", foundDocKeys);
  325. Assert.Contains("FooBar6", foundDocKeys);
  326. }
  327. using (var session = documentStore.OpenSession())
  328. {
  329. var fetchedDocuments = session.Advanced.Lazily
  330. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 4, 2, pagingInformation: pagingInformation, exclude: "1*")
  331. .Value
  332. .ToList();
  333. Assert.Equal(4, pagingInformation.Start);
  334. Assert.Equal(2, pagingInformation.PageSize);
  335. Assert.Equal(8, pagingInformation.NextPageStart);
  336. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  337. Assert.Equal(1, foundDocKeys.Count);
  338. Assert.Contains("FooBar8", foundDocKeys);
  339. }
  340. }
  341. }
  342. [Theory]
  343. [PropertyData("Storages")]
  344. public void PagingWithExcludesWithPagingInformation_Remote(string requestedStorage)
  345. {
  346. using (var documentStore = NewRemoteDocumentStore(requestedStorage: requestedStorage))
  347. {
  348. using (var session = documentStore.OpenSession())
  349. {
  350. session.Store(new SomeEntity { Id = "FooBar1" });
  351. session.Store(new SomeEntity { Id = "BarFoo2" });
  352. session.Store(new SomeEntity { Id = "FooBar3" });
  353. session.Store(new SomeEntity { Id = "FooBar11" });
  354. session.Store(new SomeEntity { Id = "FooBar12" });
  355. session.Store(new SomeEntity { Id = "FooBar21" });
  356. session.Store(new SomeEntity { Id = "FooBar5" });
  357. session.Store(new SomeEntity { Id = "BarFoo7" });
  358. session.Store(new SomeEntity { Id = "FooBar111" });
  359. session.Store(new SomeEntity { Id = "BarFoo6" });
  360. session.Store(new SomeEntity { Id = "FooBar6" });
  361. session.Store(new SomeEntity { Id = "FooBar8" });
  362. session.SaveChanges();
  363. }
  364. var pagingInformation = new RavenPagingInformation();
  365. using (var session = documentStore.OpenSession())
  366. {
  367. var fetchedDocuments = session.Advanced.Lazily
  368. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 0, 2, pagingInformation: pagingInformation, exclude: "1*")
  369. .Value
  370. .ToList();
  371. Assert.Equal(0, pagingInformation.Start);
  372. Assert.Equal(2, pagingInformation.PageSize);
  373. Assert.Equal(6, pagingInformation.NextPageStart);
  374. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  375. Assert.Equal(2, foundDocKeys.Count);
  376. Assert.Contains("FooBar21", foundDocKeys);
  377. Assert.Contains("FooBar3", foundDocKeys);
  378. }
  379. using (var session = documentStore.OpenSession())
  380. {
  381. var fetchedDocuments = session.Advanced.Lazily
  382. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 2, 2, pagingInformation: pagingInformation, exclude: "1*")
  383. .Value
  384. .ToList();
  385. Assert.Equal(2, pagingInformation.Start);
  386. Assert.Equal(2, pagingInformation.PageSize);
  387. Assert.Equal(8, pagingInformation.NextPageStart);
  388. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  389. Assert.Equal(2, foundDocKeys.Count);
  390. Assert.Contains("FooBar5", foundDocKeys);
  391. Assert.Contains("FooBar6", foundDocKeys);
  392. }
  393. using (var session = documentStore.OpenSession())
  394. {
  395. var fetchedDocuments = session.Advanced.Lazily
  396. .LoadStartingWith<SomeEntity>("FooBar", string.Empty, 4, 2, pagingInformation: pagingInformation, exclude: "1*")
  397. .Value
  398. .ToList();
  399. Assert.Equal(4, pagingInformation.Start);
  400. Assert.Equal(2, pagingInformation.PageSize);
  401. Assert.Equal(8, pagingInformation.NextPageStart);
  402. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  403. Assert.Equal(1, foundDocKeys.Count);
  404. Assert.Contains("FooBar8", foundDocKeys);
  405. }
  406. }
  407. }
  408. [Theory]
  409. [PropertyData("Storages")]
  410. public void PagingWithMatchesWithPagingInformation(string requestedStorage)
  411. {
  412. using (var documentStore = NewDocumentStore(requestedStorage: requestedStorage))
  413. {
  414. using (var session = documentStore.OpenSession())
  415. {
  416. session.Store(new SomeEntity { Id = "FooBar1" });
  417. session.Store(new SomeEntity { Id = "BarFoo2" });
  418. session.Store(new SomeEntity { Id = "FooBar3" });
  419. session.Store(new SomeEntity { Id = "FooBar11" });
  420. session.Store(new SomeEntity { Id = "FooBar12" });
  421. session.Store(new SomeEntity { Id = "FooBar21" });
  422. session.Store(new SomeEntity { Id = "FooBar5" });
  423. session.Store(new SomeEntity { Id = "BarFoo7" });
  424. session.Store(new SomeEntity { Id = "FooBar111" });
  425. session.Store(new SomeEntity { Id = "BarFoo6" });
  426. session.Store(new SomeEntity { Id = "FooBar6" });
  427. session.Store(new SomeEntity { Id = "FooBar8" });
  428. session.SaveChanges();
  429. }
  430. var pagingInformation = new RavenPagingInformation();
  431. using (var session = documentStore.OpenSession())
  432. {
  433. var fetchedDocuments = session.Advanced.Lazily
  434. .LoadStartingWith<SomeEntity>("FooBar", "1*", 0, 2, pagingInformation: pagingInformation)
  435. .Value
  436. .ToList();
  437. Assert.Equal(0, pagingInformation.Start);
  438. Assert.Equal(2, pagingInformation.PageSize);
  439. Assert.Equal(2, pagingInformation.NextPageStart);
  440. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  441. Assert.Equal(2, foundDocKeys.Count);
  442. Assert.Contains("FooBar1", foundDocKeys);
  443. Assert.Contains("FooBar11", foundDocKeys);
  444. }
  445. using (var session = documentStore.OpenSession())
  446. {
  447. var fetchedDocuments = session.Advanced.Lazily
  448. .LoadStartingWith<SomeEntity>("FooBar", "1*", 2, 1, pagingInformation: pagingInformation)
  449. .Value
  450. .ToList();
  451. Assert.Equal(2, pagingInformation.Start);
  452. Assert.Equal(1, pagingInformation.PageSize);
  453. Assert.Equal(3, pagingInformation.NextPageStart);
  454. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  455. Assert.Equal(1, foundDocKeys.Count);
  456. Assert.Contains("FooBar111", foundDocKeys);
  457. }
  458. using (var session = documentStore.OpenSession())
  459. {
  460. var fetchedDocuments = session.Advanced.Lazily
  461. .LoadStartingWith<SomeEntity>("FooBar", "1*", 3, 10, pagingInformation: pagingInformation)
  462. .Value
  463. .ToList();
  464. Assert.Equal(3, pagingInformation.Start);
  465. Assert.Equal(10, pagingInformation.PageSize);
  466. Assert.Equal(3, pagingInformation.NextPageStart);
  467. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  468. Assert.Equal(1, foundDocKeys.Count);
  469. Assert.Contains("FooBar12", foundDocKeys);
  470. }
  471. }
  472. }
  473. [Theory]
  474. [PropertyData("Storages")]
  475. public void PagingWithMatchesWithPagingInformation_Remote(string requestedStorage)
  476. {
  477. using (var documentStore = NewRemoteDocumentStore(requestedStorage: requestedStorage))
  478. {
  479. using (var session = documentStore.OpenSession())
  480. {
  481. session.Store(new SomeEntity { Id = "FooBar1" });
  482. session.Store(new SomeEntity { Id = "BarFoo2" });
  483. session.Store(new SomeEntity { Id = "FooBar3" });
  484. session.Store(new SomeEntity { Id = "FooBar11" });
  485. session.Store(new SomeEntity { Id = "FooBar12" });
  486. session.Store(new SomeEntity { Id = "FooBar21" });
  487. session.Store(new SomeEntity { Id = "FooBar5" });
  488. session.Store(new SomeEntity { Id = "BarFoo7" });
  489. session.Store(new SomeEntity { Id = "FooBar111" });
  490. session.Store(new SomeEntity { Id = "BarFoo6" });
  491. session.Store(new SomeEntity { Id = "FooBar6" });
  492. session.Store(new SomeEntity { Id = "FooBar8" });
  493. session.SaveChanges();
  494. }
  495. var pagingInformation = new RavenPagingInformation();
  496. using (var session = documentStore.OpenSession())
  497. {
  498. var fetchedDocuments = session.Advanced.Lazily
  499. .LoadStartingWith<SomeEntity>("FooBar", "1*", 0, 2, pagingInformation: pagingInformation)
  500. .Value
  501. .ToList();
  502. Assert.Equal(0, pagingInformation.Start);
  503. Assert.Equal(2, pagingInformation.PageSize);
  504. Assert.Equal(2, pagingInformation.NextPageStart);
  505. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  506. Assert.Equal(2, foundDocKeys.Count);
  507. Assert.Contains("FooBar1", foundDocKeys);
  508. Assert.Contains("FooBar11", foundDocKeys);
  509. }
  510. using (var session = documentStore.OpenSession())
  511. {
  512. var fetchedDocuments = session.Advanced.Lazily
  513. .LoadStartingWith<SomeEntity>("FooBar", "1*", 2, 1, pagingInformation: pagingInformation)
  514. .Value
  515. .ToList();
  516. Assert.Equal(2, pagingInformation.Start);
  517. Assert.Equal(1, pagingInformation.PageSize);
  518. Assert.Equal(3, pagingInformation.NextPageStart);
  519. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  520. Assert.Equal(1, foundDocKeys.Count);
  521. Assert.Contains("FooBar111", foundDocKeys);
  522. }
  523. using (var session = documentStore.OpenSession())
  524. {
  525. var fetchedDocuments = session.Advanced.Lazily
  526. .LoadStartingWith<SomeEntity>("FooBar", "1*", 3, 10, pagingInformation: pagingInformation)
  527. .Value
  528. .ToList();
  529. Assert.Equal(3, pagingInformation.Start);
  530. Assert.Equal(10, pagingInformation.PageSize);
  531. Assert.Equal(3, pagingInformation.NextPageStart);
  532. var foundDocKeys = fetchedDocuments.Select(doc => doc.Id).ToList();
  533. Assert.Equal(1, foundDocKeys.Count);
  534. Assert.Contains("FooBar12", foundDocKeys);
  535. }
  536. }
  537. }
  538. }
  539. }