Ejemplo n.º 1
0
        public void SingleCreateUser_Pass(int sysID, string fName, string lName, string email,
                                          string password, string salt, string accntType, bool accountStatus, string errMsg)
        {
            // Arrange
            User      invokingUser = new User(sysID, fName, lName, email, password, salt, "System Admin", accountStatus, errMsg);
            User      operatedUser = new User(114, fName, lName, email, password, null, accntType, true, null);
            var       expected     = operatedUser;
            User      actual       = null;
            Stopwatch stopwatch    = new Stopwatch();

            // Act
            try
            {
                stopwatch.Start();
                // System admin creates an admin
                actual = _userManagementManager.SingleCreateUsers(invokingUser, operatedUser);
                stopwatch.Stop();
            }
            catch (ArgumentException)
            {
            }
            catch (Exception) { }


            Console.WriteLine("Elapsed = {0} ms", stopwatch.ElapsedMilliseconds);

            // Assert
            Assert.AreEqual(expected, actual);

            // Delete user to clean database
            ResetDB();
        }
Ejemplo n.º 2
0
        public void SingleUpdateUser_Pass(int sysID, string fName, string lName, string email,
                                          string password, string salt, string accntType, bool accountStatus, string errMsg)
        {
            // Arrange

            // Initializing User objects to test

            // User to update in DB
            User user = new User(sysID, fName, lName, email, password, salt, accntType, accountStatus, errMsg);

            // User performing operation
            User thisUser = new User(109, null, null, null, "meMEeiaj093QNGEJOW~~~", null, "System Admin", true, null);
            var  um       = new UserManagementManager();
            bool result;

            // Act
            um.SingleCreateUsers(thisUser, user);
            try
            {
                string nameChange = "Bob";
                user.FirstName = nameChange;                                       //attempts to change the user's name to Bob
                result         = um.SingleUpdateUser(thisUser, user, "FirstName"); //then pushes the update
                //TODO: wait... shouldnt we test to see IF our DB is changing values?
            }
            catch (ArgumentException)
            {
                result = false;
            }
            catch (Exception) { result = false; }

            // Assert
            Assert.IsTrue(result);
        }
Ejemplo n.º 3
0
        public IActionResult SingleCreateUser(User operatedUser, string accountType)
        {
            User invokingUser = new User(6, null, null, null, null, null, accountType, true, null);

            try
            {
                return(Ok(_userManagementManager.SingleCreateUsers(invokingUser, operatedUser)));
            }
            catch
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
        public IActionResult RegisterNewUser(RegistrationInput userInput)
        {
            try
            {
                User user = new User(userInput);
                // HACK: this is fixed in another branch, so for now this will HOPEFULLY
                // keep away any possible collisions. when that happend comment out the next 2 lines.
                //Random rnd = new Random();
                //user.SystemID = rnd.Next(Int32.MinValue, Int32.MaxValue);

                //HACK: due to time constraints, I realised that gamer tags need to be unique.
                GamerInfo verifyGamer = _gamerDataAccess.GetGamerInfo(new GamerInfo(null, userInput.GamerTag, 0, 0));
                if (verifyGamer == null)
                {
                    _userManagementManager.SingleCreateUsers(doAsUser.systemAdmin(), user);
                    _userManagementManager.updateGamerTag(user, userInput.GamerTag);
                }
                else
                {
                    user.ErrorMessage = "Gamer tag is already in use";
                }
                ContentResult serverReply = Content(user.ErrorMessage);

                switch (user.ErrorMessage)
                {
                case "Invalid permissions":
                    serverReply.StatusCode = StatusCodes.Status401Unauthorized; break;

                case "Password is not secured":
                case "ID already exists":
                case "Email already registered":
                case "Email malformed":
                case "Invalid names":
                case "Gamer tag is already in use":
                    serverReply.StatusCode = StatusCodes.Status400BadRequest; break;

                case "Email failed to register":
                    serverReply.StatusCode = StatusCodes.Status500InternalServerError; break;

                default:
                    serverReply.StatusCode = StatusCodes.Status200OK;
                    break;
                }
                return(serverReply);
            }
            catch (ArgumentException)
            {
                return(StatusCode(StatusCodes.Status400BadRequest));
            }
        }