Пример #1
0
        public void CreateUserTest()
        {
            User testUser = new User
            {
                Name     = "Merkle Chowbuster",
                Password = "******",
                Salt     = "RrQlUO2CbmowsGDSpRhXZA==",
                Role     = "Users",
                Username = "******"
            };

            dao.CreateUser(testUser);

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();
                SqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = @"select * from UserLogin where userName = '******'";
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    testUser.Name     = (string)reader["first_Last_Name"];
                    testUser.Role     = (string)reader["userRole"];
                    testUser.Password = (string)reader["password"];
                }
            }

            Assert.AreEqual("Users", testUser.Role);
        }
        public void Assignment_UpdateUser_Test()
        {
            //Arrange
            UserSqlDAL dao = new UserSqlDAL(ConnectionString);

            User inputUser = new User();

            inputUser.Password = "******";
            inputUser.Salt     = "NuE0Y6FonAI=";
            inputUser.Role     = "Teacher";
            inputUser.Username = "******";


            dao.CreateUser(inputUser);

            inputUser = dao.GetUser(inputUser.Username);

            inputUser.Role = "Admin";
            dao.UpdateUser(inputUser);

            //Action
            User testUser = dao.GetUser(inputUser.Username);

            //Assert
            Assert.AreEqual(testUser.Role, inputUser.Role);
        }
        public void Assignment_DeleteUser_Test()
        {
            //Arrange
            UserSqlDAL dao = new UserSqlDAL(ConnectionString);

            User inputUser = new User();

            inputUser.Password = "******";
            inputUser.Salt     = "NuE0Y6FonAI=";
            inputUser.Role     = "Teacher";
            inputUser.Username = "******";


            dao.CreateUser(inputUser);

            int test = GetRowCount("users");

            inputUser = dao.GetUser(inputUser.Username);
            //Action
            dao.DeleteUser(inputUser);
            int result = GetRowCount("users");

            //Assert
            Assert.AreEqual(result, test - 1);
        }
Пример #4
0
        /// <summary>
        /// Creates a new user and saves their username in session.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="role"></param>
        /// <returns></returns>
        public void Register(string userEmail, string password, string role)
        {
            var hashProvider = new HashProvider();
            var passwordHash = hashProvider.HashPassword(password);

            var user = new UserProfile
            {
                UserEmail    = userEmail,
                UserPassword = passwordHash.Password,
                Salt         = passwordHash.Salt,
                Role         = role
            };

            userDAL.CreateUser(user);
            Session.SetString(SessionKey, user.UserEmail);
        }
Пример #5
0
        public ActionResult CreateProfile(UserProfile userProfile)
        {
            var checkExists = userSqlDAL.GetUser(userProfile.UserEmail);

            if (checkExists != null)
            {
                return(View("CreateProfileUserNameTaken"));
            }

            var hashedPasswordAndSalt = hashProvider.HashPassword(userProfile.UserPassword);

            userProfile.UserPassword = hashedPasswordAndSalt.Password;
            userProfile.Salt         = hashedPasswordAndSalt.Salt;
            userSqlDAL.CreateUser(userProfile);
            SaveUserSession(userProfile.UserEmail);


            return(RedirectToAction("Survey", "Home")); //Jarrod: changed this to redirect to the survey, before it was going to profile and crashing because they hadnt made a profile yet
        }
Пример #6
0
        public void CreateUserTest()
        {
            UserSqlDAL dal  = new UserSqlDAL(ConnectionString);
            User       user = new User();

            //populates our fake user with info
            user.BirthDate = new DateTime(2018, 1, 15);
            user.Email     = "*****@*****.**";
            user.HomeCity  = "pittsburgh";
            user.HomeState = "PA";

            user.PasswordHash = "fake";
            user.Salt         = "testSalt";

            user.SelfDescription   = "testdescription";
            user.Username          = "******";
            user.ListOfInstruments = new List <Instrument>();
            Instrument horn = new Instrument("Horn");

            Instrument violin = new Instrument("Violin");

            Instrument viola = new Instrument("Viola");


            user.ListOfInstruments.Add(horn);
            user.ListOfInstruments.Add(violin);
            user.ListOfInstruments.Add(viola);

            Place firstPlace  = new Place("foo", "bar", DateTime.Today, DateTime.Today);
            Place secondPlace = new Place("fooburgh", "barland", DateTime.Today, DateTime.Today);

            user.ListOfPlaces = new List <Place>();
            user.ListOfPlaces.Add(firstPlace);
            user.ListOfPlaces.Add(secondPlace);

            dal.CreateUser(user);

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                string     cmdText   = "SELECT email FROM users WHERE username = '******'";
                SqlCommand command   = new SqlCommand(cmdText, connection);
                string     userEmail = Convert.ToString(command.ExecuteScalar());

                cmdText = "SELECT ID FROM users WHERE username = '******'";
                command = new SqlCommand(cmdText, connection);
                string userId = Convert.ToString(command.ExecuteScalar());


                cmdText = $"SELECT instrument_name FROM Instruments_Played WHERE user_id = '{userId}' ORDER BY instrument_name ASC";
                command = new SqlCommand(cmdText, connection);
                string userInstrument = Convert.ToString(command.ExecuteScalar());

                cmdText = $"SELECT from_date FROM PLaces WHERE user_id = '{userId}'";
                command = new SqlCommand(cmdText, connection);
                string userDate = Convert.ToString(command.ExecuteScalar());

                Assert.AreEqual("*****@*****.**", $"{userEmail}");
                Assert.AreEqual("Horn", $"{userInstrument}");
                Assert.AreEqual($"{DateTime.Today}", actual: $"{userDate}");
            }
        }