Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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