UnitTest1.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using Kusach;
  4. namespace UnitTests
  5. {
  6. [TestClass]
  7. public class UnitTest1
  8. {
  9. [TestMethod]
  10. public void IsValidPhoneNumber()
  11. {
  12. Assert.IsTrue(Functions.IsValidPhoneNumber("9999194949"));
  13. Assert.IsTrue(Functions.IsValidPhoneNumber("9994443322"));
  14. Assert.IsFalse(Functions.IsValidPhoneNumber("99991949499"));
  15. Assert.IsFalse(Functions.IsValidPhoneNumber("999919494"));
  16. Assert.IsFalse(Functions.IsValidPhoneNumber("My phone number"));
  17. Assert.IsFalse(Functions.IsValidPhoneNumber(""));
  18. }
  19. [TestMethod]
  20. public void IsValidEmail()
  21. {
  22. Assert.IsTrue(Functions.IsValidEmail("user@gmail.com"));
  23. Assert.IsTrue(Functions.IsValidEmail("user@mail.ru"));
  24. Assert.IsFalse(Functions.IsValidEmail("usergmail.com"));
  25. Assert.IsFalse(Functions.IsValidEmail("usergmailcom"));
  26. Assert.IsFalse(Functions.IsValidEmail(""));
  27. }
  28. [TestMethod]
  29. public void PasswordEncryptTest()
  30. {
  31. string password = "qq";
  32. string expected = "BED4EB698C6EEEA7F1DDF5397D480D3F2C0FB938";
  33. Assert.AreEqual(Encrypt.GetHash(password), expected);
  34. }
  35. [TestMethod]
  36. public void LoginTest()
  37. {
  38. string login = "kovalev30";
  39. string password = "kovalev333";
  40. Assert.IsTrue(Functions.LoginCheck(login, password));
  41. }
  42. [TestMethod]
  43. public void IsValidLoginAndPassword()
  44. {
  45. Assert.IsTrue(Functions.IsValidLogAndPass("login3", "password33"));
  46. Assert.IsTrue(Functions.IsValidLogAndPass("qq", "ww"));
  47. Assert.IsTrue(Functions.IsValidLogAndPass("laq", "wwadsw"));
  48. Assert.IsFalse(Functions.IsValidLogAndPass("", ""));
  49. Assert.IsFalse(Functions.IsValidLogAndPass("", "SimplePass"));
  50. Assert.IsFalse(Functions.IsValidLogAndPass("SimpleLogin", ""));
  51. }
  52. [TestMethod]
  53. public void IsValidLoginAndPasswordRegister()
  54. {
  55. Assert.IsTrue(Functions.IsValidLogAndPassRegister("login3", "password33"));
  56. Assert.IsFalse(Functions.IsValidLogAndPassRegister("login3", "login3"));
  57. Assert.IsFalse(Functions.IsValidLogAndPassRegister("qq", "ww"));
  58. Assert.IsFalse(Functions.IsValidLogAndPassRegister("qqvxfc", "ww"));
  59. }
  60. [TestMethod]
  61. public void IsLoginAlreadyTaken()
  62. {
  63. Assert.IsTrue(Functions.IsLoginAlreadyTaken("kovalev30"));
  64. Assert.IsFalse(Functions.IsLoginAlreadyTaken("user23"));
  65. Assert.IsFalse(Functions.IsLoginAlreadyTaken("F"));
  66. Assert.IsFalse(Functions.IsLoginAlreadyTaken(""));
  67. }
  68. [TestMethod]
  69. public void GetNameOfTransportUsingId()
  70. {
  71. int transportId = 1;
  72. string expected = "Avtobus";
  73. Assert.AreEqual(Functions.GetNameOfTransport(transportId), expected);
  74. }
  75. [TestMethod]
  76. public void GetNumberPlateUsingId()
  77. {
  78. int transportId = 1;
  79. string expected = "а333аа78";
  80. Assert.AreEqual(Functions.GetNumberPlate(transportId), expected);
  81. }
  82. [TestMethod]
  83. public void GetRouteNameUsingId()
  84. {
  85. int routeId = 1;
  86. string expected = "Маршрут #1";
  87. Assert.AreEqual(Functions.GetRouteName(routeId), expected);
  88. }
  89. [TestMethod]
  90. public void GetNameOfPointUsingId()
  91. {
  92. int pointId = 1;
  93. string expected = "Томская";
  94. Assert.AreEqual(Functions.GetNameOfPoint(pointId), expected);
  95. }
  96. [TestMethod]
  97. public void GetLocationOfPointUsingId()
  98. {
  99. int pointId = 1;
  100. string expected = "Томская, 21";
  101. Assert.AreEqual(Functions.GetLocationOfPoint(pointId), expected);
  102. }
  103. [TestMethod]
  104. public void IsValidNameAndLocationOfPoint()
  105. {
  106. string Name = "Томская";
  107. string Location = "Томская, 21";
  108. Assert.IsTrue(Functions.IsValidNameAndLocationOfPoint(Name, Location));
  109. }
  110. [TestMethod]
  111. public void IsValidInfoAboutDriver()
  112. {
  113. string IdTransport = "1";
  114. string name = "Петр";
  115. string surname = "Некрасов";
  116. string patronymic = "Антонович";
  117. Assert.IsTrue(Functions.IsValidInfoAboutDriver(IdTransport, name, surname, patronymic));
  118. }
  119. [TestMethod]
  120. public void IsOnlyDigits()
  121. {
  122. string Id = "123";
  123. Assert.IsTrue(Functions.IsOnlyDigits(Id));
  124. }
  125. [TestMethod]
  126. public void IsValidDateOfBirthday()
  127. {
  128. DateTime date1 = new DateTime(2000,05,02);
  129. DateTime date2 = new DateTime(2025,02,01);
  130. Assert.IsTrue(Functions.IsValidDateOfBirthday(date1));
  131. Assert.IsFalse(Functions.IsValidDateOfBirthday(date2));
  132. }
  133. [TestMethod]
  134. public void IsPhoneNumberAlreadyTaken()
  135. {
  136. Assert.IsTrue(Functions.IsPhoneNumberAlreadyTaken("9996963350"));
  137. Assert.IsFalse(Functions.IsPhoneNumberAlreadyTaken("7776006061"));
  138. Assert.IsFalse(Functions.IsPhoneNumberAlreadyTaken("7776006062"));
  139. Assert.IsFalse(Functions.IsPhoneNumberAlreadyTaken("7776006063"));
  140. Assert.IsFalse(Functions.IsPhoneNumberAlreadyTaken("7776006064"));
  141. Assert.IsFalse(Functions.IsPhoneNumberAlreadyTaken("7776006065"));
  142. }
  143. [TestMethod]
  144. public void IsEmailAlreadyTaken()
  145. {
  146. Assert.IsTrue(Functions.IsEmailAlreadyTaken("rud.kovalev@gmail.com"));
  147. Assert.IsFalse(Functions.IsEmailAlreadyTaken("filaks@mail.ru"));
  148. Assert.IsFalse(Functions.IsEmailAlreadyTaken("cute@gmail.com"));
  149. Assert.IsFalse(Functions.IsEmailAlreadyTaken("user@gmail.com"));
  150. Assert.IsFalse(Functions.IsEmailAlreadyTaken("simpleEmail@sibmail.com"));
  151. }
  152. }
  153. }