UnitTest1.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System.Collections.Generic;
  3. using Курсовой_проект_3._1;
  4. using System.Linq;
  5. namespace UnitTestProject
  6. {
  7. [TestClass]
  8. public class UnitTest1
  9. {
  10. [TestMethod]
  11. public void AuthorizationTest()
  12. {
  13. string login, password;
  14. // 1
  15. login = "nikich4523";
  16. password = "123qaz";
  17. Assert.IsTrue(Test.AuthorizationTest(login, password));
  18. // 2
  19. login = "gr692_pav";
  20. password = "uncorrect_pass";
  21. Assert.IsFalse(Test.AuthorizationTest(login, password));
  22. // 3
  23. login = "nikich4523";
  24. password = "";
  25. Assert.IsFalse(Test.AuthorizationTest(login, password));
  26. // 4
  27. login = "";
  28. password = "123qaz";
  29. Assert.IsFalse(Test.AuthorizationTest(login, password));
  30. // 5
  31. login = "nikich45233";
  32. password = "123qaz";
  33. Assert.IsFalse(Test.AuthorizationTest(login, password));
  34. // 6
  35. login = "";
  36. password = "";
  37. Assert.IsFalse(Test.AuthorizationTest(login, password));
  38. }
  39. [TestMethod]
  40. public void RegistrationTest()
  41. {
  42. string login, password, fname, lname, mname, nickname, email, phoneNumber, birthday;
  43. // 1
  44. login = "newUser";
  45. password = "123qaz";
  46. fname = "Иван";
  47. lname = "Иванов";
  48. mname = "Иванович";
  49. nickname = "newNickname";
  50. email = "ivan4523@mail.ru";
  51. phoneNumber = "+79641166980";
  52. birthday = "02.04.2003";
  53. Assert.IsTrue(Test.RegistrationTest(login, password, fname, lname, mname, nickname, email, phoneNumber, birthday));
  54. // 2
  55. login = "";
  56. password = "123qaz";
  57. fname = "Иван";
  58. lname = "Иванов";
  59. mname = "Иванович";
  60. nickname = "newNickname";
  61. email = "ivan4523@mail.ru";
  62. phoneNumber = "+79641166980";
  63. birthday = "02.04.2003";
  64. Assert.IsFalse(Test.RegistrationTest(login, password, fname, lname, mname, nickname, email, phoneNumber, birthday));
  65. // 3
  66. login = "newUser";
  67. password = "";
  68. fname = "Иван";
  69. lname = "Иванов";
  70. mname = "Иванович";
  71. nickname = "newNickname";
  72. email = "ivan4523@mail.ru";
  73. phoneNumber = "+79641166980";
  74. birthday = "02.04.2003";
  75. Assert.IsFalse(Test.RegistrationTest(login, password, fname, lname, mname, nickname, email, phoneNumber, birthday));
  76. // 4
  77. login = "newUser";
  78. password = "123qaz";
  79. fname = "";
  80. lname = "Иванов";
  81. mname = "Иванович";
  82. nickname = "newNickname";
  83. email = "ivan4523@mail.ru";
  84. phoneNumber = "+79641166980";
  85. birthday = "02.04.2003";
  86. Assert.IsFalse(Test.RegistrationTest(login, password, fname, lname, mname, nickname, email, phoneNumber, birthday));
  87. // 5
  88. login = "newUser";
  89. password = "123qaz";
  90. fname = "Иван";
  91. lname = "";
  92. mname = "Иванович";
  93. nickname = "newNickname";
  94. email = "ivan4523@mail.ru";
  95. phoneNumber = "+79641166980";
  96. birthday = "02.04.2003";
  97. Assert.IsFalse(Test.RegistrationTest(login, password, fname, lname, mname, nickname, email, phoneNumber, birthday));
  98. // 6
  99. login = "newUser";
  100. password = "123qaz";
  101. fname = "Иван";
  102. lname = "Иванов";
  103. mname = "";
  104. nickname = "newNickname";
  105. email = "ivan4523@mail.ru";
  106. phoneNumber = "+79641166980";
  107. birthday = "02.04.2003";
  108. Assert.IsFalse(Test.RegistrationTest(login, password, fname, lname, mname, nickname, email, phoneNumber, birthday));
  109. // 7
  110. login = "newUser";
  111. password = "123qaz";
  112. fname = "Иван";
  113. lname = "Иванов";
  114. mname = "Иванович";
  115. nickname = "";
  116. email = "ivan4523@mail.ru";
  117. phoneNumber = "+79641166980";
  118. birthday = "02.04.2003";
  119. Assert.IsFalse(Test.RegistrationTest(login, password, fname, lname, mname, nickname, email, phoneNumber, birthday));
  120. // 8
  121. login = "newUser";
  122. password = "123qaz";
  123. fname = "Иван";
  124. lname = "Иванов";
  125. mname = "Иванович";
  126. nickname = "newNickname";
  127. email = "";
  128. phoneNumber = "+79641166980";
  129. birthday = "02.04.2003";
  130. Assert.IsFalse(Test.RegistrationTest(login, password, fname, lname, mname, nickname, email, phoneNumber, birthday));
  131. // 9
  132. login = "nikich4523";
  133. password = "123qaz";
  134. fname = "Иван";
  135. lname = "Иванов";
  136. mname = "Иванович";
  137. nickname = "newNickname";
  138. email = "ivan4523@mail.ru";
  139. phoneNumber = "";
  140. birthday = "02.04.2003";
  141. Assert.IsFalse(Test.RegistrationTest(login, password, fname, lname, mname, nickname, email, phoneNumber, birthday));
  142. // 10
  143. login = "newUser";
  144. password = "123qaz";
  145. fname = "Иван";
  146. lname = "Иванов";
  147. mname = "Иванович";
  148. nickname = "newNickname";
  149. email = "ivan4523mail.ru";
  150. phoneNumber = "+79641166980";
  151. birthday = "02.04.2003";
  152. Assert.IsFalse(Test.RegistrationTest(login, password, fname, lname, mname, nickname, email, phoneNumber, birthday));
  153. // 11
  154. login = "newUser";
  155. password = "123qaz";
  156. fname = "Иван";
  157. lname = "Иванов";
  158. mname = "Иванович";
  159. nickname = "newNickname";
  160. email = "ivan4523@mail.ru";
  161. phoneNumber = "+7964116698AAAAA";
  162. birthday = "02.04.2003";
  163. Assert.IsFalse(Test.RegistrationTest(login, password, fname, lname, mname, nickname, email, phoneNumber, birthday));
  164. // 12
  165. login = "newUser";
  166. password = "123qaz";
  167. fname = "Иван";
  168. lname = "Иванов";
  169. mname = "Иванович";
  170. nickname = "newNickname";
  171. email = "ivan4523@mail.ru";
  172. phoneNumber = "+79641166980";
  173. birthday = "";
  174. Assert.IsFalse(Test.RegistrationTest(login, password, fname, lname, mname, nickname, email, phoneNumber, birthday));
  175. // 13
  176. login = "newUser";
  177. password = "123qaz";
  178. fname = "Иван";
  179. lname = "Иванов";
  180. mname = "Иванович";
  181. nickname = "Arxont";
  182. email = "ivan4523@mail.ru";
  183. phoneNumber = "+79641166980";
  184. birthday = "02.04.2003";
  185. Assert.IsFalse(Test.RegistrationTest(login, password, fname, lname, mname, nickname, email, phoneNumber, birthday));
  186. }
  187. [TestMethod]
  188. public void ChangeSettingsTest()
  189. {
  190. int userId;
  191. string email, phoneNumber, about;
  192. // 1
  193. userId = 1;
  194. email = "newEmail@mail.ru";
  195. phoneNumber = "+79132818850";
  196. about = "Немного обо мне!)";
  197. Assert.IsTrue(Test.ChangeSettingsTest(userId, email, phoneNumber, about));
  198. // 2
  199. userId = 1;
  200. email = "newEmail@mail.ru";
  201. phoneNumber = "+79132818850";
  202. about = "";
  203. Assert.IsTrue(Test.ChangeSettingsTest(userId, email, phoneNumber, about));
  204. // 3
  205. userId = 1;
  206. email = "nikich4523@mail.ru";
  207. phoneNumber = "+79132818850";
  208. about = "Немного обо мне!)";
  209. Assert.IsFalse(Test.ChangeSettingsTest(userId, email, phoneNumber, about));
  210. // 4
  211. userId = 1;
  212. email = "newEmail@mail.ru";
  213. phoneNumber = "+79641166987";
  214. about = "Немного обо мне!)";
  215. Assert.IsFalse(Test.ChangeSettingsTest(userId, email, phoneNumber, about));
  216. // 5
  217. userId = 1;
  218. email = "";
  219. phoneNumber = "";
  220. about = "Немного обо мне!)";
  221. Assert.IsFalse(Test.ChangeSettingsTest(userId, email, phoneNumber, about));
  222. // 6
  223. userId = 1;
  224. email = "alen.20.plo@mail.ru";
  225. phoneNumber = "+79642DDD6432";
  226. about = "Немного обо мне!)";
  227. Assert.IsFalse(Test.ChangeSettingsTest(userId, email, phoneNumber, about));
  228. }
  229. [TestMethod]
  230. public void CreatePlayerAppTest()
  231. {
  232. string title, text;
  233. int userId;
  234. // 1
  235. userId = 2;
  236. title = "Ищу команду!";
  237. text = "Играю в Dota 2. Опыта игры на профессинональной сцене не имею.";
  238. Assert.IsTrue(Test.CreatePlayerApp(userId, title, text));
  239. // 2
  240. userId = 1;
  241. title = "Ищу команду!";
  242. text = "Играю в Dota 2. Опыта игры на профессинональной сцене не имею.";
  243. Assert.IsFalse(Test.CreatePlayerApp(userId, title, text));
  244. // 3
  245. userId = 2;
  246. title = "";
  247. text = "Играю в Dota 2. Опыта игры на профессинональной сцене не имею.";
  248. Assert.IsFalse(Test.CreatePlayerApp(userId, title, text));
  249. // 4
  250. userId = 2;
  251. title = "Ищу команду!";
  252. text = "";
  253. Assert.IsFalse(Test.CreatePlayerApp(userId, title, text));
  254. // 5
  255. userId = 2;
  256. title = "";
  257. text = "";
  258. Assert.IsFalse(Test.CreatePlayerApp(userId, title, text));
  259. }
  260. [TestMethod]
  261. public void CreateTeamAppTest()
  262. {
  263. string title, text;
  264. int teamId;
  265. // 1
  266. teamId = 2;
  267. title = "Ищем игрока!";
  268. text = "Команда по Counter-Strike ищет игрока на роль снайпера. Ранг глобал или выше!";
  269. Assert.IsTrue(Test.CreateTeamApp(teamId, title, text));
  270. // 2
  271. teamId = 1;
  272. title = "Ищем игрока!";
  273. text = "Команда по Counter-Strike ищет игрока на роль снайпера. Ранг глобал или выше!";
  274. Assert.IsFalse(Test.CreateTeamApp(teamId, title, text));
  275. // 3
  276. teamId = 2;
  277. title = "";
  278. text = "Команда по Counter-Strike ищет игрока на роль снайпера. Ранг глобал или выше!";
  279. Assert.IsFalse(Test.CreateTeamApp(teamId, title, text));
  280. // 4
  281. teamId = 2;
  282. title = "Ищем игрока!";
  283. text = "";
  284. Assert.IsFalse(Test.CreateTeamApp(teamId, title, text));
  285. // 5
  286. teamId = 2;
  287. title = "";
  288. text = "";
  289. Assert.IsFalse(Test.CreateTeamApp(teamId, title, text));
  290. }
  291. [TestMethod]
  292. public void TeamInfoOutput()
  293. {
  294. int tournamentId, teamId;
  295. int expected, result;
  296. // GetPrizeInTournament ///
  297. // 1
  298. tournamentId = 1;
  299. teamId = 6;
  300. expected = 0;
  301. result = Func.GetPrizeInTournament(tournamentId, teamId);
  302. Assert.AreEqual(expected, result);
  303. // 2
  304. tournamentId = 4;
  305. teamId = 1008;
  306. expected = 18000000;
  307. result = Func.GetPrizeInTournament(tournamentId, teamId);
  308. Assert.AreEqual(expected, result);
  309. // 3
  310. tournamentId = 4;
  311. teamId = 1016;
  312. expected = 5000000;
  313. result = Func.GetPrizeInTournament(tournamentId, teamId);
  314. Assert.AreEqual(expected, result);
  315. // GetPlaceInTournament ///
  316. // 1
  317. string resultStr;
  318. tournamentId = 1;
  319. teamId = 6;
  320. string expectedStr = "";
  321. resultStr = Func.GetPlaceInTournament(tournamentId, teamId);
  322. Assert.AreEqual(expectedStr, resultStr);
  323. // 2
  324. tournamentId = 4;
  325. teamId = 1008;
  326. expectedStr = "1";
  327. resultStr = Func.GetPlaceInTournament(tournamentId, teamId);
  328. Assert.AreEqual(expectedStr, resultStr);
  329. // 3
  330. tournamentId = 4;
  331. teamId = 1016;
  332. expectedStr = "2";
  333. resultStr = Func.GetPlaceInTournament(tournamentId, teamId);
  334. Assert.AreEqual(expectedStr, resultStr);
  335. // GetTeamTournamentIds ///
  336. // 1
  337. List<int> expectedTournamentIds = new List<int>();
  338. List<int> resultTournamentIds = Func.GetTeamTournamentIds(1);
  339. Assert.IsTrue(expectedTournamentIds.SequenceEqual(resultTournamentIds));
  340. // 2
  341. expectedTournamentIds = new List<int>() { 4 };
  342. resultTournamentIds = Func.GetTeamTournamentIds(1008);
  343. Assert.IsTrue(expectedTournamentIds.SequenceEqual(resultTournamentIds));
  344. }
  345. [TestMethod]
  346. public void PlayerInfoOutput()
  347. {
  348. // ConvertToStringMoneyTest ///
  349. int moneyInt;
  350. string expectedStr, resultStr;
  351. // 1
  352. moneyInt = 40000000;
  353. expectedStr = "40 000 000";
  354. resultStr = Func.ConvertIntToStringMoney(moneyInt);
  355. StringAssert.Equals(expectedStr, resultStr);
  356. // 2
  357. moneyInt = 0;
  358. expectedStr = "0";
  359. resultStr = Func.ConvertIntToStringMoney(moneyInt);
  360. StringAssert.Equals(expectedStr, resultStr);
  361. // 3
  362. moneyInt = 1000;
  363. expectedStr = "1 000";
  364. resultStr = Func.ConvertIntToStringMoney(moneyInt);
  365. StringAssert.Equals(expectedStr, resultStr);
  366. // 4
  367. moneyInt = 1623451;
  368. expectedStr = "1 623 451";
  369. resultStr = Func.ConvertIntToStringMoney(moneyInt);
  370. StringAssert.Equals(expectedStr, resultStr);
  371. // 5
  372. moneyInt = 235;
  373. expectedStr = "235";
  374. resultStr = Func.ConvertIntToStringMoney(moneyInt);
  375. StringAssert.Equals(expectedStr, resultStr);
  376. // GetTeamIdsTest ///
  377. List<int> expectedTeamIds;
  378. List<int> resultTeamIds;
  379. // 1
  380. expectedTeamIds = new List<int>() { };
  381. resultTeamIds = Func.GetTeamIds(1);
  382. Assert.IsTrue(expectedTeamIds.SequenceEqual(resultTeamIds));
  383. // 2
  384. expectedTeamIds = new List<int>() { 1006 };
  385. resultTeamIds = Func.GetTeamIds(7);
  386. Assert.IsTrue(expectedTeamIds.SequenceEqual(resultTeamIds));
  387. // 3
  388. expectedTeamIds = new List<int>() { 6 };
  389. resultTeamIds = Func.GetTeamIds(8);
  390. Assert.IsTrue(expectedTeamIds.SequenceEqual(resultTeamIds));
  391. // GetWinDrawLoseCountUser ///
  392. int winCount, drawCount, loseCount;
  393. (int, int, int) resultCount;
  394. // 1
  395. (winCount, drawCount, loseCount) = (0, 0, 0);
  396. resultCount = Func.GetWinDrawLoseCountUser(1);
  397. Assert.AreEqual((winCount, drawCount, loseCount), resultCount);
  398. // 2
  399. (winCount, drawCount, loseCount) = (0, 0, 0);
  400. resultCount = Func.GetWinDrawLoseCountUser(1);
  401. Assert.AreEqual((winCount, drawCount, loseCount), resultCount);
  402. // 3
  403. (winCount, drawCount, loseCount) = (0, 0, 0);
  404. resultCount = Func.GetWinDrawLoseCountUser(1);
  405. Assert.AreEqual((winCount, drawCount, loseCount), resultCount);
  406. // GetTeamMatchIds ///
  407. List<int> expectedMatchIds;
  408. List<int> resultMatchIds;
  409. // 1
  410. expectedMatchIds = new List<int>();
  411. resultMatchIds = Func.GetTeamMatchIds(1);
  412. Assert.IsTrue(expectedMatchIds.SequenceEqual(resultMatchIds));
  413. // 2
  414. expectedMatchIds = new List<int>() { 1, 9, 14};
  415. resultMatchIds = Func.GetTeamMatchIds(6);
  416. Assert.IsTrue(expectedMatchIds.SequenceEqual(resultMatchIds));
  417. // 3
  418. expectedMatchIds = new List<int>() { 5 };
  419. resultMatchIds = Func.GetTeamMatchIds(1007);
  420. Assert.IsTrue(expectedMatchIds.SequenceEqual(resultMatchIds));
  421. }
  422. }
  423. }