Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

LuEfReadDataAccessTest.cs 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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 LuEfReadDataAccessTest
  12. {
  13. [Fact]
  14. public void TestGetSingle1()
  15. {
  16. Tests.TestRealDb(context =>
  17. {
  18. var service = new LuUtilsPkBigSerialDataAccess(context);
  19. var res = service.AddDbo(new PkBigSerialAddDbo
  20. {
  21. SomeInt = 42,
  22. SomeText = "42"
  23. });
  24. Assert.Equal(LuStatus.Success, res.Status);
  25. Assert.NotEqual(0, res.Data.Id);
  26. var get = service.GetSingle(bigserial => bigserial.some_int == 42);
  27. Assert.Equal(LuStatus.Success, get.Status);
  28. Assert.Equal("42", get.Data.SomeText);
  29. Assert.Equal(42, get.Data.SomeInt);
  30. Assert.Equal(res.Data.Id, get.Data.Id);
  31. });
  32. }
  33. [Fact]
  34. public void TestGetSingle2()
  35. {
  36. Tests.TestRealDb(context =>
  37. {
  38. var service = new LuUtilsPkBigSerialDataAccess(context);
  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(context =>
  54. {
  55. var service = new LuUtilsPkBigSerialDataAccess(context);
  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(context =>
  74. {
  75. var service = new LuUtilsPkBigSerialDataAccess(context);
  76. var res = service.AddDbo(new PkBigSerialAddDbo
  77. {
  78. SomeInt = 42,
  79. SomeText = "42"
  80. });
  81. Assert.Equal(LuStatus.Success, res.Status);
  82. Assert.NotEqual(0, res.Data.Id);
  83. var get = service.GetSingleByKeys(new KeyValuePair<string, object>("some_text", "24"));
  84. Assert.Equal(LuStatus.NotFound, get.Status);
  85. });
  86. }
  87. [Fact]
  88. public void TestGetSingleById1()
  89. {
  90. Tests.TestRealDb(context =>
  91. {
  92. var service = new LuUtilsPkBigSerialDataAccess(context);
  93. var res = service.AddId(new PkBigSerialAddDbo
  94. {
  95. SomeInt = 42,
  96. SomeText = "42"
  97. });
  98. Assert.Equal(LuStatus.Success, res.Status);
  99. Assert.NotEqual(0, res.Data);
  100. var get = service.GetSingleById(res.Data);
  101. Assert.Equal(LuStatus.Success, get.Status);
  102. Assert.Equal("42", get.Data.SomeText);
  103. Assert.Equal(42, get.Data.SomeInt);
  104. Assert.Equal(res.Data, get.Data.Id);
  105. });
  106. }
  107. [Fact]
  108. public void TestGetSingleById2()
  109. {
  110. Tests.TestRealDb(context =>
  111. {
  112. var service = new LuUtilsPkBigSerialDataAccess(context);
  113. var res = service.AddId(new PkBigSerialAddDbo
  114. {
  115. SomeInt = 42,
  116. SomeText = "42"
  117. });
  118. Assert.Equal(LuStatus.Success, res.Status);
  119. Assert.NotEqual(0, res.Data);
  120. var get = service.GetSingle(bigserial => bigserial.some_int == 24);
  121. Assert.Equal(LuStatus.NotFound, get.Status);
  122. });
  123. }
  124. [Fact]
  125. public void TestGetSingleById3()
  126. {
  127. Tests.TestRealDb(context =>
  128. {
  129. var service = new LuUtilsPkGuidDataAccess(context);
  130. var res = service.AddGuid(new PkGuidAddDbo
  131. {
  132. SomeInt = 42,
  133. SomeText = "42"
  134. });
  135. Assert.Equal(LuStatus.Success, res.Status);
  136. Assert.NotEqual(new Guid().ToString(), res.Data);
  137. var get = service.GetSingleById(res.Data);
  138. Assert.Equal(LuStatus.Success, get.Status);
  139. Assert.Equal("42", get.Data.SomeText);
  140. Assert.Equal(42, get.Data.SomeInt);
  141. Assert.Equal(res.Data, get.Data.Id);
  142. });
  143. }
  144. [Fact]
  145. public void TestGetSingleById4()
  146. {
  147. Tests.TestRealDb(context =>
  148. {
  149. var service = new LuUtilsPkGuidDataAccess(context);
  150. var res = service.AddGuid(new PkGuidAddDbo
  151. {
  152. SomeInt = 42,
  153. SomeText = "42"
  154. });
  155. Assert.Equal(LuStatus.Success, res.Status);
  156. Assert.NotEqual(new Guid().ToString(), res.Data);
  157. var get = service.GetSingle(bigserial => bigserial.some_int == 24);
  158. Assert.Equal(LuStatus.NotFound, get.Status);
  159. });
  160. }
  161. [Fact]
  162. public void TestGetMultiple1()
  163. {
  164. Tests.TestRealDb(context =>
  165. {
  166. var dbos = new List<PkGuidAddDbo>
  167. {
  168. new PkGuidAddDbo
  169. {
  170. SomeInt = 42,
  171. SomeText = "442"
  172. },
  173. new PkGuidAddDbo
  174. {
  175. SomeInt = 42,
  176. SomeText = "42"
  177. },
  178. new PkGuidAddDbo
  179. {
  180. SomeInt = 24,
  181. SomeText = "24"
  182. }
  183. };
  184. var service = new LuUtilsPkGuidDataAccess(context);
  185. var res = service.AddGuid(dbos);
  186. Assert.Equal(LuStatus.Success, res.Status);
  187. var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int),
  188. guid => guid.some_int == 42, 0, int.MaxValue, set => set.OrderBy(guid => guid.some_text));
  189. Assert.Equal(LuStatus.Success, get.Status);
  190. Assert.Equal(2, get.Data.Count);
  191. Assert.Equal(2, get.Data.Data.Count);
  192. var dbo = get.Data.Data[0];
  193. Assert.Equal(42, dbo.SomeInt);
  194. Assert.Equal("42", dbo.SomeText);
  195. dbo = get.Data.Data[1];
  196. Assert.Equal(42, dbo.SomeInt);
  197. Assert.Equal("442", dbo.SomeText);
  198. });
  199. }
  200. [Fact]
  201. public void TestGetMultiple2()
  202. {
  203. Tests.TestRealDb(context =>
  204. {
  205. var dbos = new List<PkGuidAddDbo>
  206. {
  207. new PkGuidAddDbo
  208. {
  209. SomeInt = 42,
  210. SomeText = "442"
  211. },
  212. new PkGuidAddDbo
  213. {
  214. SomeInt = 42,
  215. SomeText = "42"
  216. },
  217. new PkGuidAddDbo
  218. {
  219. SomeInt = 24,
  220. SomeText = "24"
  221. }
  222. };
  223. var service = new LuUtilsPkGuidDataAccess(context);
  224. var res = service.AddGuid(dbos);
  225. Assert.Equal(LuStatus.Success, res.Status);
  226. var get = service.GetMultiple(guid => guid.some_int, guid => guid.some_int == 42, 0, int.MaxValue,
  227. guid => guid.some_text);
  228. Assert.Equal(LuStatus.Success, get.Status);
  229. Assert.Equal(2, get.Data.Count);
  230. Assert.Equal(2, get.Data.Data.Count);
  231. var dbo = get.Data.Data[0];
  232. Assert.Equal(42, dbo.SomeInt);
  233. Assert.Equal("42", dbo.SomeText);
  234. dbo = get.Data.Data[1];
  235. Assert.Equal(42, dbo.SomeInt);
  236. Assert.Equal("442", dbo.SomeText);
  237. });
  238. }
  239. [Fact]
  240. public void TestGetMultiple3()
  241. {
  242. Tests.TestRealDb(context =>
  243. {
  244. var dbos = new List<PkGuidAddDbo>
  245. {
  246. new PkGuidAddDbo
  247. {
  248. SomeInt = 42,
  249. SomeText = "442"
  250. },
  251. new PkGuidAddDbo
  252. {
  253. SomeInt = 42,
  254. SomeText = "42"
  255. },
  256. new PkGuidAddDbo
  257. {
  258. SomeInt = 24,
  259. SomeText = "24"
  260. }
  261. };
  262. var service = new LuUtilsPkGuidDataAccess(context);
  263. var res = service.AddGuid(dbos);
  264. Assert.Equal(LuStatus.Success, res.Status);
  265. var get = service.GetMultiple(table => table.OrderBy(guid => guid.some_int), 0, int.MaxValue,
  266. set => set.OrderBy(guid => guid.some_text));
  267. Assert.Equal(LuStatus.Success, get.Status);
  268. Assert.Equal(3, get.Data.Count);
  269. Assert.Equal(3, get.Data.Data.Count);
  270. var dbo = get.Data.Data[0];
  271. Assert.Equal(24, dbo.SomeInt);
  272. Assert.Equal("24", dbo.SomeText);
  273. dbo = get.Data.Data[1];
  274. Assert.Equal(42, dbo.SomeInt);
  275. Assert.Equal("42", dbo.SomeText);
  276. dbo = get.Data.Data[2];
  277. Assert.Equal(42, dbo.SomeInt);
  278. Assert.Equal("442", dbo.SomeText);
  279. });
  280. }
  281. [Fact]
  282. public void TestGetMultiple4()
  283. {
  284. Tests.TestRealDb(context =>
  285. {
  286. var dbos = new List<PkGuidAddDbo>
  287. {
  288. new PkGuidAddDbo
  289. {
  290. SomeInt = 42,
  291. SomeText = "442"
  292. },
  293. new PkGuidAddDbo
  294. {
  295. SomeInt = 42,
  296. SomeText = "42"
  297. },
  298. new PkGuidAddDbo
  299. {
  300. SomeInt = 24,
  301. SomeText = "24"
  302. }
  303. };
  304. var service = new LuUtilsPkGuidDataAccess(context);
  305. var res = service.AddGuid(dbos);
  306. Assert.Equal(LuStatus.Success, res.Status);
  307. var get = service.GetMultiple(guid => guid.some_int, 0, int.MaxValue, guid => guid.some_text);
  308. Assert.Equal(LuStatus.Success, get.Status);
  309. Assert.Equal(3, get.Data.Count);
  310. Assert.Equal(3, get.Data.Data.Count);
  311. var dbo = get.Data.Data[0];
  312. Assert.Equal(24, dbo.SomeInt);
  313. Assert.Equal("24", dbo.SomeText);
  314. dbo = get.Data.Data[1];
  315. Assert.Equal(42, dbo.SomeInt);
  316. Assert.Equal("42", dbo.SomeText);
  317. dbo = get.Data.Data[2];
  318. Assert.Equal(42, dbo.SomeInt);
  319. Assert.Equal("442", dbo.SomeText);
  320. });
  321. }
  322. }
  323. }