Exemple #1
0
 /// <summary>
 /// Method that saves company data into the 'companydetails' table.
 /// </summary>
 /// <param name="companyDetails"></param>
 public void saveCompany(companydetail companyDetails)
 {
     using (var context = new TreasureHuntEntities())
     {
         context.companydetails.AddObject(companyDetails);
         context.SaveChanges();
         context.ObjectStateManager.ChangeObjectState(companyDetails, System.Data.EntityState.Added);
     }
 }
        public void ShouldRegisterUserIfNonExistingEmailAddress()
        {
            #region Setup
            user newUser = new user();
            newUser.Email    = "*****@*****.**";
            newUser.Password = "******";
            newUser.Name     = "name";

            EmailAddress = newUser.Email;
            Password     = newUser.Password;
            Name         = newUser.Name;

            user existingUser = new user();
            existingUser.Name     = "myFakeName";
            existingUser.Password = "******";
            existingUser.Email    = "*****@*****.**";

            List <user> listOfUsers = new List <user>();
            listOfUsers.Add(existingUser);

            List <companydetail> listOfCompanies = new List <companydetail>();

            companydetail fakeCompany = new companydetail();
            fakeCompany.CompanyName     = "Fake company";
            fakeCompany.CompanyPassword = "******";
            fakeCompany.UserId          = 1;
            fakeCompany.CompanyId       = 1;

            listOfCompanies.Add(fakeCompany);

            CompanyName     = "Company Name";
            CompanyPassword = fakeCompany.CompanyPassword;

            securityquestion question = new securityquestion();
            question.SecurityQuestionId = 1;
            CurrentSecurityQuestion     = question;
            SecurityAnswer = "answer";

            long id = 1;
            #endregion

            serviceClient.Setup(s => s.GetExistingUsersAsync()).Returns(Task.FromResult(listOfUsers.ToArray()));
            serviceClient.Setup(s => s.SaveUserAsync(It.IsAny <user>())).Returns(Task.FromResult(id));
            serviceClient.Setup(s => s.saveCompanyAsync(It.IsAny <companydetail>())).Returns(Task.FromResult(""));
            serviceClient.Setup(s => s.SaveUserRoleAsync(It.IsAny <userrole>())).Returns(Task.FromResult(""));
            serviceClient.Setup(s => s.getExistingCompaniesAsync()).Returns(Task.FromResult(listOfCompanies.ToArray()));
            serviceClient.Setup(s => s.SaveUserSecurityQuestionAsync(It.IsAny <usersecurityquestion>())).Returns(Task.FromResult(""));

            viewModel.ExecuteRegisterUserCommand();

            serviceClient.Verify(s => s.GetExistingUsersAsync(), Times.Exactly(1));
            serviceClient.Verify(s => s.SaveUserRoleAsync(It.IsAny <userrole>()), Times.Exactly(1));
            serviceClient.Verify(s => s.getExistingCompaniesAsync(), Times.Exactly(1));
            serviceClient.Verify(s => s.saveCompanyAsync(It.IsAny <companydetail>()), Times.Exactly(1));
            serviceClient.Verify(s => s.SaveUserSecurityQuestionAsync(It.IsAny <usersecurityquestion>()), Times.Exactly(1));
            serviceClient.Verify(s => s.SaveUserAsync(It.IsAny <user>()), Times.Exactly(1));
        }
Exemple #3
0
        /// <summary>
        /// Method that will attempt to save the new admininistrator and their details into the datbase.
        /// </summary>
        /// <param name="newUser"></param>
        private async void SaveUser(user newUser)
        {
            //Save the new user in the database
            long userId = await this.serviceClient.SaveUserAsync(newUser);

            //Save their company details in the database
            companydetail newCompany = new companydetail();

            newCompany.UserId          = userId;
            newCompany.CompanyName     = this.companyName;
            newCompany.CompanyPassword = this.companyPassword;

            await this.serviceClient.saveCompanyAsync(newCompany);

            //Save this new user as an administrative user in the database
            userrole newUserRole = new userrole();

            newUserRole.UserId = userId;
            newUserRole.RoleId = 1;

            await this.serviceClient.SaveUserRoleAsync(newUserRole);

            //Saving their security question and answer in the database
            usersecurityquestion newSecurityQuestion = new usersecurityquestion();

            newSecurityQuestion.UserId             = userId;
            newSecurityQuestion.SecurityQuestionId = CurrentSecurityQuestion.SecurityQuestionId;
            newSecurityQuestion.Answer             = SecurityAnswer;
            await this.serviceClient.SaveUserSecurityQuestionAsync(newSecurityQuestion);

            PopupDisplayed = false;

            MessageBoxResult messageBox = MessageBox.Show("You have successfully registered!", "Success");

            Messenger.Default.Send <UpdateViewMessage>(new UpdateViewMessage()
            {
                UpdateViewTo = "LoginViewModel"
            });

            EmailAddress    = String.Empty;
            Password        = String.Empty;
            Name            = String.Empty;
            CompanyName     = String.Empty;
            CompanyPassword = String.Empty;
            securityAnswer  = String.Empty;
        }
        public void ShouldRegisterUserIfNonExistingEmailAddress()
        {
            #region Setup
            user newUser = new user();
            newUser.Email = "*****@*****.**";
            newUser.Password = "******";
            newUser.Name = "name";

            EmailAddress = newUser.Email;
            Password = newUser.Password;
            Name = newUser.Name;

            user existingUser = new user();
            existingUser.Name = "myFakeName";
            existingUser.Password = "******";
            existingUser.Email = "*****@*****.**";

            List<user> listOfUsers = new List<user>();
            listOfUsers.Add(existingUser);

            List<companydetail> listOfCompanies = new List<companydetail>();

            companydetail fakeCompany = new companydetail();
            fakeCompany.CompanyName = "Fake company";
            fakeCompany.CompanyPassword = "******";
            fakeCompany.UserId = 1;
            fakeCompany.CompanyId = 1;

            listOfCompanies.Add(fakeCompany);

            CompanyName = "Company Name";
            CompanyPassword = fakeCompany.CompanyPassword;

            securityquestion question = new securityquestion();
            question.SecurityQuestionId = 1;
            CurrentSecurityQuestion = question;
            SecurityAnswer = "answer";

            long id = 1;
            #endregion

            serviceClient.Setup(s => s.GetExistingUsersAsync()).Returns(Task.FromResult(listOfUsers.ToArray()));
            serviceClient.Setup(s => s.SaveUserAsync(It.IsAny<user>())).Returns(Task.FromResult(id));
            serviceClient.Setup(s => s.saveCompanyAsync(It.IsAny<companydetail>())).Returns(Task.FromResult(""));
            serviceClient.Setup(s => s.SaveUserRoleAsync(It.IsAny<userrole>())).Returns(Task.FromResult(""));
            serviceClient.Setup(s => s.getExistingCompaniesAsync()).Returns(Task.FromResult(listOfCompanies.ToArray()));
            serviceClient.Setup(s => s.SaveUserSecurityQuestionAsync(It.IsAny<usersecurityquestion>())).Returns(Task.FromResult(""));

            viewModel.ExecuteRegisterUserCommand();

            serviceClient.Verify(s => s.GetExistingUsersAsync(), Times.Exactly(1));
            serviceClient.Verify(s => s.SaveUserRoleAsync(It.IsAny<userrole>()), Times.Exactly(1));
            serviceClient.Verify(s => s.getExistingCompaniesAsync(), Times.Exactly(1));
            serviceClient.Verify(s => s.saveCompanyAsync(It.IsAny<companydetail>()), Times.Exactly(1));
            serviceClient.Verify(s => s.SaveUserSecurityQuestionAsync(It.IsAny<usersecurityquestion>()), Times.Exactly(1));
            serviceClient.Verify(s => s.SaveUserAsync(It.IsAny<user>()), Times.Exactly(1));
        }
        /// <summary>
        /// Method that will attempt to save the new admininistrator and their details into the datbase.
        /// </summary>
        /// <param name="newUser"></param>
        private async void SaveUser(user newUser)
        { 
            //Save the new user in the database
            long userId = await this.serviceClient.SaveUserAsync(newUser);

            //Save their company details in the database
            companydetail newCompany = new companydetail();
            newCompany.UserId = userId;
            newCompany.CompanyName = this.companyName;
            newCompany.CompanyPassword = this.companyPassword;

            await this.serviceClient.saveCompanyAsync(newCompany);

            //Save this new user as an administrative user in the database
            userrole newUserRole = new userrole();
            newUserRole.UserId = userId;
            newUserRole.RoleId = 1;

            await this.serviceClient.SaveUserRoleAsync(newUserRole);

            //Saving their security question and answer in the database
            usersecurityquestion newSecurityQuestion = new usersecurityquestion();
            newSecurityQuestion.UserId = userId;
            newSecurityQuestion.SecurityQuestionId = CurrentSecurityQuestion.SecurityQuestionId;
            newSecurityQuestion.Answer = SecurityAnswer;
            await this.serviceClient.SaveUserSecurityQuestionAsync(newSecurityQuestion);

            PopupDisplayed = false;
         
            MessageBoxResult messageBox = MessageBox.Show("You have successfully registered!", "Success");

            Messenger.Default.Send<UpdateViewMessage>(new UpdateViewMessage() { UpdateViewTo = "LoginViewModel" });

            EmailAddress = String.Empty;
            Password = String.Empty;
            Name = String.Empty;
            CompanyName = String.Empty;
            CompanyPassword = String.Empty;
            securityAnswer = String.Empty ;
        }