UnitTest1.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 = "qq";
  39. string password = "qq";
  40. Assert.IsTrue(Functions.LoginCheck(login, password));
  41. }
  42. [TestMethod]
  43. public void IsValidLoginAndPassword()
  44. {
  45. Assert.IsTrue(Functions.IsValidLogAndPass("qq", "ww"));
  46. Assert.IsTrue(Functions.IsValidLogAndPass("laq", "wwadsw"));
  47. Assert.IsFalse(Functions.IsValidLogAndPass("", ""));
  48. Assert.IsFalse(Functions.IsValidLogAndPass("", "SimplePass"));
  49. Assert.IsFalse(Functions.IsValidLogAndPass("SimpleLogin", ""));
  50. }
  51. [TestMethod]
  52. public void IsLoginAlreadyTaken()
  53. {
  54. Assert.IsTrue(Functions.IsLoginAlreadyTaken("qq"));
  55. Assert.IsFalse(Functions.IsLoginAlreadyTaken("user23"));
  56. Assert.IsFalse(Functions.IsLoginAlreadyTaken("F"));
  57. Assert.IsFalse(Functions.IsLoginAlreadyTaken(""));
  58. }
  59. [TestMethod]
  60. public void GetNameOfTransportUsingId()
  61. {
  62. int transportId = 1;
  63. string expected = "Avtobus";
  64. Assert.AreEqual(Functions.GetNameOfTransport(transportId), expected);
  65. }
  66. [TestMethod]
  67. public void GetNumberPlateUsingId()
  68. {
  69. int transportId = 1;
  70. string expected = "AA333AA78";
  71. Assert.AreEqual(Functions.GetNumberPlate(transportId), expected);
  72. }
  73. [TestMethod]
  74. public void GetRouteNameUsingId()
  75. {
  76. int routeId = 1;
  77. string expected = "Маршрут #1";
  78. Assert.AreEqual(Functions.GetRouteName(routeId), expected);
  79. }
  80. [TestMethod]
  81. public void GetNameOfPointUsingId()
  82. {
  83. int pointId = 1;
  84. string expected = "Томская";
  85. Assert.AreEqual(Functions.GetNameOfPoint(pointId), expected);
  86. }
  87. [TestMethod]
  88. public void GetLocationOfPointUsingId()
  89. {
  90. int pointId = 1;
  91. string expected = "Томская, 21";
  92. Assert.AreEqual(Functions.GetLocationOfPoint(pointId), expected);
  93. }
  94. [TestMethod]
  95. public void IsValidNameAndLocationOfPoint()
  96. {
  97. string Name = "Томская";
  98. string Location = "Томская, 21";
  99. Assert.IsTrue(Functions.IsValidNameAndLocationOfPoint(Name, Location));
  100. }
  101. [TestMethod]
  102. public void IsValidInfoAboutDriver()
  103. {
  104. string IdTransport = "1";
  105. string name = "Петр";
  106. string surname = "Некрасов";
  107. string patronymic = "Антонович";
  108. Assert.IsTrue(Functions.IsValidInfoAboutDriver(IdTransport, name, surname, patronymic));
  109. }
  110. [TestMethod]
  111. public void IsOnlyDigits()
  112. {
  113. string Id = "123";
  114. Assert.IsTrue(Functions.IsOnlyDigits(Id));
  115. }
  116. [TestMethod]
  117. public void IsValidDateOfBirthday()
  118. {
  119. DateTime date1 = new DateTime(2000,05,02);
  120. DateTime date2 = new DateTime(2025,02,01);
  121. Assert.IsTrue(Functions.IsValidDateOfBirthday(date1));
  122. Assert.IsFalse(Functions.IsValidDateOfBirthday(date2));
  123. }
  124. [TestMethod]
  125. public void IsPhoneNumberAlreadyTaken()
  126. {
  127. Assert.IsTrue(Functions.IsPhoneNumberAlreadyTaken("7776006060"));
  128. Assert.IsFalse(Functions.IsPhoneNumberAlreadyTaken("7776006061"));
  129. Assert.IsFalse(Functions.IsPhoneNumberAlreadyTaken("7776006062"));
  130. Assert.IsFalse(Functions.IsPhoneNumberAlreadyTaken("7776006063"));
  131. Assert.IsFalse(Functions.IsPhoneNumberAlreadyTaken("7776006064"));
  132. Assert.IsFalse(Functions.IsPhoneNumberAlreadyTaken("7776006065"));
  133. }
  134. [TestMethod]
  135. public void IsEmailAlreadyTaken()
  136. {
  137. Assert.IsTrue(Functions.IsEmailAlreadyTaken("filaks@gmail.com"));
  138. Assert.IsFalse(Functions.IsEmailAlreadyTaken("filaks@mail.ru"));
  139. Assert.IsFalse(Functions.IsEmailAlreadyTaken("cute@gmail.com"));
  140. Assert.IsFalse(Functions.IsEmailAlreadyTaken("user@gmail.com"));
  141. Assert.IsFalse(Functions.IsEmailAlreadyTaken("simpleEmail@sibmail.com"));
  142. }
  143. }
  144. }