public void CreateMultipleAccountPass()
        {
            //Arrange
            bool expected = true;
            //Act
            List <Account> testAccounts = new List <Account>();

            for (int i = 0; i < 10; i++)
            {
                Account testAccount = new Account("testerEmail" + i, "testHashedPassword", "testSalt");
                testAccounts.Add(testAccount);
                DeleteUser(testAccount.UserEmail);
                DeleteMapping(testAccount.UserEmail);
                DeleteAccount(testAccount.UserEmail);
            }

            CreateAccountDAOs     daos = new CreateAccountDAOs(newAccountDAO, newMappingDAO, newUserDAO, mapperDAO);
            ICreateAccountService cas  = new SqlCreateAccountService(testAccounts, daos);
            IResult result             = cas.Create();
            bool    actual             = result.IsSuccess;

            foreach (Account testAccount in testAccounts)
            {
                DeleteUser(testAccount.UserEmail);
                DeleteMapping(testAccount.UserEmail);
                DeleteAccount(testAccount.UserEmail);
            }

            Console.WriteLine(result.Message);
            //Assert
            Assert.AreEqual(expected, actual);
        }
        public void CreateAccountNotPass()
        {
            //Arrange
            bool expected = false; //var

            //Act
            Account testAccount = new Account("testerEmail", "testHashedPassword", "testSalt");

            //create test initialize method [TestInitialize]
            DeleteUser(testAccount.UserEmail);
            DeleteMapping(testAccount.UserEmail);
            DeleteAccount(testAccount.UserEmail);
            CreateAccountDAOs     daos = new CreateAccountDAOs(newAccountDAO, newMappingDAO, newUserDAO, mapperDAO);
            ICreateAccountService cas  = new SqlCreateAccountService(testAccount, daos); // expand var name

            cas.Create();                                                                //creating initial vector
            IResult result = cas.Create();                                               //creating duplicate record; rename AccountResult, CreationResult, etc.
            bool    actual = result.IsSuccess;

            //[TestCleanup]
            DeleteUser(testAccount.UserEmail);
            DeleteMapping(testAccount.UserEmail);
            DeleteAccount(testAccount.UserEmail);
            Console.WriteLine(result.Message); //TestContext.Write
            //Assert
            Assert.AreEqual(expected, actual);
        }
        //Create multiple accounts and users. Execute deletion of multiple users.
        public void DeleteMultipleUsers_Pass()
        {
            //Arrange
            bool expected = true;

            Account               testAccount = new Account("tester2Email", "testHashedPassword", "testSalt");
            CreateAccountDAOs     daos        = new CreateAccountDAOs(newAccountDAO, newMappingDAO, newUserDAO, mapperDAO);
            ICreateAccountService cas         = new SqlCreateAccountService(testAccount, daos);

            cas.Create();
            User testUser = new User(mapperDAO.GetSysID(testAccount.UserEmail), "tester2Email", "Collin", "Damarines", "Activated", DateTime.Now, "Male");

            Account testAccount2 = new Account("tester3Email", "testHashedPassword2", "testSalt");

            cas = new SqlCreateAccountService(testAccount2, daos);
            cas.Create();
            User testUser2 = new User(mapperDAO.GetSysID(testAccount2.UserEmail), "tester3Email", "Woodrow", "Buthavenopaddle", "Activated", DateTime.Now, "Male");

            List <User> testUsers = new List <User>();

            testUsers.Add(testUser);
            testUsers.Add(testUser2);

            //Act
            IDeleteAccountService deleter = new DeleteAccountSQLService(testUsers, systemDB, mappingDB, accountDB);
            IResult deleteResult          = deleter.Delete();
            bool    actual = deleteResult.IsSuccess;

            //Assert
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// Creates an account for testing
        /// </summary>
        /// <param name="email">Email of account</param>
        /// <param name="password">Password of account</param>
        /// <param name="salt">Password salt of account</param>
        private void CreateAccount(string userEmail, string password, string salt)
        {
            Account               testAccount = new Account(userEmail, password, salt);
            CreateAccountDAOs     daos        = new CreateAccountDAOs(_newAccountDAO, _newMappingDAO, _newUserDAO, _mapperDAO);
            ICreateAccountService cas         = new SqlCreateAccountService(testAccount, daos);

            cas.Create();
        }
示例#5
0
        private void CreateDummyAccount()
        {
            Account               testAccount = new Account("*****@*****.**", "testHashedPassword", "testSalt");
            CreateAccountDAOs     daos        = new CreateAccountDAOs(newAccountDAO, newMappingDAO, newUserDAO, mapperDAO);
            ICreateAccountService cas         = new SqlCreateAccountService(testAccount, daos);

            cas.Create();
        }
        /// <summary>
        /// Complete Registration for the user
        /// </summary>
        /// <returns>IResult the result of whole registration process</returns>
        public IResult RegisterUser()
        {
            string message = "";

            string   email    = registrationRequest.Email;
            string   fname    = registrationRequest.Firstname;
            string   lname    = registrationRequest.Lastname;
            DateTime dob      = registrationRequest.Dob;
            string   password = registrationRequest.Password;

            // Generate salt and hash password
            Hasher     hasher     = new Hasher(algorithm);
            HashObject hash       = hasher.GenerateSaltedHash(password);
            string     hashedPw   = hash.HashedValue;
            string     salt       = hash.Salt;
            Account    newAccount = new Account(email, hashedPw, salt);

            ICreateAccountDAO newAccountDAO = new SqlCreateAccountDAO(Environment.GetEnvironmentVariable("sqlConnectionAccount", EnvironmentVariableTarget.User));
            ICreateAccountDAO newMappingDAO = new SqlCreateAccountDAO(Environment.GetEnvironmentVariable("sqlConnectionMapping", EnvironmentVariableTarget.User));
            IMapperDAO        mapperDAO     = new SqlMapperDAO(Environment.GetEnvironmentVariable("sqlConnectionMapping", EnvironmentVariableTarget.User));
            ICreateAccountDAO newUserDAO    = new SqlCreateAccountDAO(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User));

            CreateAccountDAOs     daos = new CreateAccountDAOs(newAccountDAO, newMappingDAO, newUserDAO, mapperDAO);
            ICreateAccountService cas  = new SqlCreateAccountService(newAccount, daos);
            IResult checkResult        = cas.Create();

            message = message + checkResult.Message;
            bool ifSuccess = checkResult.IsSuccess;

            if (ifSuccess)
            {
                int sysID = mapperDAO.GetSysID(email);
                if (sysID != -1)
                {
                    ISqlDAO DAO     = new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User));
                    User    newUser = new User(sysID, email, fname, lname, "Enable", dob, "male");
                    UpdateAccountSqlService updateAccount = new UpdateAccountSqlService(newUser, DAO);
                    checkResult = updateAccount.Update();
                    message     = message + checkResult.Message;
                    ifSuccess   = checkResult.IsSuccess;
                }
                else
                {
                    ifSuccess = false;
                    message   = message + "failed to Retrieve sysID";
                }
            }

            return(new CheckResult(message, ifSuccess));
        }
 public UserManagementManager(JWTService authService, AuthenticationService authenticationService, SqlCreateAccountService createAccountService, DeleteAccountSQLService deleteAccountService, UpdateAccountSqlService updateAccountService, PermissionUpdateSqlService updatePermissionService)
 {
     //_newAccountDAO = new SqlCreateAccountDAO(Environment.GetEnvironmentVariable("sqlConnectionAccount", EnvironmentVariableTarget.User));
     //_newMappingDAO = new SqlCreateAccountDAO(Environment.GetEnvironmentVariable("sqlConnectionMapping", EnvironmentVariableTarget.User));
     //_newUserDAO = new SqlCreateAccountDAO(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User));
     //_mapperDAO = new SqlMapperDAO(Environment.GetEnvironmentVariable("sqlConnectionMapping", EnvironmentVariableTarget.User));
     //_systemDB = new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User));
     //_mappingDB = new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionMapping", EnvironmentVariableTarget.User));
     //_accountDB = new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionAccount", EnvironmentVariableTarget.User));
     _updatePermissionService = updatePermissionService;
     _updateAccountService    = updateAccountService;
     _createAccountService    = createAccountService;
     _deleteAccountService    = deleteAccountService;
     _authNService            = authenticationService;
     _authService             = authService;
 }
        public UserManagementManager()
        {
            var sqlDao           = new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User));
            var createAccountDAO = new SqlCreateAccountDAO(Environment.GetEnvironmentVariable("sqlConnectionAccount", EnvironmentVariableTarget.User));
            var newMappingDAO    = new SqlCreateAccountDAO(Environment.GetEnvironmentVariable("sqlConnectionMapping", EnvironmentVariableTarget.User));
            var newUserDAO       = new SqlCreateAccountDAO(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User));
            var mapperDAO        = new SqlMapperDAO(Environment.GetEnvironmentVariable("sqlConnectionMapping", EnvironmentVariableTarget.User));
            var bunchedDaos      = new CreateAccountDAOs(createAccountDAO, newMappingDAO, newUserDAO, mapperDAO);

            _updatePermissionService = new PermissionUpdateSqlService(new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User)), new SqlMapperDAO(Environment.GetEnvironmentVariable("sqlConnectionMapping", EnvironmentVariableTarget.User)));
            _updateAccountService    = new UpdateAccountSqlService(new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User)));
            _createAccountService    = new SqlCreateAccountService(bunchedDaos);
            _deleteAccountService    = new DeleteAccountSQLService(new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User)), new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionMapping", EnvironmentVariableTarget.User)), new SqlDAO(Environment.GetEnvironmentVariable("sqlConnectionAccount", EnvironmentVariableTarget.User)));
            _authNService            = new AuthenticationService(new GetUserDao(Environment.GetEnvironmentVariable("sqlConnectionSystem", EnvironmentVariableTarget.User)));
            _authService             = new JWTService();
        }
        public void HouseHoldCreateNotPassB()
        {
            //Arrange
            bool expected = false;
            //Act
            //Create a new testing user and then delete it
            Account testAccount = new Account("testerEmail", "testHashedPassword", "testSalt");

            DeleteUser(testAccount.UserEmail);
            DeleteMapping(testAccount.UserEmail);
            DeleteAccount(testAccount.UserEmail);

            CreateAccountDAOs     daos = new CreateAccountDAOs(newAccountDAO, newMappingDAO, newUserDAO, mapperDAO);
            ICreateAccountService cas  = new SqlCreateAccountService(testAccount, daos);
            HouseHoldManager      mr   = new HouseHoldManager();

            cas.Create();
            int sid = mapperDAO.GetSysID("testerEmail");

            User testUser = new User(sid, "testerEmail", "testerFname", "testerLname", "Enable", DateTime.Today, "Male");
            HouseholdCreationRequestDTO request = new HouseholdCreationRequestDTO
            {
                Requester     = "testerEmail",
                StreetAddress = "TestStreetAddress",
                City          = "TestCity",
                Zip           = 92868,
                SuiteNumber   = "TestSuiteNumber",
                Rent          = 1500.00
            };;
            IResult result = mr.CreateNewHouseHold(request);
            int     hID    = Int32.Parse(result.Message);

            result = mr.CreateNewHouseHold(request);
            Console.WriteLine(result.Message);
            DeleteUser(testAccount.UserEmail);
            DeleteMapping(testAccount.UserEmail);
            DeleteAccount(testAccount.UserEmail);
            mr.DeleteHouseHold(hID);
            bool actual = result.IsSuccess;

            //Assert
            Assert.AreEqual(expected, actual);
        }
        //Create a new acccount and a matching user. Execute deletion for a single user.
        public void DeleteSingleUser_Pass()
        {
            //Arrange
            bool expected = true;

            Account               testAccount = new Account("tester1Email", "testHashedPassword", "testSalt");
            CreateAccountDAOs     daos        = new CreateAccountDAOs(newAccountDAO, newMappingDAO, newUserDAO, mapperDAO);
            ICreateAccountService cas         = new SqlCreateAccountService(testAccount, daos);

            cas.Create();
            User testUser = new User(mapperDAO.GetSysID(testAccount.UserEmail), "tester1Email", "Collin", "Damarines", "Activated", DateTime.Now, "Male");

            //Act
            IDeleteAccountService deleter = new DeleteAccountSQLService(testUser, systemDB, mappingDB, accountDB);
            IResult deleteResult          = deleter.Delete();
            bool    actual = deleteResult.IsSuccess;

            Console.WriteLine(deleteResult.Message);

            //Assert
            Assert.AreEqual(expected, actual);
        }
        public void CreateAccountPass()
        {
            //Arrange
            bool expected = true;
            //Act
            Account testAccount = new Account("testerEmail", "testHashedPassword", "testSalt");

            DeleteUser(testAccount.UserEmail);
            DeleteMapping(testAccount.UserEmail);
            DeleteAccount(testAccount.UserEmail);

            CreateAccountDAOs     daos = new CreateAccountDAOs(newAccountDAO, newMappingDAO, newUserDAO, mapperDAO);
            ICreateAccountService cas  = new SqlCreateAccountService(testAccount, daos);
            IResult result             = cas.Create();
            bool    actual             = result.IsSuccess;

            DeleteUser(testAccount.UserEmail);
            DeleteMapping(testAccount.UserEmail);
            DeleteAccount(testAccount.UserEmail);
            Console.WriteLine(result.Message);
            //Assert
            Assert.AreEqual(expected, actual);
        }