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.

LuEfDeleteDataAccessTest.cs 17KB

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