Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

LuEfDeleteDataAccessTest.cs 17KB

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