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.

LuEfDeleteDataAccessTest.cs 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Luticate2.Utils.Dbo;
  5. using Luticate2.Utils.Dbo.Result;
  6. using Test.Utils.DataAccess;
  7. using Test.Utils.Dbo.PkBigSerial;
  8. using Test.Utils.Dbo.PkGuid;
  9. using Xunit;
  10. namespace Test.Utils.EfCrubDataAccess
  11. {
  12. public class LuEfDeleteDataAccessTest
  13. {
  14. [Fact]
  15. public void TestDeleteMultiple1()
  16. {
  17. Tests.TestRealDb(context =>
  18. {
  19. var dbos = new List<PkGuidAddDbo>
  20. {
  21. new PkGuidAddDbo
  22. {
  23. SomeInt = 42,
  24. SomeText = "442"
  25. },
  26. new PkGuidAddDbo
  27. {
  28. SomeInt = 42,
  29. SomeText = "42"
  30. },
  31. new PkGuidAddDbo
  32. {
  33. SomeInt = 24,
  34. SomeText = "24"
  35. }
  36. };
  37. var service = new LuUtilsPkGuidDataAccess(context);
  38. var res = service.AddGuid(dbos);
  39. Assert.Equal(LuStatus.Success, res.Status);
  40. var edit = service.Delete(guid => guid.some_int == 42, enumerable => enumerable);
  41. Assert.Equal(LuStatus.Success, edit.Status);
  42. var elements = edit.Data.ToList();
  43. Assert.Equal(2, elements.Count);
  44. var e = elements[0];
  45. Assert.Equal(42, e.SomeInt);
  46. Assert.Equal("442", e.SomeText);
  47. e = elements[1];
  48. Assert.Equal(42, e.SomeInt);
  49. Assert.Equal("42", e.SomeText);
  50. var get = service.GetMultiple(guid => guid.some_text);
  51. Assert.Equal(LuStatus.Success, get.Status);
  52. Assert.Equal(1, get.Data.Count);
  53. Assert.Equal(1, get.Data.Data.Count);
  54. var dbo = get.Data.Data[0];
  55. Assert.Equal(24, dbo.SomeInt);
  56. Assert.Equal("24", dbo.SomeText);
  57. });
  58. }
  59. [Fact]
  60. public void TestDeleteMultiple2()
  61. {
  62. Tests.TestRealDb(context =>
  63. {
  64. var dbos = new List<PkGuidAddDbo>
  65. {
  66. new PkGuidAddDbo
  67. {
  68. SomeInt = 42,
  69. SomeText = "442"
  70. },
  71. new PkGuidAddDbo
  72. {
  73. SomeInt = 42,
  74. SomeText = "42"
  75. },
  76. new PkGuidAddDbo
  77. {
  78. SomeInt = 24,
  79. SomeText = "24"
  80. }
  81. };
  82. var service = new LuUtilsPkGuidDataAccess(context);
  83. var res = service.AddGuid(dbos);
  84. Assert.Equal(LuStatus.Success, res.Status);
  85. var edit = service.Delete(guid => guid.some_int == 42, enumerable => enumerable.Select(guidDbo => guidDbo.Id));
  86. Assert.Equal(LuStatus.Success, edit.Status);
  87. var elements = edit.Data.ToList();
  88. Assert.Equal(2, elements.Count);
  89. var get = service.GetMultiple(guid => guid.some_text);
  90. Assert.Equal(LuStatus.Success, get.Status);
  91. Assert.Equal(1, get.Data.Count);
  92. Assert.Equal(1, get.Data.Data.Count);
  93. var dbo = get.Data.Data[0];
  94. Assert.Equal(24, dbo.SomeInt);
  95. Assert.Equal("24", dbo.SomeText);
  96. });
  97. }
  98. [Fact]
  99. public void TestDeleteMultiple3()
  100. {
  101. Tests.TestRealDb(context =>
  102. {
  103. var dbos = new List<PkGuidAddDbo>
  104. {
  105. new PkGuidAddDbo
  106. {
  107. SomeInt = 42,
  108. SomeText = "442"
  109. },
  110. new PkGuidAddDbo
  111. {
  112. SomeInt = 42,
  113. SomeText = "42"
  114. },
  115. new PkGuidAddDbo
  116. {
  117. SomeInt = 24,
  118. SomeText = "24"
  119. }
  120. };
  121. var service = new LuUtilsPkGuidDataAccess(context);
  122. var res = service.AddGuid(dbos);
  123. Assert.Equal(LuStatus.Success, res.Status);
  124. var edit = service.DeleteGuid(guid => guid.some_int == 42);
  125. Assert.Equal(LuStatus.Success, edit.Status);
  126. var elements = edit.Data.ToList();
  127. Assert.Equal(2, elements.Count);
  128. var get = service.GetMultiple(guid => guid.some_text);
  129. Assert.Equal(LuStatus.Success, get.Status);
  130. Assert.Equal(1, get.Data.Count);
  131. Assert.Equal(1, get.Data.Data.Count);
  132. var dbo = get.Data.Data[0];
  133. Assert.Equal(24, dbo.SomeInt);
  134. Assert.Equal("24", dbo.SomeText);
  135. });
  136. }
  137. [Fact]
  138. public void TestDeleteMultiple4()
  139. {
  140. Tests.TestRealDb(context =>
  141. {
  142. var dbos = new List<PkBigSerialAddDbo>
  143. {
  144. new PkBigSerialAddDbo
  145. {
  146. SomeInt = 42,
  147. SomeText = "442"
  148. },
  149. new PkBigSerialAddDbo
  150. {
  151. SomeInt = 42,
  152. SomeText = "42"
  153. },
  154. new PkBigSerialAddDbo
  155. {
  156. SomeInt = 24,
  157. SomeText = "24"
  158. }
  159. };
  160. var service = new LuUtilsPkBigSerialDataAccess(context);
  161. var res = service.AddId(dbos);
  162. Assert.Equal(LuStatus.Success, res.Status);
  163. var edit = service.DeleteId(guid => guid.some_int == 42);
  164. Assert.Equal(LuStatus.Success, edit.Status);
  165. var elements = edit.Data.ToList();
  166. Assert.Equal(2, elements.Count);
  167. var get = service.GetMultiple(guid => guid.some_text);
  168. Assert.Equal(LuStatus.Success, get.Status);
  169. Assert.Equal(1, get.Data.Count);
  170. Assert.Equal(1, get.Data.Data.Count);
  171. var dbo = get.Data.Data[0];
  172. Assert.Equal(24, dbo.SomeInt);
  173. Assert.Equal("24", dbo.SomeText);
  174. });
  175. }
  176. [Fact]
  177. public void TestDeleteMultiple5()
  178. {
  179. Tests.TestRealDb(context =>
  180. {
  181. var dbos = new List<PkGuidAddDbo>
  182. {
  183. new PkGuidAddDbo
  184. {
  185. SomeInt = 42,
  186. SomeText = "442"
  187. },
  188. new PkGuidAddDbo
  189. {
  190. SomeInt = 42,
  191. SomeText = "42"
  192. },
  193. new PkGuidAddDbo
  194. {
  195. SomeInt = 24,
  196. SomeText = "24"
  197. }
  198. };
  199. var service = new LuUtilsPkGuidDataAccess(context);
  200. var res = service.AddGuid(dbos);
  201. Assert.Equal(LuStatus.Success, res.Status);
  202. var edit = service.DeleteDbo(guid => guid.some_int == 42);
  203. Assert.Equal(LuStatus.Success, edit.Status);
  204. var elements = edit.Data.ToList();
  205. Assert.Equal(2, elements.Count);
  206. var e = elements[0];
  207. Assert.Equal(42, e.SomeInt);
  208. Assert.Equal("442", e.SomeText);
  209. e = elements[1];
  210. Assert.Equal(42, e.SomeInt);
  211. Assert.Equal("42", e.SomeText);
  212. var get = service.GetMultiple(guid => guid.some_text);
  213. Assert.Equal(LuStatus.Success, get.Status);
  214. Assert.Equal(1, get.Data.Count);
  215. Assert.Equal(1, get.Data.Data.Count);
  216. var dbo = get.Data.Data[0];
  217. Assert.Equal(24, dbo.SomeInt);
  218. Assert.Equal("24", dbo.SomeText);
  219. });
  220. }
  221. [Fact]
  222. public void TestDeleteSingle1()
  223. {
  224. Tests.TestRealDb(context =>
  225. {
  226. var dbos = new List<PkGuidAddDbo>
  227. {
  228. new PkGuidAddDbo
  229. {
  230. SomeInt = 42,
  231. SomeText = "442"
  232. },
  233. new PkGuidAddDbo
  234. {
  235. SomeInt = 42,
  236. SomeText = "42"
  237. },
  238. new PkGuidAddDbo
  239. {
  240. SomeInt = 24,
  241. SomeText = "24"
  242. }
  243. };
  244. var service = new LuUtilsPkGuidDataAccess(context);
  245. var res = service.AddGuid(dbos);
  246. Assert.Equal(LuStatus.Success, res.Status);
  247. var ids = res.Data.ToList();
  248. var edit = service.DeleteSingleById(ids[0], guidDbo => guidDbo);
  249. Assert.Equal(LuStatus.Success, edit.Status);
  250. Assert.Equal(42, edit.Data.SomeInt);
  251. Assert.Equal("442", edit.Data.SomeText);
  252. var get = service.GetMultiple(guid => guid.some_text);
  253. Assert.Equal(LuStatus.Success, get.Status);
  254. Assert.Equal(2, get.Data.Count);
  255. Assert.Equal(2, get.Data.Data.Count);
  256. var dbo = get.Data.Data[0];
  257. Assert.Equal(24, dbo.SomeInt);
  258. Assert.Equal("24", dbo.SomeText);
  259. dbo = get.Data.Data[1];
  260. Assert.Equal(42, dbo.SomeInt);
  261. Assert.Equal("42", dbo.SomeText);
  262. });
  263. }
  264. [Fact]
  265. public void TestDeleteSingle2()
  266. {
  267. Tests.TestRealDb(context =>
  268. {
  269. var dbos = new List<PkGuidAddDbo>
  270. {
  271. new PkGuidAddDbo
  272. {
  273. SomeInt = 42,
  274. SomeText = "442"
  275. },
  276. new PkGuidAddDbo
  277. {
  278. SomeInt = 42,
  279. SomeText = "42"
  280. },
  281. new PkGuidAddDbo
  282. {
  283. SomeInt = 24,
  284. SomeText = "24"
  285. }
  286. };
  287. var service = new LuUtilsPkGuidDataAccess(context);
  288. var res = service.AddGuid(dbos);
  289. Assert.Equal(LuStatus.Success, res.Status);
  290. var ids = res.Data.ToList();
  291. var edit = service.DeleteSingleByIdGuid(ids[0]);
  292. Assert.Equal(LuStatus.Success, edit.Status);
  293. var get = service.GetMultiple(guid => guid.some_text);
  294. Assert.Equal(LuStatus.Success, get.Status);
  295. Assert.Equal(2, get.Data.Count);
  296. Assert.Equal(2, get.Data.Data.Count);
  297. var dbo = get.Data.Data[0];
  298. Assert.Equal(24, dbo.SomeInt);
  299. Assert.Equal("24", dbo.SomeText);
  300. dbo = get.Data.Data[1];
  301. Assert.Equal(42, dbo.SomeInt);
  302. Assert.Equal("42", dbo.SomeText);
  303. });
  304. }
  305. [Fact]
  306. public void TestDeleteSingle3()
  307. {
  308. Tests.TestRealDb(context =>
  309. {
  310. var dbos = new List<PkGuidAddDbo>
  311. {
  312. new PkGuidAddDbo
  313. {
  314. SomeInt = 42,
  315. SomeText = "442"
  316. },
  317. new PkGuidAddDbo
  318. {
  319. SomeInt = 42,
  320. SomeText = "42"
  321. },
  322. new PkGuidAddDbo
  323. {
  324. SomeInt = 24,
  325. SomeText = "24"
  326. }
  327. };
  328. var service = new LuUtilsPkGuidDataAccess(context);
  329. var res = service.AddGuid(dbos);
  330. Assert.Equal(LuStatus.Success, res.Status);
  331. var ids = res.Data.ToList();
  332. var edit = service.DeleteSingleByIdDbo(ids[0]);
  333. Assert.Equal(LuStatus.Success, edit.Status);
  334. var get = service.GetMultiple(guid => guid.some_text);
  335. Assert.Equal(LuStatus.Success, get.Status);
  336. Assert.Equal(2, get.Data.Count);
  337. Assert.Equal(2, get.Data.Data.Count);
  338. var dbo = get.Data.Data[0];
  339. Assert.Equal(24, dbo.SomeInt);
  340. Assert.Equal("24", dbo.SomeText);
  341. dbo = get.Data.Data[1];
  342. Assert.Equal(42, dbo.SomeInt);
  343. Assert.Equal("42", dbo.SomeText);
  344. });
  345. }
  346. [Fact]
  347. public void TestDeleteSingle4()
  348. {
  349. Tests.TestRealDb(context =>
  350. {
  351. var dbos = new List<PkBigSerialAddDbo>
  352. {
  353. new PkBigSerialAddDbo
  354. {
  355. SomeInt = 42,
  356. SomeText = "442"
  357. },
  358. new PkBigSerialAddDbo
  359. {
  360. SomeInt = 42,
  361. SomeText = "42"
  362. },
  363. new PkBigSerialAddDbo
  364. {
  365. SomeInt = 24,
  366. SomeText = "24"
  367. }
  368. };
  369. var service = new LuUtilsPkBigSerialDataAccess(context);
  370. var res = service.AddId(dbos);
  371. Assert.Equal(LuStatus.Success, res.Status);
  372. var ids = res.Data.ToList();
  373. var edit = service.DeleteSingleById(ids[0], guidDbo => guidDbo);
  374. Assert.Equal(LuStatus.Success, edit.Status);
  375. Assert.Equal(42, edit.Data.SomeInt);
  376. Assert.Equal("442", edit.Data.SomeText);
  377. var get = service.GetMultiple(guid => guid.some_text);
  378. Assert.Equal(LuStatus.Success, get.Status);
  379. Assert.Equal(2, get.Data.Count);
  380. Assert.Equal(2, get.Data.Data.Count);
  381. var dbo = get.Data.Data[0];
  382. Assert.Equal(24, dbo.SomeInt);
  383. Assert.Equal("24", dbo.SomeText);
  384. dbo = get.Data.Data[1];
  385. Assert.Equal(42, dbo.SomeInt);
  386. Assert.Equal("42", dbo.SomeText);
  387. });
  388. }
  389. [Fact]
  390. public void TestDeleteSingle5()
  391. {
  392. Tests.TestRealDb(context =>
  393. {
  394. var dbos = new List<PkBigSerialAddDbo>
  395. {
  396. new PkBigSerialAddDbo
  397. {
  398. SomeInt = 42,
  399. SomeText = "442"
  400. },
  401. new PkBigSerialAddDbo
  402. {
  403. SomeInt = 42,
  404. SomeText = "42"
  405. },
  406. new PkBigSerialAddDbo
  407. {
  408. SomeInt = 24,
  409. SomeText = "24"
  410. }
  411. };
  412. var service = new LuUtilsPkBigSerialDataAccess(context);
  413. var res = service.AddId(dbos);
  414. Assert.Equal(LuStatus.Success, res.Status);
  415. var ids = res.Data.ToList();
  416. var edit = service.DeleteSingleByIdId(ids[0]);
  417. Assert.Equal(LuStatus.Success, edit.Status);
  418. var get = service.GetMultiple(guid => guid.some_text);
  419. Assert.Equal(LuStatus.Success, get.Status);
  420. Assert.Equal(2, get.Data.Count);
  421. Assert.Equal(2, get.Data.Data.Count);
  422. var dbo = get.Data.Data[0];
  423. Assert.Equal(24, dbo.SomeInt);
  424. Assert.Equal("24", dbo.SomeText);
  425. dbo = get.Data.Data[1];
  426. Assert.Equal(42, dbo.SomeInt);
  427. Assert.Equal("42", dbo.SomeText);
  428. });
  429. }
  430. [Fact]
  431. public void TestDeleteSingle6()
  432. {
  433. Tests.TestRealDb(context =>
  434. {
  435. var dbos = new List<PkBigSerialAddDbo>
  436. {
  437. new PkBigSerialAddDbo
  438. {
  439. SomeInt = 42,
  440. SomeText = "442"
  441. },
  442. new PkBigSerialAddDbo
  443. {
  444. SomeInt = 42,
  445. SomeText = "42"
  446. },
  447. new PkBigSerialAddDbo
  448. {
  449. SomeInt = 24,
  450. SomeText = "24"
  451. }
  452. };
  453. var service = new LuUtilsPkBigSerialDataAccess(context);
  454. var res = service.AddId(dbos);
  455. Assert.Equal(LuStatus.Success, res.Status);
  456. var ids = res.Data.ToList();
  457. var edit = service.DeleteSingleByIdDbo(ids[0]);
  458. Assert.Equal(LuStatus.Success, edit.Status);
  459. var get = service.GetMultiple(guid => guid.some_text);
  460. Assert.Equal(LuStatus.Success, get.Status);
  461. Assert.Equal(2, get.Data.Count);
  462. Assert.Equal(2, get.Data.Data.Count);
  463. var dbo = get.Data.Data[0];
  464. Assert.Equal(24, dbo.SomeInt);
  465. Assert.Equal("24", dbo.SomeText);
  466. dbo = get.Data.Data[1];
  467. Assert.Equal(42, dbo.SomeInt);
  468. Assert.Equal("42", dbo.SomeText);
  469. });
  470. }
  471. }
  472. }