Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

LuEfDeleteDataAccessTest.cs 18KB

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