Exemplo n.º 1
0
        public APIReturnObject register(int userId, String email, String name, string password)
        {
            if (!Regex.IsMatch(name, NAME_REGEX))
            {
                return(_returnBridge.mapToAPIReturnObjectFrom(new ReturnObject(false, "Invalid Username.")));
            }
            if (!Regex.IsMatch(email, EMAIL_REGEX))
            {
                return(_returnBridge.mapToAPIReturnObjectFrom(new ReturnObject(false, "Invalid Email.")));
            }
            if (!Regex.IsMatch(password, PASSWORD_REGEX))
            {
                return(_returnBridge.mapToAPIReturnObjectFrom(new ReturnObject(false, "Invalid Password.")));
            }

            string       hashedPassword = BCrypt.Net.BCrypt.HashPassword(password);
            ReturnObject returnObject   = _registerUser.registerUser(userId, email, hashedPassword, name);
            UserEntity   newUser        = _viewUser.getUserbyEmail(email);

            if (returnObject.isSuccess())
            {
                _context.UserModel.Add(new UserModel());
                _context.HistoryModel.Add(new HistoryModel(_viewUser.getHistory(userId).Id, 0, 0, newUser.getId()));
                _context.SaveChanges();
            }

            return(_returnBridge.mapToAPIReturnObjectFrom(returnObject));
        }
Exemplo n.º 2
0
        public void getHistoryTest()
        {
            var userRepositoryMock = new UserRepositoryMock();
            var viewUser           = new ViewUser(userRepositoryMock);

            var returnObject = viewUser.getHistory(0);
            var expected     = new HistoryEntity(0, 0);

            Assert.AreEqual(expected.GetType(), returnObject.GetType());
        }