Артем Гавриленко 3 سال پیش
والد
کامیت
7bab605758
4فایلهای تغییر یافته به همراه54 افزوده شده و 6 حذف شده
  1. 14 1
      Kusach/Functions.cs
  2. 1 1
      Kusach/Windows/RegWindow.xaml.cs
  3. 2 2
      Kusach/Windows/TransportEditWindow.xaml.cs
  4. 37 2
      UnitTests/UnitTest1.cs

+ 14 - 1
Kusach/Functions.cs

@@ -38,7 +38,20 @@ namespace Kusach
         {
             if (cnt.db.Dispatcher.Select(item => item.Login + item.Password).Contains(login + Encrypt.GetHash(password)))
                 return true;
-            return false;
+            else
+                return false;
+        }
+        public static bool IsLoginAlreadyTaken(string login)
+        {
+            return cnt.db.Dispatcher.Select(item => item.Login).Contains(login);
+        }
+        public static string GetNameOfTransport(int transportId)
+        {
+            return cnt.db.Transport.Where(item => item.IdTransport == transportId).Select(item => item.NameOfTransport).FirstOrDefault();
+        }
+        public static string GetNumberPlate(int transportId)
+        {
+            return cnt.db.Transport.Where(item => item.IdTransport == transportId).Select(item => item.NumberPlate).FirstOrDefault();
         }
     }
 }

+ 1 - 1
Kusach/Windows/RegWindow.xaml.cs

@@ -20,7 +20,7 @@ namespace Kusach
             {
                 if (logbox.Text == "" || passbox.Text == "")
                     MessageBox.Show("Поля не могут быть пустыми.");
-                else if (cnt.db.Dispatcher.Select(item => item.Login).Contains(logbox.Text))
+                else if (Functions.IsLoginAlreadyTaken(logbox.Text))
                     MessageBox.Show("Данный логин уже занят");
                 else
                 {

+ 2 - 2
Kusach/Windows/TransportEditWindow.xaml.cs

@@ -24,8 +24,8 @@ namespace Kusach.Windows
         {
             InitializeComponent();
             transportId = id;
-            NameOfTransportBox.Text = cnt.db.Transport.Where(item => item.IdTransport == transportId).Select(item => item.NameOfTransport).FirstOrDefault();
-            NumberPlateBox.Text = cnt.db.Transport.Where(item => item.IdTransport == transportId).Select(item => item.NumberPlate).FirstOrDefault();
+            NameOfTransportBox.Text = Functions.GetNameOfTransport(transportId);
+            NumberPlateBox.Text = Functions.GetNumberPlate(transportId);
         }
         private void BackButton_Click(object sender, RoutedEventArgs e)
         {

+ 37 - 2
UnitTests/UnitTest1.cs

@@ -9,7 +9,7 @@ namespace UnitTests
         [TestMethod]
         public void IsValidPhoneNumber()
         {
-            string phoneNum = "9996194949";
+            string phoneNum = "9999194949";
             Assert.IsTrue(Functions.IsValidPhoneNumber(phoneNum));
         }
         [TestMethod]
@@ -26,11 +26,46 @@ namespace UnitTests
             Assert.AreEqual(Functions.GetRouteName(routeId), expected);
         }
         [TestMethod]
-        public void Password()
+        public void PasswordEncryptTest()
         {
             string password = "lalka";
             string expected = "55B6F08EFCE1438F38323E02C7C451FBD1E1AA12";
             Assert.AreEqual(Encrypt.GetHash(password), expected);
         }
+        [TestMethod]
+        public void LoginTest()
+        {
+            string login = "qq";
+            string password = "qq";
+            Assert.IsTrue(Functions.LoginCheck(login, password));
+        }
+        [TestMethod]
+        public void IsValidLoginAndPassword()
+        {
+            Assert.IsTrue(Functions.IsValidLogAndPass("qq", "ww"));
+            Assert.IsTrue(Functions.IsValidLogAndPass("laq", "wwadsw"));
+            Assert.IsFalse(Functions.IsValidLogAndPass("", ""));
+            Assert.IsFalse(Functions.IsValidLogAndPass("", "SimplePass"));
+            Assert.IsFalse(Functions.IsValidLogAndPass("SimpleLogin", ""));
+        }
+        [TestMethod]
+        public void IsLoginAlreadyTaken()
+        {
+            Assert.IsTrue(Functions.IsLoginAlreadyTaken("qq"));
+        }
+        [TestMethod]
+        public void GetNameOfTransportTest()
+        {
+            int transportId = 1;
+            string expected = "Avtobus";
+            Assert.AreEqual(Functions.GetNameOfTransport(transportId), expected);
+        }
+        [TestMethod]
+        public void GetNumberPlateTest()
+        {
+            int transportId = 1;
+            string expected = "AA333AA78";
+            Assert.AreEqual(Functions.GetNumberPlate(transportId), expected);
+        }
     }
 }