You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LuEfCreateDataAccessTest.cs 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using Luticate2.Utils.Dbo;
  6. using Microsoft.AspNetCore.Mvc.Controllers;
  7. using Test.Utils.DataAccess;
  8. using Test.Utils.Dbo.PkBigSerial;
  9. using Test.Utils.Dbo.PkGuid;
  10. using Xunit;
  11. namespace Test.Utils.EfCrubDataAccess
  12. {
  13. public class LuEfCreateDataAccessTest
  14. {
  15. [Fact]
  16. public void TestAddMultiple1()
  17. {
  18. Tests.TestRealDb(context =>
  19. {
  20. var dbos = new List<PkBigSerialAddDbo>
  21. {
  22. new PkBigSerialAddDbo
  23. {
  24. SomeInt = 42,
  25. SomeText = "42"
  26. },
  27. new PkBigSerialAddDbo
  28. {
  29. SomeInt = 21,
  30. SomeText = "24"
  31. }
  32. };
  33. var service = new LuUtilsPkBigSerialDataAccess(context);
  34. var res = service.Add(dbos, enumerable => enumerable);
  35. Assert.Equal(LuStatus.Success, res.Status);
  36. foreach (var dbo in dbos.Zip(res.Data, (dbo, serialDbo) => new KeyValuePair<PkBigSerialAddDbo, PkBigSerialDbo>(dbo, serialDbo)))
  37. {
  38. Assert.NotNull(dbo.Key);
  39. Assert.NotNull(dbo.Value);
  40. Assert.NotEqual(0, dbo.Value.Id);
  41. Assert.Equal(dbo.Key.SomeText, dbo.Value.SomeText);
  42. Assert.Equal(dbo.Key.SomeInt, dbo.Value.SomeInt);
  43. var get = service.GetSingleById(dbo.Value.Id);
  44. Assert.Equal(LuStatus.Success, get.Status);
  45. Assert.Equal(dbo.Key.SomeText, get.Data.SomeText);
  46. Assert.Equal(dbo.Key.SomeInt, get.Data.SomeInt);
  47. Assert.Equal(dbo.Value.Id, get.Data.Id);
  48. }
  49. });
  50. }
  51. [Fact]
  52. public void TestAddMultiple2()
  53. {
  54. Tests.TestRealDb(context =>
  55. {
  56. var dbos = new List<PkBigSerialAddDbo>
  57. {
  58. new PkBigSerialAddDbo
  59. {
  60. SomeInt = 42,
  61. SomeText = "42"
  62. },
  63. new PkBigSerialAddDbo
  64. {
  65. SomeInt = 21,
  66. SomeText = "24"
  67. }
  68. };
  69. var service = new LuUtilsPkBigSerialDataAccess(context);
  70. var res = service.Add(dbos, enumerable => enumerable.Select(dbo => dbo.Id));
  71. Assert.Equal(LuStatus.Success, res.Status);
  72. foreach (var dbo in dbos.Zip(res.Data, (dbo, serialDbo) => new KeyValuePair<PkBigSerialAddDbo, long>(dbo, serialDbo)))
  73. {
  74. Assert.NotNull(dbo.Key);
  75. Assert.NotNull(dbo.Value);
  76. Assert.NotEqual(0, dbo.Value);
  77. var get = service.GetSingleById(dbo.Value);
  78. Assert.Equal(LuStatus.Success, get.Status);
  79. Assert.Equal(dbo.Key.SomeText, get.Data.SomeText);
  80. Assert.Equal(dbo.Key.SomeInt, get.Data.SomeInt);
  81. Assert.Equal(dbo.Value, get.Data.Id);
  82. }
  83. });
  84. }
  85. [Fact]
  86. public void TestAddMultiple3()
  87. {
  88. Tests.TestRealDb(context =>
  89. {
  90. var dbos = new List<PkBigSerialAddDbo>
  91. {
  92. new PkBigSerialAddDbo
  93. {
  94. SomeInt = 42,
  95. SomeText = "42"
  96. },
  97. new PkBigSerialAddDbo
  98. {
  99. SomeInt = 21,
  100. SomeText = "24"
  101. }
  102. };
  103. var service = new LuUtilsPkBigSerialDataAccess(context);
  104. var res = service.Add(dbos, enumerable => enumerable.Select(dbo => dbo.CreatedAt));
  105. Assert.Equal(LuStatus.Success, res.Status);
  106. foreach (var dbo in res.Data)
  107. {
  108. Assert.NotEqual(default(DateTime), dbo);
  109. }
  110. });
  111. }
  112. [Fact]
  113. public void TestAddMultiple4()
  114. {
  115. Tests.TestRealDb(context =>
  116. {
  117. var dbos = new List<PkBigSerialAddDbo>
  118. {
  119. new PkBigSerialAddDbo
  120. {
  121. SomeInt = 42,
  122. SomeText = "42"
  123. },
  124. new PkBigSerialAddDbo
  125. {
  126. SomeInt = 21,
  127. SomeText = "42"
  128. }
  129. };
  130. var service = new LuUtilsPkBigSerialDataAccess(context);
  131. var res = service.Add(dbos, enumerable => enumerable.Select(dbo => dbo.CreatedAt));
  132. Assert.Equal(LuStatus.DbError, res.Status);
  133. });
  134. }
  135. [Fact]
  136. public void TestAddSingle1()
  137. {
  138. Tests.TestRealDb(context =>
  139. {
  140. var service = new LuUtilsPkBigSerialDataAccess(context);
  141. var res = service.Add(new PkBigSerialAddDbo
  142. {
  143. SomeInt = 42,
  144. SomeText = "42"
  145. }, dbo => dbo);
  146. Assert.Equal(LuStatus.Success, res.Status);
  147. Assert.NotEqual(0, res.Data.Id);
  148. Assert.Equal("42", res.Data.SomeText);
  149. Assert.Equal(42, res.Data.SomeInt);
  150. var get = service.GetSingleById(res.Data.Id);
  151. Assert.Equal(LuStatus.Success, get.Status);
  152. Assert.Equal("42", get.Data.SomeText);
  153. Assert.Equal(42, get.Data.SomeInt);
  154. Assert.Equal(res.Data.Id, get.Data.Id);
  155. });
  156. }
  157. [Fact]
  158. public void TestAddSingle2()
  159. {
  160. Tests.TestRealDb(context =>
  161. {
  162. var service = new LuUtilsPkBigSerialDataAccess(context);
  163. var res = service.Add(new PkBigSerialAddDbo
  164. {
  165. SomeInt = 42,
  166. SomeText = "42"
  167. }, dbo => dbo.Id);
  168. Assert.Equal(LuStatus.Success, res.Status);
  169. Assert.NotEqual(0, res.Data);
  170. var get = service.GetSingleById(res.Data);
  171. Assert.Equal(LuStatus.Success, get.Status);
  172. Assert.Equal("42", get.Data.SomeText);
  173. Assert.Equal(42, get.Data.SomeInt);
  174. Assert.Equal(res.Data, get.Data.Id);
  175. });
  176. }
  177. [Fact]
  178. public void TestAddSingle3()
  179. {
  180. Tests.TestRealDb(context =>
  181. {
  182. var service = new LuUtilsPkBigSerialDataAccess(context);
  183. var res = service.Add(new PkBigSerialAddDbo
  184. {
  185. SomeInt = 42,
  186. SomeText = "42"
  187. }, dbo => dbo.CreatedAt);
  188. Assert.Equal(LuStatus.Success, res.Status);
  189. Assert.NotEqual(default(DateTime), res.Data);
  190. });
  191. }
  192. [Fact]
  193. public void TestAddGuidMultiple1()
  194. {
  195. Tests.TestRealDb(context =>
  196. {
  197. var dbos = new List<PkGuidAddDbo>
  198. {
  199. new PkGuidAddDbo
  200. {
  201. SomeInt = 42,
  202. SomeText = "42"
  203. },
  204. new PkGuidAddDbo
  205. {
  206. SomeInt = 21,
  207. SomeText = "24"
  208. }
  209. };
  210. var service = new LuUtilsPkGuidDataAccess(context);
  211. var res = service.AddGuid(dbos);
  212. Assert.Equal(LuStatus.Success, res.Status);
  213. foreach (var dbo in dbos.Zip(res.Data, (dbo, serialDbo) => new KeyValuePair<PkGuidAddDbo, string>(dbo, serialDbo)))
  214. {
  215. Assert.NotNull(dbo.Key);
  216. Assert.NotNull(dbo.Value);
  217. Assert.NotEqual(new Guid().ToString(), dbo.Value);
  218. var get = service.GetSingleById(dbo.Value);
  219. Assert.Equal(LuStatus.Success, get.Status);
  220. Assert.Equal(dbo.Key.SomeText, get.Data.SomeText);
  221. Assert.Equal(dbo.Key.SomeInt, get.Data.SomeInt);
  222. Assert.Equal(dbo.Value, get.Data.Id);
  223. }
  224. });
  225. }
  226. [Fact]
  227. public void TestAddGuidSingle1()
  228. {
  229. Tests.TestRealDb(context =>
  230. {
  231. var service = new LuUtilsPkGuidDataAccess(context);
  232. var res = service.AddGuid(new PkGuidAddDbo
  233. {
  234. SomeInt = 42,
  235. SomeText = "42"
  236. });
  237. Assert.Equal(LuStatus.Success, res.Status);
  238. Assert.NotEqual(new Guid().ToString(), res.Data);
  239. var get = service.GetSingleById(res.Data);
  240. Assert.Equal(LuStatus.Success, get.Status);
  241. Assert.Equal("42", get.Data.SomeText);
  242. Assert.Equal(42, get.Data.SomeInt);
  243. Assert.Equal(res.Data, get.Data.Id);
  244. });
  245. }
  246. [Fact]
  247. public void TestAddIdMultiple1()
  248. {
  249. Tests.TestRealDb(context =>
  250. {
  251. var dbos = new List<PkBigSerialAddDbo>
  252. {
  253. new PkBigSerialAddDbo
  254. {
  255. SomeInt = 42,
  256. SomeText = "42"
  257. },
  258. new PkBigSerialAddDbo
  259. {
  260. SomeInt = 21,
  261. SomeText = "24"
  262. }
  263. };
  264. var service = new LuUtilsPkBigSerialDataAccess(context);
  265. var res = service.AddId(dbos);
  266. Assert.Equal(LuStatus.Success, res.Status);
  267. foreach (var dbo in dbos.Zip(res.Data, (dbo, serialDbo) => new KeyValuePair<PkBigSerialAddDbo, long>(dbo, serialDbo)))
  268. {
  269. Assert.NotNull(dbo.Key);
  270. Assert.NotNull(dbo.Value);
  271. Assert.NotEqual(0, dbo.Value);
  272. var get = service.GetSingleById(dbo.Value);
  273. Assert.Equal(LuStatus.Success, get.Status);
  274. Assert.Equal(dbo.Key.SomeText, get.Data.SomeText);
  275. Assert.Equal(dbo.Key.SomeInt, get.Data.SomeInt);
  276. Assert.Equal(dbo.Value, get.Data.Id);
  277. }
  278. });
  279. }
  280. [Fact]
  281. public void TestAddIdSingle1()
  282. {
  283. Tests.TestRealDb(context =>
  284. {
  285. var service = new LuUtilsPkBigSerialDataAccess(context);
  286. var res = service.AddId(new PkBigSerialAddDbo
  287. {
  288. SomeInt = 42,
  289. SomeText = "42"
  290. });
  291. Assert.Equal(LuStatus.Success, res.Status);
  292. Assert.NotEqual(0, res.Data);
  293. var get = service.GetSingleById(res.Data);
  294. Assert.Equal(LuStatus.Success, get.Status);
  295. Assert.Equal("42", get.Data.SomeText);
  296. Assert.Equal(42, get.Data.SomeInt);
  297. Assert.Equal(res.Data, get.Data.Id);
  298. });
  299. }
  300. [Fact]
  301. public void TestAddDboMultiple1()
  302. {
  303. Tests.TestRealDb(context =>
  304. {
  305. var dbos = new List<PkBigSerialAddDbo>
  306. {
  307. new PkBigSerialAddDbo
  308. {
  309. SomeInt = 42,
  310. SomeText = "42"
  311. },
  312. new PkBigSerialAddDbo
  313. {
  314. SomeInt = 21,
  315. SomeText = "24"
  316. }
  317. };
  318. var service = new LuUtilsPkBigSerialDataAccess(context);
  319. var res = service.AddDbo(dbos);
  320. Assert.Equal(LuStatus.Success, res.Status);
  321. foreach (var dbo in dbos.Zip(res.Data, (dbo, serialDbo) => new KeyValuePair<PkBigSerialAddDbo, PkBigSerialDbo>(dbo, serialDbo)))
  322. {
  323. Assert.NotNull(dbo.Key);
  324. Assert.NotNull(dbo.Value);
  325. Assert.NotEqual(0, dbo.Value.Id);
  326. var get = service.GetSingleById(dbo.Value.Id);
  327. Assert.Equal(LuStatus.Success, get.Status);
  328. Assert.Equal(dbo.Key.SomeText, get.Data.SomeText);
  329. Assert.Equal(dbo.Key.SomeInt, get.Data.SomeInt);
  330. Assert.Equal(dbo.Value.Id, get.Data.Id);
  331. }
  332. });
  333. }
  334. [Fact]
  335. public void TestAddDboSingle1()
  336. {
  337. Tests.TestRealDb(context =>
  338. {
  339. var service = new LuUtilsPkBigSerialDataAccess(context);
  340. var res = service.AddDbo(new PkBigSerialAddDbo
  341. {
  342. SomeInt = 42,
  343. SomeText = "42"
  344. });
  345. Assert.Equal(LuStatus.Success, res.Status);
  346. Assert.NotEqual(0, res.Data.Id);
  347. var get = service.GetSingleById(res.Data.Id);
  348. Assert.Equal(LuStatus.Success, get.Status);
  349. Assert.Equal("42", get.Data.SomeText);
  350. Assert.Equal(42, get.Data.SomeInt);
  351. Assert.Equal(res.Data.Id, get.Data.Id);
  352. });
  353. }
  354. [Fact]
  355. public void TestGetSingle1()
  356. {
  357. Tests.TestRealDb(context =>
  358. {
  359. var service = new LuUtilsPkBigSerialDataAccess(context);
  360. var res = service.AddDbo(new PkBigSerialAddDbo
  361. {
  362. SomeInt = 42,
  363. SomeText = "42"
  364. });
  365. Assert.Equal(LuStatus.Success, res.Status);
  366. Assert.NotEqual(0, res.Data.Id);
  367. var get = service.GetSingle(bigserial => bigserial.some_int == 42);
  368. Assert.Equal(LuStatus.Success, get.Status);
  369. Assert.Equal("42", get.Data.SomeText);
  370. Assert.Equal(42, get.Data.SomeInt);
  371. Assert.Equal(res.Data.Id, get.Data.Id);
  372. });
  373. }
  374. [Fact]
  375. public void TestGetSingle2()
  376. {
  377. Tests.TestRealDb(context =>
  378. {
  379. var service = new LuUtilsPkBigSerialDataAccess(context);
  380. var res = service.AddDbo(new PkBigSerialAddDbo
  381. {
  382. SomeInt = 42,
  383. SomeText = "42"
  384. });
  385. Assert.Equal(LuStatus.Success, res.Status);
  386. Assert.NotEqual(0, res.Data.Id);
  387. var get = service.GetSingle(bigserial => bigserial.some_int == 24);
  388. Assert.Equal(LuStatus.NotFound, get.Status);
  389. });
  390. }
  391. [Fact]
  392. public void TestGetSingleByKeys1()
  393. {
  394. Tests.TestRealDb(context =>
  395. {
  396. var service = new LuUtilsPkBigSerialDataAccess(context);
  397. var res = service.AddDbo(new PkBigSerialAddDbo
  398. {
  399. SomeInt = 42,
  400. SomeText = "42"
  401. });
  402. Assert.Equal(LuStatus.Success, res.Status);
  403. Assert.NotEqual(0, res.Data.Id);
  404. var get = service.GetSingleByKeys(new KeyValuePair<string, object>("some_text", "42"));
  405. Assert.Equal(LuStatus.Success, get.Status);
  406. Assert.Equal("42", get.Data.SomeText);
  407. Assert.Equal(42, get.Data.SomeInt);
  408. Assert.Equal(res.Data.Id, get.Data.Id);
  409. });
  410. }
  411. [Fact]
  412. public void TestGetSingleByKeys2()
  413. {
  414. Tests.TestRealDb(context =>
  415. {
  416. var service = new LuUtilsPkBigSerialDataAccess(context);
  417. var res = service.AddDbo(new PkBigSerialAddDbo
  418. {
  419. SomeInt = 42,
  420. SomeText = "42"
  421. });
  422. Assert.Equal(LuStatus.Success, res.Status);
  423. Assert.NotEqual(0, res.Data.Id);
  424. var get = service.GetSingleByKeys(new KeyValuePair<string, object>("some_text", "24"));
  425. Assert.Equal(LuStatus.NotFound, get.Status);
  426. });
  427. }
  428. [Fact]
  429. public void TestGetSingleById1()
  430. {
  431. Tests.TestRealDb(context =>
  432. {
  433. var service = new LuUtilsPkBigSerialDataAccess(context);
  434. var res = service.AddId(new PkBigSerialAddDbo
  435. {
  436. SomeInt = 42,
  437. SomeText = "42"
  438. });
  439. Assert.Equal(LuStatus.Success, res.Status);
  440. Assert.NotEqual(0, res.Data);
  441. var get = service.GetSingleById(res.Data);
  442. Assert.Equal(LuStatus.Success, get.Status);
  443. Assert.Equal("42", get.Data.SomeText);
  444. Assert.Equal(42, get.Data.SomeInt);
  445. Assert.Equal(res.Data, get.Data.Id);
  446. });
  447. }
  448. [Fact]
  449. public void TestGetSingleById2()
  450. {
  451. Tests.TestRealDb(context =>
  452. {
  453. var service = new LuUtilsPkBigSerialDataAccess(context);
  454. var res = service.AddId(new PkBigSerialAddDbo
  455. {
  456. SomeInt = 42,
  457. SomeText = "42"
  458. });
  459. Assert.Equal(LuStatus.Success, res.Status);
  460. Assert.NotEqual(0, res.Data);
  461. var get = service.GetSingle(bigserial => bigserial.some_int == 24);
  462. Assert.Equal(LuStatus.NotFound, get.Status);
  463. });
  464. }
  465. [Fact]
  466. public void TestGetSingleById3()
  467. {
  468. Tests.TestRealDb(context =>
  469. {
  470. var service = new LuUtilsPkGuidDataAccess(context);
  471. var res = service.AddGuid(new PkGuidAddDbo
  472. {
  473. SomeInt = 42,
  474. SomeText = "42"
  475. });
  476. Assert.Equal(LuStatus.Success, res.Status);
  477. Assert.NotEqual(new Guid().ToString(), res.Data);
  478. var get = service.GetSingleById(res.Data);
  479. Assert.Equal(LuStatus.Success, get.Status);
  480. Assert.Equal("42", get.Data.SomeText);
  481. Assert.Equal(42, get.Data.SomeInt);
  482. Assert.Equal(res.Data, get.Data.Id);
  483. });
  484. }
  485. [Fact]
  486. public void TestGetSingleById4()
  487. {
  488. Tests.TestRealDb(context =>
  489. {
  490. var service = new LuUtilsPkGuidDataAccess(context);
  491. var res = service.AddGuid(new PkGuidAddDbo
  492. {
  493. SomeInt = 42,
  494. SomeText = "42"
  495. });
  496. Assert.Equal(LuStatus.Success, res.Status);
  497. Assert.NotEqual(new Guid().ToString(), res.Data);
  498. var get = service.GetSingle(bigserial => bigserial.some_int == 24);
  499. Assert.Equal(LuStatus.NotFound, get.Status);
  500. });
  501. }
  502. [Fact]
  503. public void TestGetMultiple1()
  504. {
  505. Tests.TestRealDb(context =>
  506. {
  507. var dbos = new List<PkGuidAddDbo>
  508. {
  509. new PkGuidAddDbo
  510. {
  511. SomeInt = 42,
  512. SomeText = "442"
  513. },
  514. new PkGuidAddDbo
  515. {
  516. SomeInt = 42,
  517. SomeText = "42"
  518. },
  519. new PkGuidAddDbo
  520. {
  521. SomeInt = 24,
  522. SomeText = "24"
  523. }
  524. };
  525. var service = new LuUtilsPkGuidDataAccess(context);
  526. var res = service.AddGuid(dbos);
  527. Assert.Equal(LuStatus.Success, res.Status);
  528. var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int),
  529. guid => guid.some_int == 42, 0, int.MaxValue, set => set.OrderBy(guid => guid.some_text));
  530. Assert.Equal(LuStatus.Success, get.Status);
  531. Assert.Equal(2, get.Data.Count);
  532. Assert.Equal(2, get.Data.Data.Count);
  533. var dbo = get.Data.Data[0];
  534. Assert.Equal(42, dbo.SomeInt);
  535. Assert.Equal("42", dbo.SomeText);
  536. dbo = get.Data.Data[1];
  537. Assert.Equal(42, dbo.SomeInt);
  538. Assert.Equal("442", dbo.SomeText);
  539. });
  540. }
  541. [Fact]
  542. public void TestGetMultiple2()
  543. {
  544. Tests.TestRealDb(context =>
  545. {
  546. var dbos = new List<PkGuidAddDbo>
  547. {
  548. new PkGuidAddDbo
  549. {
  550. SomeInt = 42,
  551. SomeText = "442"
  552. },
  553. new PkGuidAddDbo
  554. {
  555. SomeInt = 42,
  556. SomeText = "42"
  557. },
  558. new PkGuidAddDbo
  559. {
  560. SomeInt = 24,
  561. SomeText = "24"
  562. }
  563. };
  564. var service = new LuUtilsPkGuidDataAccess(context);
  565. var res = service.AddGuid(dbos);
  566. Assert.Equal(LuStatus.Success, res.Status);
  567. var get = service.GetMultiple(guid => guid.some_int, guid => guid.some_int == 42, 0, int.MaxValue,
  568. guid => guid.some_text);
  569. Assert.Equal(LuStatus.Success, get.Status);
  570. Assert.Equal(2, get.Data.Count);
  571. Assert.Equal(2, get.Data.Data.Count);
  572. var dbo = get.Data.Data[0];
  573. Assert.Equal(42, dbo.SomeInt);
  574. Assert.Equal("42", dbo.SomeText);
  575. dbo = get.Data.Data[1];
  576. Assert.Equal(42, dbo.SomeInt);
  577. Assert.Equal("442", dbo.SomeText);
  578. });
  579. }
  580. [Fact]
  581. public void TestGetMultiple3()
  582. {
  583. Tests.TestRealDb(context =>
  584. {
  585. var dbos = new List<PkGuidAddDbo>
  586. {
  587. new PkGuidAddDbo
  588. {
  589. SomeInt = 42,
  590. SomeText = "442"
  591. },
  592. new PkGuidAddDbo
  593. {
  594. SomeInt = 42,
  595. SomeText = "42"
  596. },
  597. new PkGuidAddDbo
  598. {
  599. SomeInt = 24,
  600. SomeText = "24"
  601. }
  602. };
  603. var service = new LuUtilsPkGuidDataAccess(context);
  604. var res = service.AddGuid(dbos);
  605. Assert.Equal(LuStatus.Success, res.Status);
  606. var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int), 0, int.MaxValue,
  607. set => set.OrderBy(guid => guid.some_text));
  608. Assert.Equal(LuStatus.Success, get.Status);
  609. Assert.Equal(3, get.Data.Count);
  610. Assert.Equal(3, get.Data.Data.Count);
  611. var dbo = get.Data.Data[0];
  612. Assert.Equal(24, dbo.SomeInt);
  613. Assert.Equal("24", dbo.SomeText);
  614. dbo = get.Data.Data[1];
  615. Assert.Equal(42, dbo.SomeInt);
  616. Assert.Equal("42", dbo.SomeText);
  617. dbo = get.Data.Data[2];
  618. Assert.Equal(42, dbo.SomeInt);
  619. Assert.Equal("442", dbo.SomeText);
  620. });
  621. }
  622. [Fact]
  623. public void TestGetMultiple4()
  624. {
  625. Tests.TestRealDb(context =>
  626. {
  627. var dbos = new List<PkGuidAddDbo>
  628. {
  629. new PkGuidAddDbo
  630. {
  631. SomeInt = 42,
  632. SomeText = "442"
  633. },
  634. new PkGuidAddDbo
  635. {
  636. SomeInt = 42,
  637. SomeText = "42"
  638. },
  639. new PkGuidAddDbo
  640. {
  641. SomeInt = 24,
  642. SomeText = "24"
  643. }
  644. };
  645. var service = new LuUtilsPkGuidDataAccess(context);
  646. var res = service.AddGuid(dbos);
  647. Assert.Equal(LuStatus.Success, res.Status);
  648. var get = service.GetMultiple(guid => guid.some_int, 0, int.MaxValue, guid => guid.some_text);
  649. Assert.Equal(LuStatus.Success, get.Status);
  650. Assert.Equal(3, get.Data.Count);
  651. Assert.Equal(3, get.Data.Data.Count);
  652. var dbo = get.Data.Data[0];
  653. Assert.Equal(24, dbo.SomeInt);
  654. Assert.Equal("24", dbo.SomeText);
  655. dbo = get.Data.Data[1];
  656. Assert.Equal(42, dbo.SomeInt);
  657. Assert.Equal("42", dbo.SomeText);
  658. dbo = get.Data.Data[2];
  659. Assert.Equal(42, dbo.SomeInt);
  660. Assert.Equal("442", dbo.SomeText);
  661. });
  662. }
  663. }
  664. }