UnitTest1.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using Supabase.Postgrest.Responses;
  2. using static Supabase.Postgrest.Constants;
  3. using Supabase;
  4. using UnitTestTripHelper.Model;
  5. using UnitTestTripHelper.SupabaseConnect;
  6. namespace UnitTestTripHelper
  7. {
  8. public class UnitTest1
  9. {
  10. [Fact] //Òåñò íà ïðîâåðêó ñîçäàíèÿ êëèåíòà
  11. public async void TestCreateUser()
  12. {
  13. Client new_user = await Connect.Domain();
  14. Assert.NotNull(new_user);
  15. }
  16. [Fact] //Òåñò íà âõîä ïîëüçîâàòåëÿ
  17. public async void TestLoginUser()
  18. {
  19. Client new_user = await Connect.Domain();
  20. string email = "r@r.com";
  21. string password = "r";
  22. var user = await new_user.Auth.SignIn(email, password);
  23. Assert.NotNull(new_user);
  24. }
  25. [Fact] //Òåñò íà ðåãèñòðàöèþ íîâîãî ïîëüçîâàòåëÿ
  26. public async void TestSignUpNewUser()
  27. {
  28. Client new_user = await Connect.Domain();
  29. string email = "mikamakiboom7@gmail.com";
  30. string password = "test111";
  31. var user = await new_user.Auth.SignUp(email, password);
  32. await new_user.Auth.SignOut();
  33. Assert.NotNull(new_user);
  34. }
  35. [Fact] //Òåñò íà ÷òåíèå è ïîëó÷åíèå äàííûõ
  36. public async void TestReadDataCity()
  37. {
  38. Client conect = await Connect.Domain();
  39. int count = 0;
  40. int except = 49;
  41. count = await conect.From<City>().Count(CountType.Exact);
  42. Assert.True(count == except);
  43. }
  44. [Fact] //Òåñò íà äîáàâëåíèå ñòðîêè â òàáëèöó Ñòðàíû
  45. public async void TestInsertDataCountry()
  46. {
  47. Client conect = await Connect.Domain();
  48. bool check = false;
  49. Country model = new Country
  50. {
  51. Title = "Íîâàÿ ñòðàíà",
  52. Flag = null
  53. };
  54. try
  55. {
  56. ModeledResponse<Country> response = await conect.From<Country>().Insert(model);
  57. check = true;
  58. }
  59. catch
  60. {
  61. check = false;
  62. }
  63. Assert.True(check);
  64. }
  65. [Fact] //Òåñò íà óäàëåíèå â òàáëèöå Ñòðàíû
  66. public async void TestDeleteData()
  67. {
  68. Client conect = await Connect.Domain();
  69. bool check = false;
  70. try
  71. {
  72. await conect
  73. .From<City>()
  74. .Where(x => x.Id == 2)
  75. .Delete();
  76. check = true;
  77. }
  78. catch
  79. {
  80. check = false;
  81. }
  82. Assert.True(check);
  83. }
  84. [Fact] //Íåãàòèâíûé Òåñò íà ïðîâåðêó òðèããåðà äëÿ ðåéòèíãà, äèàïîçîí ðåéòèíãà îò 1 äî 5 â Îòåëå
  85. public async void TestCheckTriggerForRatingInHotels()
  86. {
  87. Client conect = await Connect.Domain();
  88. int rating = 6;
  89. bool check = false;
  90. try
  91. {
  92. var model = await conect
  93. .From<Hotels>()
  94. .Where(x => x.Id == 1)
  95. .Set(x => x.Rating, rating)
  96. .Update();
  97. check = true;
  98. }
  99. catch
  100. {
  101. check = false;
  102. }
  103. Assert.False(check);
  104. }
  105. [Fact] //Íåãàòèâíûé Òåñò íà ïðîâåðêó òðèããåðà äëÿ êîëè÷åñòâà êîìíàò â Îòåëå
  106. public async void TestCheckTriggerForQuantityInHotels()
  107. {
  108. Client conect = await Connect.Domain();
  109. int quantity = -10;
  110. bool check = false;
  111. try
  112. {
  113. var model = await conect
  114. .From<Hotels>()
  115. .Where(x => x.Id == 3)
  116. .Set(x => x.Quantity_of_rooms, quantity)
  117. .Update();
  118. check = true;
  119. }
  120. catch
  121. {
  122. check = false;
  123. }
  124. Assert.False(check);
  125. }
  126. [Fact] //Íåãàòèâíûé Òåñò íà ïðîâåðêó òðèããåðà äëÿ êîëè÷åñòâà ýòàæåé â Îòåëå
  127. public async void TestCheckTriggerForFloorsInHotels()
  128. {
  129. Client conect = await Connect.Domain();
  130. int floors = -100;
  131. bool check = false;
  132. try
  133. {
  134. var model = await conect
  135. .From<Hotels>()
  136. .Where(x => x.Id == 3)
  137. .Set(x => x.Floors, floors)
  138. .Update();
  139. check = true;
  140. }
  141. catch
  142. {
  143. check = false;
  144. }
  145. Assert.False(check);
  146. }
  147. [Fact] //Íåãàòèâíûé Òåñò íà ïðîâåðêó òðèããåðà äëÿ ñðåäíåãî ÷åêà â ðåñòîðàíàõ
  148. public async void TestCheckTriggerForAverageCheckInRestaurants()
  149. {
  150. Client conect = await Connect.Domain();
  151. int average = -15;
  152. bool check = false;
  153. try
  154. {
  155. var model = await conect
  156. .From<Restaurants>()
  157. .Where(x => x.Id == 3)
  158. .Set(x => x.Average_check, average)
  159. .Update();
  160. check = true;
  161. }
  162. catch
  163. {
  164. check = false;
  165. }
  166. Assert.False(check);
  167. }
  168. [Fact] //Íåãàòèâíûé Òåñò íà ïðîâåðêó òðèããåðà äëÿ ïîêàçíîé öåíû â Äîñòîïðèìå÷àòåëüíîñòÿõ
  169. public async void TestCheckTriggerForPriceInAttractions()
  170. {
  171. Client conect = await Connect.Domain();
  172. int price = -3;
  173. bool check = false;
  174. try
  175. {
  176. var model = await conect
  177. .From<Attractions>()
  178. .Where(x => x.Id == 3)
  179. .Set(x => x.Price_showing, price)
  180. .Update();
  181. check = true;
  182. }
  183. catch
  184. {
  185. check = false;
  186. }
  187. Assert.False(check);
  188. }
  189. [Fact] //Íåãàòèâíûé Òåñò íà ïðîâåðêó îãðàíè÷åíèé varchar â Äîñòîïðèìå÷àòåëüíîñòÿõ
  190. public async void TestCheckSizeVarcharTitle()
  191. {
  192. Client conect = await Connect.Domain();
  193. bool check = false;
  194. string title = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut "; //203 ñèìâîë
  195. try
  196. {
  197. var model = await conect
  198. .From<Attractions>()
  199. .Where (x => x.Id == 1)
  200. .Set(x=> x.Name, title)
  201. .Update();
  202. check = true;
  203. }
  204. catch
  205. {
  206. check = false;
  207. }
  208. Assert.False(check);
  209. }
  210. }
  211. }