Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

LuEfUpdateDataAccessTest.cs 29KB

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