Beispiel #1
0
        public void UpdateUserTest()
        {
            UsersSqlDAO dao = new UsersSqlDAO(connectionString);
            string      updatedFirstName = "Jane";
            string      updatedLastName  = "Doe";
            string      updatedRole      = "Admin";

            User testUser = new User();

            testUser.FirstName = "John";
            testUser.LastName  = "Smith";
            testUser.Username  = "******";
            testUser.Role      = "User";
            testUser.Password  = "******";
            testUser.Salt      = "salt";

            dao.AddUser(testUser);

            User updatedTestUser = new User();

            updatedTestUser.FirstName = "Jane";
            updatedTestUser.LastName  = "Doe";
            updatedTestUser.Username  = "******";
            updatedTestUser.Role      = "Admin";
            updatedTestUser.Password  = "******";
            updatedTestUser.Salt      = "salt";

            dao.UpdateUser(updatedTestUser);

            User finalUser = new User();

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(getUserSql, conn);
                cmd.Parameters.AddWithValue("@userName", testUser.Username);

                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    User tempUser = new User();
                    tempUser.Role      = Convert.ToString(reader["role"]);
                    tempUser.FirstName = Convert.ToString(reader["firstname"]);
                    tempUser.LastName  = Convert.ToString(reader["lastname"]);

                    finalUser = tempUser;
                }
            }

            Assert.AreEqual(updatedRole, finalUser.Role);
            Assert.AreEqual(updatedFirstName, finalUser.FirstName);
            Assert.AreEqual(updatedLastName, finalUser.LastName);
        }
Beispiel #2
0
        public void AddUserTest()
        {
            int originalRowCount = GetRowCount("users");

            UsersSqlDAO dao = new UsersSqlDAO(connectionString);

            User testUser = new User();

            testUser.FirstName = "John";
            testUser.LastName  = "Smith";
            testUser.Username  = "******";
            testUser.Role      = "User";
            testUser.Password  = "******";
            testUser.Salt      = "salt";

            dao.AddUser(testUser);

            int expectedRowCount = GetRowCount("users");

            Assert.AreEqual(originalRowCount + 1, expectedRowCount);
        }