commit 414636c00f17b5129cbc071f420e756df8fd9f1f
Author: schenkj <schenkj@students.zcu.cz>
Date:   Tue Apr 19 09:01:53 2022 +0200

    commentary
    
    new comments for testing classes and messages for failed tests

diff --git a/Backend/BackendTesting/UserManagementTesting.cs b/Backend/BackendTesting/UserManagementTesting.cs
index 6f204f9..38f9a7d 100644
--- a/Backend/BackendTesting/UserManagementTesting.cs
+++ b/Backend/BackendTesting/UserManagementTesting.cs
@@ -17,22 +17,27 @@ using Models.Users;
 
 namespace Core.Services
 {
+    //class responsible for testing user and backend autentication on login
     [TestClass]
     public class UserManagementTesting      //testing of Core/Services/UserService
     {
+        //necessary items for new database with my data for teting
         private static readonly IConfiguration configuration = new ConfigurationBuilder().Build();
         public DatabaseContext ctx;
-
         public Core.Services.IUserService US;
+        
+        //constructor for creating database and filling it with dummy data
         public UserManagementTesting()
         {
+            //creating new database
             this.ctx = new DatabaseContext(configuration);
             this.US = new UserServiceEF(this.ctx, TestingLogger.GetLogger(), TestingMapper.GetMapper());
 
+            //ensure the database is fresh without unwanted users from previous testings
             ctx.Database.EnsureDeleted();
             ctx.Database.EnsureCreated();
 
-            //vytvoření dat pro testování
+            //data for testing creation
             var userList = new List<User>();
             userList.Add(new User() { Username = "aaa", Name = "aaa", Surname = "aaa", Password = "aaa", Role = Models.Enums.ERole.ANNOTATOR });
             userList.Add(new User() { Username = "bbb", Name = "bbb", Surname = "bbb", Password = "bbb", Role = Models.Enums.ERole.ANNOTATOR });
@@ -45,7 +50,7 @@ namespace Core.Services
             userList.Add(new User() { Username = "iii", Name = "iii", Surname = "iii", Password = "iii", Role = Models.Enums.ERole.ADMINISTRATOR });
             userList.Add(new User() { Username = "jjj", Name = "jjj", Surname = "jjj", Password = "jjj", Role = Models.Enums.ERole.ADMINISTRATOR });
 
-            //nahrani do databaze
+            //filling up the database
             foreach (var user in userList)
             {
                 US.CreateUser(user.Username, user.Name, user.Surname, user.Password, user.Role);
@@ -98,16 +103,16 @@ namespace Core.Services
             {
                 if (user.Username == username)
                 {
-                    //checking, that user with wanted username was not changed
-                    /*Assert.AreEqual(expected.Username, user.Username);*/
-                    Assert.AreEqual(name, user.Name);
-                    Assert.AreEqual(surname, user.Surname);
-                    Assert.AreNotEqual(password, user.Password);
-                    Assert.AreEqual(role, user.Role);
+                    //checking, that user with wanted username was not changed and he is present in database
+                    //if there were some data changed (not username) - these tests will fail
+                    Assert.AreEqual(name, user.Name, "names are not same");
+                    Assert.AreEqual(surname, user.Surname, "surnames are not same");
+                    Assert.AreNotEqual(password, user.Password, "passwords are same - it should have been hashed");
+                    Assert.AreEqual(role, user.Role, "roles are not same");
                     return;
                 }
             }
-            //if there was username not found, inserted user must have been changed or wasnt saved into database at all - test fails
+            //if there was username not found, inserted users username must have been changed or wasnt saved into database at all - test fails
             Assert.Fail("supposedly created user was not found in database");
         }
 
@@ -115,7 +120,7 @@ namespace Core.Services
         [DataRow("aaa", "aaa", "aaa", "aaa", "aaa", ERole.ANNOTATOR)]
         [DataRow("bbb", "bbb", "bbb", "bbb", "bbb", ERole.ANNOTATOR)]
         [DataRow("ccc", "ccc", "ccc", "ccc", "ccc", ERole.ADMINISTRATOR)]
-        //method testing, that user searched by username is the one wanted - data are inserted before
+        //method testing, that user searched by username is the one wanted - data are inserted in constructor
         public void GetUserByUsername_Test(string insertedUsername, string username, string name, string surname, string password, ERole role)
         {
             User? actual = US.GetUserByUsername(insertedUsername);
@@ -130,27 +135,26 @@ namespace Core.Services
         [DataRow("aaa", "aaa", "aaa", "aaa", ERole.ANNOTATOR)]
         [DataRow("bbb", "bbb", "bbb", "bbb", ERole.ANNOTATOR)]
         [DataRow("ccc", "ccc", "ccc", "ccc", ERole.ADMINISTRATOR)]
+        //testing method to get user via his ID, using another tested method - GetUserByUsername
         public void GetUserById_Test(string username, string name, string surname, string password, ERole role)
         {
-            //TODO Find id other way then via another tested method
             User? expected = US.GetUserByUsername(username);
             if (expected == null)
             {
-                Assert.Fail();
+                Assert.Fail("There is mistake in test data or in GetUserByUsername method");
                 return;
             }
-
             User? actual = US.GetUserById(expected.Id);
 
             //testing whole users
-            Assert.AreEqual(expected, actual);
+            Assert.AreEqual(expected, actual, "Users are not same");
 
             //testing all parameters
-            Assert.AreEqual(actual.Username, username);
-            Assert.AreEqual(actual.Name, name);
-            Assert.AreEqual(actual.Surname, surname);
-            Assert.AreNotEqual(actual.Password, password);
-            Assert.AreEqual(actual.Role, role);
+            Assert.AreEqual(actual.Username, username, "usernames are not same");
+            Assert.AreEqual(actual.Name, name, "names are not same");
+            Assert.AreEqual(actual.Surname, surname, "surnames are not same");
+            Assert.AreNotEqual(actual.Password, password, "passwords ARE same (the one from database should have been hashed)");
+            Assert.AreEqual(actual.Role, role, "roles are not same");
         }
 
 
@@ -164,16 +168,18 @@ namespace Core.Services
         [DataRow("xxx", "xxx", "xxx", "xxx", ERole.ANNOTATOR, "xxx", "bbb", "ccc", ERole.ANNOTATOR)]
         [DataRow("xxx", "xxx", "xxx", "xxx", ERole.ANNOTATOR, "xxx", "xxx", "xxx", ERole.ADMINISTRATOR)]
         [DataRow("xxx", "xxx", "xxx", "xxx", ERole.ANNOTATOR, "xxx", "bbb", "ccc", ERole.ADMINISTRATOR)]
+        //creating new user and updating him
         public void UpdateUser_Test(string oldUsername, string oldName, string oldSurname, string password, ERole oldRole, string? username = null, string? name = null, string? surname = null, ERole? role = null)
         {
+            //new user creation
             User? newUser = US.CreateUser(oldUsername, oldName, oldSurname, password, oldRole);
             if(newUser == null)
             {
-                Assert.Fail("user not created");
+                Assert.Fail("user not created (maybe already user username?)");
             }
             User? actual = US.UpdateUser(newUser, username, name, surname, role);
 
-            Assert.IsNotNull(actual);
+            Assert.IsNotNull(actual, "user wasnt updated, null was returned");
             Assert.AreEqual(username, actual.Username, "wrong username");
             Assert.AreEqual(name, actual.Name, "wrong name");
             Assert.AreEqual(surname, actual.Surname, "wrong surname");
@@ -186,9 +192,10 @@ namespace Core.Services
         [DataRow("ccc", "aaa")]//admin
         [DataRow("bbb", "")]//set to none password
         [DataRow("eee", "eee")]//keep old password
+        //test of changing password
         public void ChangePassword_Test(string username, string newPassword) 
         {
-            //get user
+            //get user using GetUserByUsername
             User? changingUser = US.GetUserByUsername(username);
             if(changingUser == null)
             {
@@ -229,6 +236,7 @@ namespace Core.Services
         [DataRow("aaa", "aaa")]//anotator
         [DataRow("fff", "fff")]//anotator
         [DataRow("iii", "iii")]//admin
+        //testing login autentication CheckUsernamePassword
         public void CheckUsernamePassword_Correct(string username, string password)
         {
             User? checkedUser = US.CheckUsernamePassword(username, password);
@@ -244,9 +252,10 @@ namespace Core.Services
                 Assert.Fail("There is mistake in tested data");
                 return;
             }
-            Assert.AreEqual(expected, checkedUser);
+            Assert.AreEqual(expected, checkedUser, "Users are not same (maybe wrong password)");
         }
 
+
         [TestMethod]
         [DataRow("aaa", "bbb")]//changedPassword?
         [DataRow("fff", "fgh")]//anotator
@@ -256,7 +265,7 @@ namespace Core.Services
             User? checkedUser = US.CheckUsernamePassword(username, password);
             if (checkedUser != null)
             {
-                //there are just correct users - this should have returned user
+                //there are just incorrect users - this should not have returned user
                 Assert.Fail("there are just incorrect users-passwords - this should not return user");
                 return;
             }
@@ -265,13 +274,15 @@ namespace Core.Services
         [TestMethod]
         [DataRow("fff", "fff", "123")]//anotator
         [DataRow("iii", "iii", "456")]//admin
+        //more complex test of the same as the above
+        //passwords are changed and then there is login
         public void CheckUsernamePassword_ChangedPassword(string username, string oldPassword, string newPassword)
         {
             //get user from database
             User? oldUser = US.CheckUsernamePassword(username, oldPassword);
             if (oldUser == null) 
             {
-                Assert.Fail("This should have returned user - there are wrong input data");
+                Assert.Fail("This should have returned user - there are wrong input data or CheckUsernamePassword isnt working properly");
                 return;
             }
             //change users password
@@ -301,6 +312,7 @@ namespace Core.Services
             }
         }
         [TestMethod]
+        //I dont really know how to test this
         public void GetUsers_Test()
         {
             var userList = US.GetUsers();
@@ -310,36 +322,40 @@ namespace Core.Services
 
 
         [TestMethod]
-        //correct
+        //login from AuthService testing with correct username-password
         [DataRow("aaa", "aaa", ERole.ANNOTATOR)]//anotator
         [DataRow("fff", "fff", ERole.ANNOTATOR)]//anotator
         [DataRow("iii", "iii", ERole.ADMINISTRATOR)]//admin
         public void AuthService_Login_Correct(string username, string password, ERole role)
         {
+            //creating new instance of AuthService
             var jwt = TestingJwtUtils.GetJwtUtils();
             var AS = new AuthService(US, jwt);
-         //   var AS = new AuthServiceEF(this.ctx, TestingLogger.GetLogger(), TestingMapper.GetMapper());
+            //try login
             var loginResults = AS.Login(username, password);
+            //check results
             Assert.IsNotNull(loginResults);
             Assert.IsTrue(loginResults.Ok);
             Assert.IsNotNull(loginResults.Token);
             DateTime exp = loginResults.Expiration;
+            //expiration is in the future
             var now = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
             Assert.IsTrue(exp.CompareTo(now) > 0);//if compare is >0 -> exp is in the future
             Assert.AreEqual(role, loginResults.Role);
         }
 
-        //incorrect
+        //login from AuthService testing with incorrect username-password
         [TestMethod]
         [DataRow("aaa", "bbb")]//changedPassword?
         [DataRow("fff", "fgh")]//anotator
         [DataRow("iii", "123")]//admin
         public void AuthService_Login_Incorrect(string username, string password)
         {
+            //creating new instance of AuthService
             var jwt = TestingJwtUtils.GetJwtUtils();
             var AS = new AuthService(US, jwt);
-            //   var AS = new AuthServiceEF(this.ctx, TestingLogger.GetLogger(), TestingMapper.GetMapper());
             var loginResults = AS.Login(username, password);
+            //checking if login results are null or there is false in OK and there is none obtained token
             if (loginResults != null)
             {
                 Assert.IsFalse(loginResults.Ok);
diff --git a/Backend/FrontendTesting/LoginTesting.cs b/Backend/FrontendTesting/LoginTesting.cs
index 185c162..3bcd23b 100644
--- a/Backend/FrontendTesting/LoginTesting.cs
+++ b/Backend/FrontendTesting/LoginTesting.cs
@@ -16,6 +16,7 @@ namespace FrontendTesting
     [TestClass]
     public class LoginTesting
     {
+        //defining variables needed for testing
         public string url = "http://localhost:3000/login";
         public By usernameField = By.Id("login_username");
         public By passwordField = By.Id("login_password");
@@ -26,7 +27,15 @@ namespace FrontendTesting
         public string[] passwords = { "aaa", "bbb", "ccc" };
 
 
+        /**
+         Names of tests should be self-explanatory
+        tests are separated, becouse there were problems with multiple tests runs in one method
+        tests contain thread.sleep becouse of waiting on components to load (if I find better and reasonable solution, I will change it)
+         */
+
+
         [TestMethod]
+        //dummy method for constructing tests
         public void Login_Dummy()
         {
             var driver = Drivers.cDriver;
@@ -50,14 +59,14 @@ namespace FrontendTesting
         public void Login_Correct_Annotator_Firefox()
         {
             var driver = new FirefoxDriver();
-            driver.Navigate().GoToUrl(url);                             //zakladni stranka
+            driver.Navigate().GoToUrl(url);                                     //zakladni stranka
             Thread.Sleep(3000);
-            driver.FindElement(usernameField).SendKeys(usernames[0]);          //enter username
-            driver.FindElement(passwordField).SendKeys(passwords[0]);          //enter password
-            driver.FindElement(loginButton).Click();                    //click on login
+            driver.FindElement(usernameField).SendKeys(usernames[0]);           //enter username
+            driver.FindElement(passwordField).SendKeys(passwords[0]);           //enter password
+            driver.FindElement(loginButton).Click();                            //click on login
             Thread.Sleep(3000);
-            Assert.AreEqual(driver.Url, "http://localhost:3000/documents/annotator");
-            driver.Navigate().GoToUrl(url);
+            Assert.AreEqual(driver.Url, "http://localhost:3000/documents/annotator");   //check if your url is changed on this
+            driver.Navigate().GoToUrl(url);                                     //return back on login screen (effectively logout, becouse logout button was too hard to click)
             driver.Close();
             driver.Quit();
         }
@@ -71,8 +80,8 @@ namespace FrontendTesting
             driver.FindElement(passwordField).SendKeys(passwords[2]);          //enter password
             driver.FindElement(loginButton).Click();                    //click on login
             Thread.Sleep(3000);
-            Assert.AreEqual(driver.Url, "http://localhost:3000/documents/admin");
-            driver.Navigate().GoToUrl(url);
+            Assert.AreEqual(driver.Url, "http://localhost:3000/documents/admin");   //check if url changed
+            driver.Navigate().GoToUrl(url);                                     //return back on login screen (effectively logout, becouse logout button was too hard to click)
             driver.Close();
             driver.Quit();
         }
@@ -86,8 +95,8 @@ namespace FrontendTesting
             driver.FindElement(passwordField).SendKeys(passwords[0]);          //enter password
             driver.FindElement(loginButton).Click();                    //click on login
             Thread.Sleep(3000);
-            Assert.AreEqual(driver.Url, "http://localhost:3000/documents/annotator");
-            driver.Navigate().GoToUrl(url);
+            Assert.AreEqual(driver.Url, "http://localhost:3000/documents/annotator");   //check if url changed
+            driver.Navigate().GoToUrl(url);                                     //return back on login screen (effectively logout, becouse logout button was too hard to click)
             driver.Close();
             driver.Quit();
         }
@@ -101,8 +110,8 @@ namespace FrontendTesting
             driver.FindElement(passwordField).SendKeys(passwords[2]);          //enter password
             driver.FindElement(loginButton).Click();                    //click on login
             Thread.Sleep(3000);
-            Assert.AreEqual(driver.Url, "http://localhost:3000/documents/admin");
-            driver.Navigate().GoToUrl(url);
+            Assert.AreEqual(driver.Url, "http://localhost:3000/documents/admin");   //check if url changed
+            driver.Navigate().GoToUrl(url);                                     //return back on login screen (effectively logout, becouse logout button was too hard to click)
             driver.Close();
             driver.Quit();
         }
@@ -118,7 +127,7 @@ namespace FrontendTesting
             driver.FindElement(passwordField).SendKeys("abc");          //enter password
             driver.FindElement(loginButton).Click();                    //click on login
             Thread.Sleep(3000);
-            Assert.AreEqual(driver.Url, "http://localhost:3000/login");
+            Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
             Thread.Sleep(3000);
             driver.Close();
             driver.Quit();
@@ -133,7 +142,7 @@ namespace FrontendTesting
             driver.FindElement(passwordField).SendKeys("abc");          //enter password
             driver.FindElement(loginButton).Click();                    //click on login
             Thread.Sleep(3000);
-            Assert.AreEqual(driver.Url, "http://localhost:3000/login");
+            Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
             Thread.Sleep(3000);
             driver.Close();
             driver.Quit();
@@ -148,7 +157,7 @@ namespace FrontendTesting
             driver.FindElement(passwordField).SendKeys("abc");          //enter password
             driver.FindElement(loginButton).Click();                    //click on login
             Thread.Sleep(3000);
-            Assert.AreEqual(driver.Url, "http://localhost:3000/login");
+            Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
             Thread.Sleep(3000);
             driver.Close();
             driver.Quit();
@@ -163,7 +172,7 @@ namespace FrontendTesting
             driver.FindElement(passwordField).SendKeys("abc");          //enter password
             driver.FindElement(loginButton).Click();                    //click on login
             Thread.Sleep(3000);
-            Assert.AreEqual(driver.Url, "http://localhost:3000/login");
+            Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
             Thread.Sleep(3000);
             driver.Close();
             driver.Quit();
@@ -178,7 +187,7 @@ namespace FrontendTesting
             driver.FindElement(passwordField).SendKeys("abc");          //enter password
             driver.FindElement(loginButton).Click();                    //click on login
             Thread.Sleep(3000);
-            Assert.AreEqual(driver.Url, "http://localhost:3000/login");
+            Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
             Thread.Sleep(3000);
             driver.Close();
             driver.Quit();
@@ -193,7 +202,7 @@ namespace FrontendTesting
             driver.FindElement(passwordField).SendKeys("abc");          //enter password
             driver.FindElement(loginButton).Click();                    //click on login
             Thread.Sleep(3000);
-            Assert.AreEqual(driver.Url, "http://localhost:3000/login");
+            Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
             Thread.Sleep(3000);
             driver.Close();
             driver.Quit();
@@ -208,7 +217,7 @@ namespace FrontendTesting
             driver.FindElement(passwordField).SendKeys("");          //enter password
             driver.FindElement(loginButton).Click();                    //click on login
             Thread.Sleep(3000);
-            Assert.AreEqual(driver.Url, "http://localhost:3000/login");
+            Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
             Thread.Sleep(3000);
             driver.Close();
             driver.Quit();
@@ -223,7 +232,7 @@ namespace FrontendTesting
             driver.FindElement(passwordField).SendKeys("");          //enter password
             driver.FindElement(loginButton).Click();                    //click on login
             Thread.Sleep(3000);
-            Assert.AreEqual(driver.Url, "http://localhost:3000/login");
+            Assert.AreEqual(driver.Url, "http://localhost:3000/login"); //check if url didn change and user was not logged in
             Thread.Sleep(3000);
             driver.Close();
             driver.Quit();
diff --git a/Backend/FrontendTesting/MainTestingClass.cs b/Backend/FrontendTesting/MainTestingClass.cs
new file mode 100644
index 0000000..94fa61c
--- /dev/null
+++ b/Backend/FrontendTesting/MainTestingClass.cs
@@ -0,0 +1,14 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace FrontendTesting
+{
+    [TestClass]
+    public class MainTestingClass
+    {
+        [TestMethod]
+        public void RunAll()
+        {
+            
+        }
+    }
+}
\ No newline at end of file
diff --git a/Backend/FrontendTesting/UnitTest1.cs b/Backend/FrontendTesting/UnitTest1.cs
deleted file mode 100644
index 41bf2df..0000000
--- a/Backend/FrontendTesting/UnitTest1.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace FrontendTesting
-{
-    [TestClass]
-    public class UnitTest1
-    {
-        [TestMethod]
-        public void TestMethod1()
-        {
-        }
-    }
-}
\ No newline at end of file
