UnitTest1.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using Supabase;
  2. using Supabase.Postgrest.Attributes;
  3. using Supabase.Postgrest.Models;
  4. using Supabase.Postgrest.Responses;
  5. using Supabase.Realtime;
  6. using System.ComponentModel;
  7. using System.Reflection;
  8. namespace TestProject1
  9. {
  10. [TestClass]
  11. public class UnitTest1
  12. {
  13. static string url = "https://vkxcxcimqqswxqxncmof.supabase.co";
  14. static string key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InZreGN4Y2ltcXFzd3hxeG5jbW9mIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjkxNjE0NDcsImV4cCI6MjA0NDczNzQ0N30.UZK8UzVHu47SZV4RtWRHVcOfTL3333_Kb_BbHDeqOCo";
  15. static Supabase.SupabaseOptions options = new Supabase.SupabaseOptions
  16. {
  17. AutoConnectRealtime = true
  18. };
  19. Supabase.Client supabase = new Supabase.Client(url, key, options);
  20. public async void Initialize()
  21. {
  22. await supabase.InitializeAsync();
  23. }
  24. public async Task<ModeledResponse<Season>> Get()
  25. {
  26. return await supabase.From<Season>().Get();
  27. }
  28. public async Task<ModeledResponse<Style>> Get1()
  29. {
  30. return await supabase.From<Style>().Get();
  31. }
  32. public async Task<ModeledResponse<Type>> Get2()
  33. {
  34. return await supabase.From<Type>().Get();
  35. }
  36. public async Task<ModeledResponse<Users>> Get3()
  37. {
  38. return await supabase.From<Users>().Get();
  39. }
  40. public async Task<ModeledResponse<type_subtype>> Get4()
  41. {
  42. return await supabase.From<type_subtype>().Get();
  43. }
  44. [TestMethod]
  45. public void TestSeasonReturn()//òåñò äëÿ ïðîâåðêè òîãî, ÷òî òàáëèöà ñåçîíîâ âîçâðàùàåò íå íóëåâûå çíà÷åíèÿ
  46. {
  47. Initialize();
  48. Task<ModeledResponse<Season>> result = Get();
  49. result.Wait();
  50. var seson = result.Result.Models;
  51. Assert.IsNotNull(seson);
  52. }
  53. [TestMethod]
  54. public void TestTypeReturn()//òåñò äëÿ ïðîâåðêè òîãî, ÷òî òàáëèöà ñåçîíîâ âîçâðàùàåò íå íóëåâûå çíà÷åíèÿ
  55. {
  56. Initialize();
  57. Task<ModeledResponse<Type>> result = Get2();
  58. result.Wait();
  59. var type = result.Result.Models;
  60. Assert.IsNotNull(type);
  61. }
  62. [TestMethod]
  63. public void TestStyleReturn()//òåñò äëÿ ïðîâåðêè òîãî, ÷òî òàáëèöà ññòèëåé âîçâðàùàåò íå íóëåâûå çíà÷åíèÿ
  64. {
  65. Initialize();
  66. Task<ModeledResponse<Style>> result = Get1();
  67. result.Wait();
  68. var styles = result.Result.Models;
  69. Assert.IsNotNull(styles);
  70. }
  71. [TestMethod]
  72. public void TestUsersReturn()//òåñò äëÿ ïðîâåðêè òîãî, ÷òî òàáëèöà ññòèëåé âîçâðàùàåò íå íóëåâûå çíà÷åíèÿ
  73. {
  74. Initialize();
  75. Task<ModeledResponse<Users>> result = Get3();
  76. result.Wait();
  77. var users = result.Result.Models;
  78. Assert.IsNotNull(users);
  79. }
  80. [TestMethod]
  81. public void TestSubtypereturn()//òåñò äëÿ ïðîâåðêè òîãî, ÷òî òàáëèöà ññòèëåé âîçâðàùàåò íå íóëåâûå çíà÷åíèÿ
  82. {
  83. Initialize();
  84. Task<ModeledResponse<type_subtype>> result = Get4();
  85. result.Wait();
  86. var subs = result.Result.Models;
  87. Assert.IsNotNull(subs);
  88. }
  89. [TestMethod]
  90. public void TestStyle()//òåñò äëÿ ïðîâåðêè òîãî, ÷òî òàáëèöà ñòèëåé âîçâðàùàåò êîððåêòíûå çíà÷åíèÿ ñòîëáöîâ
  91. {
  92. Initialize();
  93. Task<ModeledResponse<Style>> result = Get1();
  94. result.Wait();
  95. var styles = result.Result.Models;
  96. // Ïðîâåðÿåì, ÷òî â òàáëèöå åñòü çàïèñü ñ id = 5
  97. var style = styles.FirstOrDefault(s => s.Id == 5);
  98. Assert.IsNotNull(styles);
  99. // Ïðîâåðÿåì, ÷òî çíà÷åíèå title ðàâíî "Áîõî"
  100. Assert.AreEqual("áîõî", style.title);
  101. }
  102. [TestMethod]
  103. public void TestType()//òåñò äëÿ ïðîâåðêè òîãî, ÷òî òàáëèöà òèïîâ îäåæäû ñîäåðæèò 7 çàïèñåé
  104. {
  105. Initialize();
  106. Task<ModeledResponse<Type>> result = Get2();
  107. result.Wait();
  108. var types = result.Result.Models;
  109. Assert.AreEqual(7, types.Count, "Êîëè÷åñòâî òèïîâ îäåæäû â òàáëèöå íå ðàâíî 7.");
  110. }
  111. [TestMethod]
  112. public void TestSubtype()//òåñò äëÿ ïðîâåðêè òîãî, ÷òî òàáëèöà ñîäåðæèò 26 çàïèñåé
  113. {
  114. Initialize();
  115. Task<ModeledResponse<type_subtype>> result = Get4();
  116. result.Wait();
  117. var subs = result.Result.Models;
  118. Assert.AreEqual(26, subs.Count, "Êîëè÷åñòâî òèïîâ îäåæäû â òàáëèöå íå ðàâíî 7.");
  119. }
  120. [TestMethod]
  121. public void TestTypeNegative()//ïðåäûäóùèé òåñò, íî íåãàòèâíûé
  122. {
  123. Initialize();
  124. Task<ModeledResponse<Type>> result = Get2();
  125. result.Wait();
  126. var types = result.Result.Models;
  127. Assert.AreNotEqual(8, types.Count, "Êîëè÷åñòâî òèïîâ îäåæäû â òàáëèöå íå ðàâíî 7.");
  128. }
  129. [TestMethod]
  130. public void TestUser() // òåñò äëÿ ïðîâåðêè, ÷òî ïîëüçîâàòåëü ñ ID 2 èìååò èìÿ "àäìèí"
  131. {
  132. Initialize();
  133. Task<ModeledResponse<Users>> result = Get3();
  134. result.Wait();
  135. var users = result.Result.Models;
  136. // Ïðîâåðÿåì, ÷òî â òàáëèöå åñòü çàïèñü ñ id = 2
  137. var user = users.FirstOrDefault(u => u.Id == 2);
  138. // Ïðîâåðÿåì, ÷òî çíà÷åíèå name ðàâíî "àäìèí"
  139. Assert.AreEqual("Admin", user.name, "Èìÿ ïîëüçîâàòåëÿ ñ ID 2 íå ðàâíî 'àäìèí'.");
  140. }
  141. }
  142. }