UnitTest1.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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://mkrrkgiaewskfaslstgx.supabase.co";
  14. static string key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im1rcnJrZ2lhZXdza2Zhc2xzdGd4Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjkxNjExMDYsImV4cCI6MjA0NDczNzEwNn0.G6-C-LDzQBTuNAOcE83gZIjWUTiDpYWYa1Rjp4M5Kx0";
  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<Label>> Get()
  25. {
  26. return await supabase.From<Label>().Get();
  27. }
  28. public async Task<ModeledResponse<Age_rating>> Get1()
  29. {
  30. return await supabase.From<Age_rating>().Get();
  31. }
  32. public async Task<ModeledResponse<Company>> Get2()
  33. {
  34. return await supabase.From<Company>().Get();
  35. }
  36. public async Task<ModeledResponse<Game>> Get3()
  37. {
  38. return await supabase.From<Game>().Get();
  39. }
  40. [TestMethod] //Ïðîâåðêà íà òî, ÷òî òàáëèöà labels âîçâðàùàåò çíà÷åíèÿ
  41. public void TestLabels()
  42. {
  43. Initialize();
  44. Task<ModeledResponse<Label>> result = Get();
  45. result.Wait();
  46. var labels = result.Result.Models;
  47. Assert.IsNotNull(labels);
  48. }
  49. [TestMethod] //Ïðîâåðêà íà òî, ÷òî òàáëèöà âîçðàñòíûõ ðåéòèíãîâ íå ïóñòà
  50. public void TestRatingNotEmpty()
  51. {
  52. Initialize();
  53. Task<ModeledResponse<Age_rating>> result = Get1();
  54. result.Wait();
  55. var Age_rating = result.Result.Models;
  56. Assert.IsTrue(Age_rating.Count > 0, "Ðåéòèíã äîëæåí áûòü íå ïóñòûì.");
  57. }
  58. [TestMethod] //Ïðîâåðêà óíèêàëüíûõ èäåíòèôèêàòîðîâ â òàáëèöå êîìïàíèé
  59. public void TestCompanyHaveUniqueIds()
  60. {
  61. Initialize();
  62. Task<ModeledResponse<Company>> result = Get2();
  63. result.Wait();
  64. var Company = result.Result.Models;
  65. var uniqueIds = new HashSet<int>(Company.Select(l => l.Id));
  66. Assert.AreEqual(uniqueIds.Count, Company.Count, "Êîìïàíèè äîëæíû èìåòü óíèêàëüíûé èäåíòèôèêàòîð");
  67. }
  68. [TestMethod]
  69. public async Task TestInsertGame() //Òåñò âñòàâêè äàííûõ â òàáëèöó èãð
  70. {
  71. var game = new Game
  72. {
  73. Id = 15,
  74. Name = "Test Game",
  75. Desc = "This is a test game description.",
  76. Company = 1,
  77. Picture = "test_picture_url",
  78. Views = 0,
  79. Fav = 0,
  80. Age = 1,
  81. Ofi = "https://official-link.com",
  82. Tor = "https://torrent-link.com"
  83. };
  84. var result = await supabase.From<Game>().Insert(game);
  85. Assert.IsNotNull(result.Models);
  86. Assert.IsTrue(result.Models.Count > 0, "Çàïèñü íå âñòàâëåíà");
  87. }
  88. [TestMethod]
  89. public void TestGame() //Òåñò âûáîðà äàííûõ èç òàáëèöû èãð
  90. {
  91. Initialize();
  92. Task<ModeledResponse<Game>> result = Get3();
  93. result.Wait();
  94. var Game = result.Result.Models;
  95. Assert.IsNotNull(Game);
  96. }
  97. [TestMethod] //Ïðîâåðÿåò, ÷òî â ìåòêàõ âîçâðàùàåòñÿ 20 ñòðîê
  98. public void TestGetLabels_ReturnsTwentyRows()
  99. {
  100. Initialize();
  101. Task<ModeledResponse<Label>> result = Get();
  102. result.Wait();
  103. var labels = result.Result.Models;
  104. Assert.IsNotNull(labels);
  105. Assert.AreEqual(20, labels.Count);
  106. }
  107. [TestMethod] //Ïðîâåðÿåò, ÷òî â êîëëåêöèè íåò ïóñòûõ çíà÷åíèé
  108. public void TestLabelsContainNoNulls()
  109. {
  110. Initialize();
  111. Task<ModeledResponse<Label>> result = Get();
  112. result.Wait();
  113. var labels = result.Result.Models;
  114. Assert.IsFalse(labels.Contains(null), "Ìåòêè íå äîëæíû ñîäåðæàòü ïóñòûõ çíà÷åíèé.");
  115. }
  116. [TestMethod]
  117. public void TestCompany() //Òåñò âûáîðà äàííûõ èç òàáëèöû êîìïàíèè
  118. {
  119. Initialize();
  120. Task<ModeledResponse<Company>> result = Get2();
  121. result.Wait();
  122. var Company = result.Result.Models;
  123. Assert.IsNotNull(Company);
  124. }
  125. [TestMethod] //Òåñò ÷òî ñòðîêà ñî 2id â êîìïàíèè ÿâëÿåòñÿ Riot Games
  126. public void TestCompanyHaveRow()
  127. {
  128. Initialize();
  129. Task<ModeledResponse<Company>> result = Get2();
  130. result.Wait();
  131. var company = result.Result.Models;
  132. var companyy = company.FirstOrDefault(s => s.Id == 2);
  133. Assert.IsNotNull(company);
  134. Assert.AreEqual("Riot Games", companyy.name);
  135. }
  136. [TestMethod] //Ïðîâåðêà óíèêàëüíûõ èäåíòèôèêàòîðîâ â òàáëèöå ìåòîê
  137. public void TestLabelHaveUniqueIds()
  138. {
  139. Initialize();
  140. Task<ModeledResponse<Label>> result = Get();
  141. result.Wait();
  142. var labels = result.Result.Models;
  143. var uniqueIds = new HashSet<int>(labels.Select(l => l.ID));
  144. Assert.AreEqual(uniqueIds.Count, labels.Count, "Ìåòêè äîëæíû èìåòü óíèêàëüíûé èäåíòèôèêàòîð");
  145. }
  146. }
  147. }