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ů.

LuEfReadDataAccessTest.cs 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Luticate2.Utils.Dbo;
  5. using Luticate2.Utils.Dbo.OrderBy;
  6. using Luticate2.Utils.Dbo.Result;
  7. using TestUtils.DataAccess;
  8. using TestUtils.Dbo.PkBigSerial;
  9. using TestUtils.Dbo.PkGuid;
  10. using Xunit;
  11. namespace TestUtils.EfCrudDataAccess
  12. {
  13. public class LuEfReadDataAccessTest
  14. {
  15. [Fact]
  16. public void TestGetSingle1()
  17. {
  18. Tests.TestRealDb<LuUtilsPkBigSerialDataAccess>(service =>
  19. {
  20. var res = service.AddDbo(new PkBigSerialAddDbo
  21. {
  22. SomeInt = 42,
  23. SomeText = "42"
  24. });
  25. Assert.Equal(LuStatus.Success, res.Status);
  26. Assert.NotEqual(0, res.Data.Id);
  27. var get = service.GetSingle(bigserial => bigserial.some_int == 42);
  28. Assert.Equal(LuStatus.Success, get.Status);
  29. Assert.Equal("42", get.Data.SomeText);
  30. Assert.Equal(42, get.Data.SomeInt);
  31. Assert.Equal(res.Data.Id, get.Data.Id);
  32. });
  33. }
  34. [Fact]
  35. public void TestGetSingle2()
  36. {
  37. Tests.TestRealDb<LuUtilsPkBigSerialDataAccess>(service =>
  38. {
  39. var res = service.AddDbo(new PkBigSerialAddDbo
  40. {
  41. SomeInt = 42,
  42. SomeText = "42"
  43. });
  44. Assert.Equal(LuStatus.Success, res.Status);
  45. Assert.NotEqual(0, res.Data.Id);
  46. var get = service.GetSingle(bigserial => bigserial.some_int == 24);
  47. Assert.Equal(LuStatus.NotFound, get.Status);
  48. });
  49. }
  50. [Fact]
  51. public void TestGetSingleByKeys1()
  52. {
  53. Tests.TestRealDb<LuUtilsPkBigSerialDataAccess>(service =>
  54. {
  55. var res = service.AddDbo(new PkBigSerialAddDbo
  56. {
  57. SomeInt = 42,
  58. SomeText = "42"
  59. });
  60. Assert.Equal(LuStatus.Success, res.Status);
  61. Assert.NotEqual(0, res.Data.Id);
  62. var get = service.GetSingleByKeys(new KeyValuePair<string, object>("some_text", "42"));
  63. Assert.Equal(LuStatus.Success, get.Status);
  64. Assert.Equal("42", get.Data.SomeText);
  65. Assert.Equal(42, get.Data.SomeInt);
  66. Assert.Equal(res.Data.Id, get.Data.Id);
  67. });
  68. }
  69. [Fact]
  70. public void TestGetSingleByKeys2()
  71. {
  72. Tests.TestRealDb<LuUtilsPkBigSerialDataAccess>(service =>
  73. {
  74. var res = service.AddDbo(new PkBigSerialAddDbo
  75. {
  76. SomeInt = 42,
  77. SomeText = "42"
  78. });
  79. Assert.Equal(LuStatus.Success, res.Status);
  80. Assert.NotEqual(0, res.Data.Id);
  81. var get = service.GetSingleByKeys(new KeyValuePair<string, object>("some_text", "24"));
  82. Assert.Equal(LuStatus.NotFound, get.Status);
  83. });
  84. }
  85. [Fact]
  86. public void TestGetSingleById1()
  87. {
  88. Tests.TestRealDb<LuUtilsPkBigSerialDataAccess>(service =>
  89. {
  90. var res = service.AddId(new PkBigSerialAddDbo
  91. {
  92. SomeInt = 42,
  93. SomeText = "42"
  94. });
  95. Assert.Equal(LuStatus.Success, res.Status);
  96. Assert.NotEqual(0, res.Data);
  97. var get = service.GetSingleById(res.Data);
  98. Assert.Equal(LuStatus.Success, get.Status);
  99. Assert.Equal("42", get.Data.SomeText);
  100. Assert.Equal(42, get.Data.SomeInt);
  101. Assert.Equal(res.Data, get.Data.Id);
  102. });
  103. }
  104. [Fact]
  105. public void TestGetSingleById2()
  106. {
  107. Tests.TestRealDb<LuUtilsPkBigSerialDataAccess>(service =>
  108. {
  109. var res = service.AddId(new PkBigSerialAddDbo
  110. {
  111. SomeInt = 42,
  112. SomeText = "42"
  113. });
  114. Assert.Equal(LuStatus.Success, res.Status);
  115. Assert.NotEqual(0, res.Data);
  116. var get = service.GetSingle(bigserial => bigserial.some_int == 24);
  117. Assert.Equal(LuStatus.NotFound, get.Status);
  118. });
  119. }
  120. [Fact]
  121. public void TestGetSingleById3()
  122. {
  123. Tests.TestRealDb<LuUtilsPkGuidDataAccess>(service =>
  124. {
  125. var res = service.AddId(new PkGuidAddDbo
  126. {
  127. SomeInt = 42,
  128. SomeText = "42"
  129. });
  130. Assert.Equal(LuStatus.Success, res.Status);
  131. Assert.NotEqual(new Guid().ToString(), res.Data);
  132. var get = service.GetSingleById(res.Data);
  133. Assert.Equal(LuStatus.Success, get.Status);
  134. Assert.Equal("42", get.Data.SomeText);
  135. Assert.Equal(42, get.Data.SomeInt);
  136. Assert.Equal(res.Data, get.Data.Id);
  137. });
  138. }
  139. [Fact]
  140. public void TestGetSingleById4()
  141. {
  142. Tests.TestRealDb<LuUtilsPkGuidDataAccess>(service =>
  143. {
  144. var res = service.AddId(new PkGuidAddDbo
  145. {
  146. SomeInt = 42,
  147. SomeText = "42"
  148. });
  149. Assert.Equal(LuStatus.Success, res.Status);
  150. Assert.NotEqual(new Guid().ToString(), res.Data);
  151. var get = service.GetSingle(bigserial => bigserial.some_int == 24);
  152. Assert.Equal(LuStatus.NotFound, get.Status);
  153. });
  154. }
  155. [Fact]
  156. public void TestGetMultiple1()
  157. {
  158. Tests.TestRealDb<LuUtilsPkGuidDataAccess>(service =>
  159. {
  160. var dbos = new List<PkGuidAddDbo>
  161. {
  162. new PkGuidAddDbo
  163. {
  164. SomeInt = 42,
  165. SomeText = "442"
  166. },
  167. new PkGuidAddDbo
  168. {
  169. SomeInt = 42,
  170. SomeText = "42"
  171. },
  172. new PkGuidAddDbo
  173. {
  174. SomeInt = 142,
  175. SomeText = "24"
  176. }
  177. };
  178. var res = service.AddId(dbos);
  179. Assert.Equal(LuStatus.Success, res.Status);
  180. var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int),
  181. guid => guid.some_int == 42, 0, int.MaxValue, set => set.ThenBy(guid => guid.some_text));
  182. Assert.Equal(LuStatus.Success, get.Status);
  183. Assert.Equal(2, get.Data.Count);
  184. Assert.Equal(2, get.Data.Data.Count);
  185. var dbo = get.Data.Data[0];
  186. Assert.Equal(42, dbo.SomeInt);
  187. Assert.Equal("42", dbo.SomeText);
  188. dbo = get.Data.Data[1];
  189. Assert.Equal(42, dbo.SomeInt);
  190. Assert.Equal("442", dbo.SomeText);
  191. });
  192. }
  193. [Fact]
  194. public void TestGetMultiple2()
  195. {
  196. Tests.TestRealDb<LuUtilsPkGuidDataAccess>(service =>
  197. {
  198. var dbos = new List<PkGuidAddDbo>
  199. {
  200. new PkGuidAddDbo
  201. {
  202. SomeInt = 42,
  203. SomeText = "442"
  204. },
  205. new PkGuidAddDbo
  206. {
  207. SomeInt = 42,
  208. SomeText = "42"
  209. },
  210. new PkGuidAddDbo
  211. {
  212. SomeInt = 142,
  213. SomeText = "24"
  214. }
  215. };
  216. var res = service.AddId(dbos);
  217. Assert.Equal(LuStatus.Success, res.Status);
  218. var get = service.GetMultiple(guid => guid.some_int, guid => guid.some_int == 42, 0, int.MaxValue,
  219. guid => guid.some_text);
  220. Assert.Equal(LuStatus.Success, get.Status);
  221. Assert.Equal(2, get.Data.Count);
  222. Assert.Equal(2, get.Data.Data.Count);
  223. var dbo = get.Data.Data[0];
  224. Assert.Equal(42, dbo.SomeInt);
  225. Assert.Equal("42", dbo.SomeText);
  226. dbo = get.Data.Data[1];
  227. Assert.Equal(42, dbo.SomeInt);
  228. Assert.Equal("442", dbo.SomeText);
  229. });
  230. }
  231. [Fact]
  232. public void TestGetMultiple3()
  233. {
  234. Tests.TestRealDb<LuUtilsPkGuidDataAccess>(service =>
  235. {
  236. var dbos = new List<PkGuidAddDbo>
  237. {
  238. new PkGuidAddDbo
  239. {
  240. SomeInt = 42,
  241. SomeText = "442"
  242. },
  243. new PkGuidAddDbo
  244. {
  245. SomeInt = 42,
  246. SomeText = "42"
  247. },
  248. new PkGuidAddDbo
  249. {
  250. SomeInt = 142,
  251. SomeText = "24"
  252. }
  253. };
  254. var res = service.AddId(dbos);
  255. Assert.Equal(LuStatus.Success, res.Status);
  256. var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int), 0, int.MaxValue,
  257. set => set.ThenBy(guid => guid.some_text));
  258. Assert.Equal(LuStatus.Success, get.Status);
  259. Assert.Equal(3, get.Data.Count);
  260. Assert.Equal(3, get.Data.Data.Count);
  261. var dbo = get.Data.Data[0];
  262. Assert.Equal(42, dbo.SomeInt);
  263. Assert.Equal("42", dbo.SomeText);
  264. dbo = get.Data.Data[1];
  265. Assert.Equal(42, dbo.SomeInt);
  266. Assert.Equal("442", dbo.SomeText);
  267. dbo = get.Data.Data[2];
  268. Assert.Equal(142, dbo.SomeInt);
  269. Assert.Equal("24", dbo.SomeText);
  270. });
  271. }
  272. [Fact]
  273. public void TestGetMultiple4()
  274. {
  275. Tests.TestRealDb<LuUtilsPkGuidDataAccess>(service =>
  276. {
  277. var dbos = new List<PkGuidAddDbo>
  278. {
  279. new PkGuidAddDbo
  280. {
  281. SomeInt = 42,
  282. SomeText = "442"
  283. },
  284. new PkGuidAddDbo
  285. {
  286. SomeInt = 42,
  287. SomeText = "42"
  288. },
  289. new PkGuidAddDbo
  290. {
  291. SomeInt = 142,
  292. SomeText = "24"
  293. }
  294. };
  295. var res = service.AddId(dbos);
  296. Assert.Equal(LuStatus.Success, res.Status);
  297. var get = service.GetMultiple(guid => guid.some_int, 0, int.MaxValue, guid => guid.some_text);
  298. Assert.Equal(LuStatus.Success, get.Status);
  299. Assert.Equal(3, get.Data.Count);
  300. Assert.Equal(3, get.Data.Data.Count);
  301. var dbo = get.Data.Data[0];
  302. Assert.Equal(42, dbo.SomeInt);
  303. Assert.Equal("42", dbo.SomeText);
  304. dbo = get.Data.Data[1];
  305. Assert.Equal(42, dbo.SomeInt);
  306. Assert.Equal("442", dbo.SomeText);
  307. dbo = get.Data.Data[2];
  308. Assert.Equal(142, dbo.SomeInt);
  309. Assert.Equal("24", dbo.SomeText);
  310. });
  311. }
  312. [Fact]
  313. public void TestGetMultiple5()
  314. {
  315. Tests.TestRealDb<LuUtilsPkGuidDataAccess>(service =>
  316. {
  317. var dbos = new List<PkGuidAddDbo>
  318. {
  319. new PkGuidAddDbo
  320. {
  321. SomeInt = 42,
  322. SomeText = "442"
  323. },
  324. new PkGuidAddDbo
  325. {
  326. SomeInt = 42,
  327. SomeText = "42"
  328. },
  329. new PkGuidAddDbo
  330. {
  331. SomeInt = 142,
  332. SomeText = "24"
  333. }
  334. };
  335. var res = service.AddId(dbos);
  336. Assert.Equal(LuStatus.Success, res.Status);
  337. var orderBy = LuOrderByBinder.FromString("someInt,someText");
  338. Assert.Equal(LuStatus.Success, orderBy.Status);
  339. var get = service.GetMultiple(orderBy.Data);
  340. Assert.Equal(LuStatus.Success, get.Status);
  341. Assert.Equal(3, get.Data.Count);
  342. Assert.Equal(3, get.Data.Data.Count);
  343. var dbo = get.Data.Data[0];
  344. Assert.Equal(42, dbo.SomeInt);
  345. Assert.Equal("42", dbo.SomeText);
  346. dbo = get.Data.Data[1];
  347. Assert.Equal(42, dbo.SomeInt);
  348. Assert.Equal("442", dbo.SomeText);
  349. dbo = get.Data.Data[2];
  350. Assert.Equal(142, dbo.SomeInt);
  351. Assert.Equal("24", dbo.SomeText);
  352. });
  353. }
  354. [Fact]
  355. public void TestGetMultiple6()
  356. {
  357. Tests.TestRealDb<LuUtilsPkGuidDataAccess>(service =>
  358. {
  359. var dbos = new List<PkGuidAddDbo>
  360. {
  361. new PkGuidAddDbo
  362. {
  363. SomeInt = 42,
  364. SomeText = "442"
  365. },
  366. new PkGuidAddDbo
  367. {
  368. SomeInt = 42,
  369. SomeText = "42"
  370. },
  371. new PkGuidAddDbo
  372. {
  373. SomeInt = 142,
  374. SomeText = "24"
  375. }
  376. };
  377. var res = service.AddId(dbos);
  378. Assert.Equal(LuStatus.Success, res.Status);
  379. var orderBy = LuOrderByBinder.FromString("someText:desc,someInt");
  380. Assert.Equal(LuStatus.Success, orderBy.Status);
  381. var get = service.GetMultiple(orderBy.Data);
  382. Assert.Equal(LuStatus.Success, get.Status);
  383. Assert.Equal(3, get.Data.Count);
  384. Assert.Equal(3, get.Data.Data.Count);
  385. var dbo = get.Data.Data[0];
  386. Assert.Equal(42, dbo.SomeInt);
  387. Assert.Equal("442", dbo.SomeText);
  388. dbo = get.Data.Data[1];
  389. Assert.Equal(42, dbo.SomeInt);
  390. Assert.Equal("42", dbo.SomeText);
  391. dbo = get.Data.Data[2];
  392. Assert.Equal(142, dbo.SomeInt);
  393. Assert.Equal("24", dbo.SomeText);
  394. });
  395. }
  396. }
  397. }