Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

LuEfUpdateDataAccessTest.cs 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 LuEfUpdateDataAccessTest
  12. {
  13. [Fact]
  14. public void TestEditMultiple1()
  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.Edit(guid => guid.some_int == 42, guid => guid.some_int = -1, 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(-1, e.SomeInt);
  45. Assert.Equal("442", e.SomeText);
  46. e = elements[1];
  47. Assert.Equal(-1, e.SomeInt);
  48. Assert.Equal("42", e.SomeText);
  49. });
  50. }
  51. [Fact]
  52. public void TestEditMultiple2()
  53. {
  54. Tests.TestRealDb(context =>
  55. {
  56. var dbos = new List<PkGuidAddDbo>
  57. {
  58. new PkGuidAddDbo
  59. {
  60. SomeInt = 42,
  61. SomeText = "442"
  62. },
  63. new PkGuidAddDbo
  64. {
  65. SomeInt = 42,
  66. SomeText = "42"
  67. },
  68. new PkGuidAddDbo
  69. {
  70. SomeInt = 24,
  71. SomeText = "24"
  72. }
  73. };
  74. var service = new LuUtilsPkGuidDataAccess(context);
  75. var res = service.AddGuid(dbos);
  76. Assert.Equal(LuStatus.Success, res.Status);
  77. var edit = service.Edit(guid => guid.some_int == 42, guid => guid.some_int = -1, enumerable => enumerable.Select(guidDbo => guidDbo.SomeText));
  78. Assert.Equal(LuStatus.Success, edit.Status);
  79. var elements = edit.Data.ToList();
  80. Assert.Equal(2, elements.Count);
  81. var e = elements[0];
  82. Assert.Equal("442", e);
  83. e = elements[1];
  84. Assert.Equal("42", e);
  85. });
  86. }
  87. [Fact]
  88. public void TestEditMultiple3()
  89. {
  90. Tests.TestRealDb(context =>
  91. {
  92. var dbos = new List<PkGuidAddDbo>
  93. {
  94. new PkGuidAddDbo
  95. {
  96. SomeInt = 42,
  97. SomeText = "442"
  98. },
  99. new PkGuidAddDbo
  100. {
  101. SomeInt = 42,
  102. SomeText = "42"
  103. },
  104. new PkGuidAddDbo
  105. {
  106. SomeInt = 24,
  107. SomeText = "24"
  108. }
  109. };
  110. var service = new LuUtilsPkGuidDataAccess(context);
  111. var res = service.AddGuid(dbos);
  112. Assert.Equal(LuStatus.Success, res.Status);
  113. var edit = service.EditGuid(guid => guid.some_int == 42, guid => guid.some_int = -1);
  114. Assert.Equal(LuStatus.Success, edit.Status);
  115. var elements = edit.Data.ToList();
  116. Assert.Equal(2, elements.Count);
  117. var e = elements[0];
  118. Assert.NotEqual(new Guid().ToString(), e);
  119. e = elements[1];
  120. Assert.NotEqual(new Guid().ToString(), e);
  121. });
  122. }
  123. [Fact]
  124. public void TestEditMultiple4()
  125. {
  126. Tests.TestRealDb(context =>
  127. {
  128. var dbos = new List<PkBigSerialAddDbo>
  129. {
  130. new PkBigSerialAddDbo
  131. {
  132. SomeInt = 42,
  133. SomeText = "442"
  134. },
  135. new PkBigSerialAddDbo
  136. {
  137. SomeInt = 42,
  138. SomeText = "42"
  139. },
  140. new PkBigSerialAddDbo
  141. {
  142. SomeInt = 24,
  143. SomeText = "24"
  144. }
  145. };
  146. var service = new LuUtilsPkBigSerialDataAccess(context);
  147. var res = service.AddId(dbos);
  148. Assert.Equal(LuStatus.Success, res.Status);
  149. var edit = service.EditId(guid => guid.some_int == 42, guid => guid.some_int = -1);
  150. Assert.Equal(LuStatus.Success, edit.Status);
  151. var elements = edit.Data.ToList();
  152. Assert.Equal(2, elements.Count);
  153. var e = elements[0];
  154. Assert.NotEqual(0, e);
  155. e = elements[1];
  156. Assert.NotEqual(0, e);
  157. });
  158. }
  159. [Fact]
  160. public void TestEditMultiple5()
  161. {
  162. Tests.TestRealDb(context =>
  163. {
  164. var dbos = new List<PkGuidAddDbo>
  165. {
  166. new PkGuidAddDbo
  167. {
  168. SomeInt = 42,
  169. SomeText = "442"
  170. },
  171. new PkGuidAddDbo
  172. {
  173. SomeInt = 42,
  174. SomeText = "42"
  175. },
  176. new PkGuidAddDbo
  177. {
  178. SomeInt = 24,
  179. SomeText = "24"
  180. }
  181. };
  182. var service = new LuUtilsPkGuidDataAccess(context);
  183. var res = service.AddGuid(dbos);
  184. Assert.Equal(LuStatus.Success, res.Status);
  185. var edit = service.EditDbo(guid => guid.some_int == 42, guid => guid.some_int = -1);
  186. Assert.Equal(LuStatus.Success, edit.Status);
  187. var elements = edit.Data.ToList();
  188. Assert.Equal(2, elements.Count);
  189. var e = elements[0];
  190. Assert.Equal(-1, e.SomeInt);
  191. Assert.Equal("442", e.SomeText);
  192. e = elements[1];
  193. Assert.Equal(-1, e.SomeInt);
  194. Assert.Equal("42", e.SomeText);
  195. });
  196. }
  197. }
  198. }