Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

LuEfDeleteDataAccessTest.cs 18KB

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