Пример #1
0
        public async Task CleanUp()
        {
            IDataGateway                   dataGateway      = new SQLServerGateway();
            IConnectionStringData          connectionString = new ConnectionStringData();
            IUserAccountSettingsRepository userAccountSettingsRepository = new UserAccountSettingRepository(dataGateway, connectionString);

            var settings = await userAccountSettingsRepository.GetAllSettings();

            foreach (var setting in settings)
            {
                await userAccountSettingsRepository.DeleteUserAccountSettingsByUserId(setting.UserId);
            }

            await DataAccessTestHelper.ReseedAsync("UserAccountSettings", 0, connectionString, dataGateway);

            IUserAccountRepository userAccountRepository = new UserAccountRepository(dataGateway, connectionString);
            var accounts = await userAccountRepository.GetAllAccounts();

            foreach (var account in accounts)
            {
                await userAccountRepository.DeleteAccountById(account.Id);
            }

            await DataAccessTestHelper.ReseedAsync("UserAccount", 0, connectionString, dataGateway);
        }
        public async Task SetUserOfflineAsync_SetOffline_UserSetOffline(int userId)
        {
            IDataGateway              dataGateway              = new SQLServerGateway();
            IConnectionStringData     connectionString         = new ConnectionStringData();
            IPublicUserProfileRepo    publicUserProfileRepo    = new PublicUserProfileRepo(dataGateway, connectionString);
            IUserAccountRepository    userAccountRepository    = new UserAccountRepository(dataGateway, connectionString);
            IUserProfileRepository    userProfileRepository    = new UserProfileRepository(dataGateway, connectionString);
            IUserProfileService       userProfileService       = new UserProfileService(userProfileRepository);
            IUserAccountService       userAccountService       = new UserAccountService(userAccountRepository);
            IValidationService        validationService        = new ValidationService(userAccountService, userProfileService);
            IPublicUserProfileService publicUserProfileService = new PublicUserProfileService(publicUserProfileRepo, validationService);

            PublicUserProfileModel model = new PublicUserProfileModel();

            model.UserId = userId;
            try
            {
                await publicUserProfileService.CeatePublicUserProfileAsync(model);


                await publicUserProfileService.SetUserOnlineAsync(userId);


                await publicUserProfileService.SetUserOfflineAsync(userId);

                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false);
            }
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            var accountRepo = new UserAccountRepository();

            var loginAccount = new CIS_UserAccount();

            bool IsValid = false;

            if (accountRepo.IsCredentialValid(
                    this.input_Username.TextStringValue,
                    this.input_Password.TextStringValue,
                    out loginAccount))
            {
                IsValid           = true;
                this.LoginAccount = loginAccount;
            }
            if (this.input_Username.TextStringValue.Equals("Demo", StringComparison.CurrentCultureIgnoreCase) &&
                this.input_Password.TextStringValue.Equals("Pass", StringComparison.CurrentCultureIgnoreCase))
            {
                IsValid = true;
            }
            if (!IsValid)
            {
                MessageBox.Show(@"Invalid Username/Password.");
            }
            else
            {
                this.DialogResult = DialogResult.OK;
            }
        }
 public async Task CleanUp()
 {
     IDataGateway           dataGateway           = new SQLServerGateway();
     IConnectionStringData  connectionString      = new ConnectionStringData();
     IUserAccountRepository userAccountRepository = new UserAccountRepository(dataGateway, connectionString);
     await TestCleaner.CleanDatabase();
 }
Пример #5
0
 public PreferenceService(UserManager <UserAccount> userManager, IUnitOfWork unitOfWork)
 {
     this.userManager = userManager;
     userAccount      = unitOfWork.UserAccount;
     preferences      = unitOfWork.Preferences;
     saveChangesAsync = unitOfWork.SaveChangesAsync;
 }
Пример #6
0
        public async Task <IActionResult> DeleteUserAccount(
            [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "UserAccount/DeleteUserAccount")] HttpRequest req, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function(DeleteUserAccount) processed a request.");

            try
            {
                string requestBody            = await new StreamReader(req.Body).ReadToEndAsync();
                var    userAccountCreateModel = JsonConvert.DeserializeObject <UserAccountCreateModel>(requestBody);

                var loginManager = new LoginManager();
                var loginResult  = loginManager.AttemptLogin(userAccountCreateModel.EmailAddress, userAccountCreateModel.Password);

                if (loginResult.Status == LoginStatus.Success)
                {
                    var userAccountRepo = new UserAccountRepository();
                    userAccountRepo.DeleteUserAccount(loginResult.UserAccount.UserAccountId);

                    return(new OkObjectResult($"User {loginResult.UserAccount.EmailAddress}) has been deleted."));
                }
                else
                {
                    // maybe change this so there's only 1 fail condition instead of having Error & Failure
                    return(new BadRequestObjectResult(loginResult.FailureReason));
                }
            }
            catch (Exception exception)
            {
                return(new BadRequestObjectResult(exception.Message));
            }
        }
Пример #7
0
        public async Task GetChannelOwner_ChannelOwner_RetrievedChannelOwner(int ChannelId, int UserId, int OwnerId, string ChannelName, int NewUserId)
        {
            ChannelModel model = new ChannelModel();

            model.OwnerId = OwnerId;
            model.Name    = ChannelName;

            IDataGateway           dataGateway           = new SQLServerGateway();
            IConnectionStringData  connectionString      = new ConnectionStringData();
            IMessagesRepo          messagesRepo          = new MessagesRepo(dataGateway, connectionString);
            IChannelsRepo          channelsRepo          = new ChannelsRepo(dataGateway, connectionString);
            IUserAccountRepository userAccountRepository = new UserAccountRepository(dataGateway, connectionString);
            IUserChannelsRepo      userChannelsRepo      = new UserChannelsRepo(dataGateway, connectionString);
            IMessagingService      messagingService      = new MessagingService(messagesRepo, channelsRepo, userChannelsRepo, userAccountRepository);
            await messagingService.CreateChannelAsync(model);

            try
            {
                int ownerId = await messagingService.GetChannelOwnerAsync(ChannelId);

                if (ownerId == 1)
                {
                    Assert.IsTrue(true);
                }
                else
                {
                    Assert.IsTrue(false);
                }
            }
            catch
            {
                Assert.IsTrue(false);
            }
        }
Пример #8
0
        public async Task CreateAccount_ExecutionTimeLessThan400Milliseconds(int expectedId, string expectedUsername,
                                                                             string expectedPassword, string expectedSalt, string expectedEmailAddress, string expectedAccountType,
                                                                             string expectedAccountStatus, string expectedCreationDate, string expectedUpdationDate, long expectedMaxExecutionTime)
        {
            //Arrange
            UserAccountModel userAccountModel = new UserAccountModel();

            userAccountModel.Id            = expectedId;
            userAccountModel.Username      = expectedUsername;
            userAccountModel.Password      = expectedPassword;
            userAccountModel.Salt          = expectedSalt;
            userAccountModel.EmailAddress  = expectedEmailAddress;
            userAccountModel.AccountType   = expectedAccountType;
            userAccountModel.AccountStatus = expectedAccountStatus;
            userAccountModel.CreationDate  = DateTimeOffset.Parse(expectedCreationDate);
            userAccountModel.UpdationDate  = DateTimeOffset.Parse(expectedUpdationDate);

            IUserAccountRepository userAccountRepository = new UserAccountRepository(new SQLServerGateway(), new ConnectionStringData());

            //Act
            var timer = Stopwatch.StartNew();
            await userAccountRepository.CreateAccount(userAccountModel);

            timer.Stop();

            var actualExecutionTime = timer.ElapsedMilliseconds;

            Debug.WriteLine("Actual Execution Time: " + timer.Elapsed);

            //Assert
            Assert.IsTrue(actualExecutionTime <= expectedMaxExecutionTime);
        }
        public async Task GetAllUsersRegisteredToday_Countaccounts()
        {
            IDataGateway           dataGateway           = new SQLServerGateway();
            IConnectionStringData  connectionString      = new ConnectionStringData();
            IFriendListRepo        friendListRepo        = new FriendListRepo(dataGateway, connectionString);
            IFriendRequestListRepo friendRequestListRepo = new FriendRequestListRepo(dataGateway, connectionString);
            IUserAccountRepository userAccountRepository = new UserAccountRepository(dataGateway, connectionString);
            IFriendBlockListRepo   friendBlockListRepo   = new FriendBlockListRepo(dataGateway, connectionString);
            IPublicUserProfileRepo publicUserProfileRepo = new PublicUserProfileRepo(dataGateway, connectionString);
            IListingRepository     listingRepository     = new ListingRepository(dataGateway, connectionString);
            ILoginTrackerRepo      loginTrackerRepo      = new LoginTrackerRepo(dataGateway, connectionString);
            IPageVisitTrackerRepo  pageVisitTrackerRepo  = new PageVisitTrackerRepo(dataGateway, connectionString);
            ISearchTrackerRepo     searchTrackerRepo     = new SearchTrackerRepo(dataGateway, connectionString);
            IUserAnalysisService   userAnalysisService   = new UserAnalysisService(friendListRepo, listingRepository, userAccountRepository,
                                                                                   loginTrackerRepo, pageVisitTrackerRepo, friendRequestListRepo, searchTrackerRepo);


            int count = await userAnalysisService.GetAllUsersRegisteredToday();

            if (count != 20)
            {
                Assert.IsTrue(false);
            }
            Assert.IsTrue(true);
        }
Пример #10
0
        public async Task deleteMessage_MessageSentThenDeleted_MessageDeleted(int channelId, int userId, string message)
        {
            MessageModel model = new MessageModel();

            model.ChannelId = channelId;
            model.UserId    = userId;
            model.Message   = message;


            IDataGateway           dataGateway           = new SQLServerGateway();
            IConnectionStringData  connectionString      = new ConnectionStringData();
            IMessagesRepo          messagesRepo          = new MessagesRepo(dataGateway, connectionString);
            IChannelsRepo          channelsRepo          = new ChannelsRepo(dataGateway, connectionString);
            IUserAccountRepository userAccountRepository = new UserAccountRepository(dataGateway, connectionString);
            IUserChannelsRepo      userChannelsRepo      = new UserChannelsRepo(dataGateway, connectionString);
            IMessagingService      messagingService      = new MessagingService(messagesRepo, channelsRepo, userChannelsRepo, userAccountRepository);

            await messagingService.SendMessageAsync(model);

            await messagingService.DeleteMessageAsync(0);


            IEnumerable <MessageModel> models = await messagesRepo.GetAllMessagesByChannelIdAsync(channelId);

            if (models.Count() == 1)
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.IsTrue(false);
            }
        }
Пример #11
0
 public CoreEfCoreUnitOfWork(CoreEfCoreDbContext context) : base(context)
 {
     UserAccountRepository         = new UserAccountRepository(context);
     FeeTransactionRepository      = new FeeTransactionRepository(context);
     InternalTransactionRepository = new InternalTransactionRepository(context);
     TransferTransactionRepository = new TransferTransactionRepository(context);
 }
 public ComparisonService(UserManager <UserAccount> userManager, IUnitOfWork unitOfWork)
 {
     this.userManager = userManager;
     userAccount      = unitOfWork.UserAccount;
     comparisons      = unitOfWork.Comparisons;
     saveChangesAsync = unitOfWork.SaveChangesAsync;
 }
Пример #13
0
        public async Task GetUserByEmailInLoginProcess()
        {
            // Arrange
            var getEmail       = "*****@*****.**";
            var mockRepository = new Mock <IUserAccountRepository>();

            mockRepository.Setup(repo => repo.GetUserByEmail(getEmail))
            .ReturnsAsync(new User {
                Id = "1", Email = "*****@*****.**"
            });

            var mockUserManager   = GetUserManagerMock <User>();
            var mockRoleManager   = GetRoleManagerMock <IdentityRole>();
            var mockConfiguration = new Mock <IConfiguration>();

            var repository = new UserAccountRepository(_context, mockUserManager.Object, mockConfiguration.Object, mockRoleManager.Object);

            // Act
            var result = await repository.GetUserByEmail("*****@*****.**");

            Console.WriteLine("!!!!!!!!!RESULT " + result);
            // Assert
            Assert.NotNull(result);

            TearDown();
        }
Пример #14
0
        public LoginResult AttemptLogin(string emailAddress, string password)
        {
            try
            {
                if (!AccountExists(emailAddress))
                {
                    return(LoginResult.Failure("Email Address not found"));
                }

                // get UserAccount from database using the EmailAdress (to get salt & hash)
                var userAccountRepo = new UserAccountRepository();
                var userAccount     = userAccountRepo.GetUserAccountByEmailAddress(emailAddress);

                // validate password against salt & hash
                if (!PasswordManager.ValidatePassword(password, userAccount.Salt, userAccount.Hash))
                {
                    return(LoginResult.Failure("Wrong password"));
                }

                return(LoginResult.Success(userAccount));
            }
            catch (Exception exception)
            {
                return(LoginResult.Error(exception));
            }
        }
        public async Task ChangeFontSize_UsersFontSizeIsChanged_FontSizeSuccessfullyChanges(int userId, int FontSize)
        {
            IDataGateway                   dataGateway                   = new SQLServerGateway();
            IConnectionStringData          connectionString              = new ConnectionStringData();
            IUserAccountRepository         userAccountRepository         = new UserAccountRepository(dataGateway, connectionString);
            IUserAccountSettingsRepository userAccountSettingsRepository = new UserAccountSettingRepository(dataGateway, connectionString);
            ICryptographyService           cryptographyService           = new CryptographyService(userAccountRepository);
            IAuthenticationService         authenticationService         = new AuthenticationService(userAccountRepository);
            IAccountSettingsService        userAccountSettingsManager    = new AccountSettingsService(userAccountRepository, userAccountSettingsRepository, cryptographyService, authenticationService);

            bool result = await userAccountSettingsManager.ChangeFontSizeAsync(userId, FontSize);

            if (!result)
            {
                Assert.IsTrue(false);
            }
            await userAccountSettingsManager.ChangeFontSizeAsync(userId, FontSize);

            string newFontSize = await userAccountSettingsRepository.GetFontSizeByID(userId);

            if (FontSize.ToString() == newFontSize)
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.IsTrue(false);
            }
        }
Пример #16
0
        public async Task Init()
        {
            await TestCleaner.CleanDatabase();

            var numTestRows = 20;

            IDataGateway           dataGateway           = new SQLServerGateway();
            IConnectionStringData  connectionString      = new ConnectionStringData();
            IUserAccountRepository userAccountRepository = new UserAccountRepository(dataGateway, connectionString);

            for (int i = 1; i <= numTestRows; ++i)
            {
                UserAccountModel userAccountModel = new UserAccountModel();
                userAccountModel.Id            = i;
                userAccountModel.Username      = "******" + i;
                userAccountModel.Password      = "******" + i;
                userAccountModel.Salt          = "TestSalt" + i;
                userAccountModel.EmailAddress  = "TestEmailAddress" + i;
                userAccountModel.AccountType   = "TestAccountType" + i;
                userAccountModel.AccountStatus = "TestAccountStatus" + i;
                userAccountModel.CreationDate  = DateTimeOffset.UtcNow;
                userAccountModel.UpdationDate  = DateTimeOffset.UtcNow;

                await userAccountRepository.CreateAccount(userAccountModel);
            }
        }
        public async Task ChangeThemeColor_UsersThemeColorChanges_UsersThemeColorIsChangedSuccessfully(int userId, string ThemeColor)
        {
            IDataGateway                   dataGateway                   = new SQLServerGateway();
            IConnectionStringData          connectionString              = new ConnectionStringData();
            IUserAccountRepository         userAccountRepository         = new UserAccountRepository(dataGateway, connectionString);
            IUserAccountSettingsRepository userAccountSettingsRepository = new UserAccountSettingRepository(dataGateway, connectionString);
            ICryptographyService           cryptographyService           = new CryptographyService(userAccountRepository);
            IAuthenticationService         authenticationService         = new AuthenticationService(userAccountRepository);
            IAccountSettingsService        userAccountSettingsManager    = new AccountSettingsService(userAccountRepository, userAccountSettingsRepository, cryptographyService, authenticationService);

            bool result = await userAccountSettingsManager.ChangeThemeColorAsync(userId, ThemeColor);

            if (!result)
            {
                Assert.IsTrue(false);
            }
            await userAccountSettingsManager.ChangeThemeColorAsync(userId, ThemeColor);

            string newThemeColor = await userAccountSettingsRepository.GetThemeColorByID(userId);

            if (ThemeColor == newThemeColor)
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.IsTrue(false);
            }
        }
Пример #18
0
        public async Task GetAllAccounts_AtLeastTwoAccountsExist_ReturnsCorrectNumberOfAccounts(int numAccounts)
        {
            // Arrange
            IUserAccountRepository userAccountRepository = new UserAccountRepository(new SQLServerGateway(), new ConnectionStringData());

            // Act
            IEnumerable <UserAccountModel> userAccounts = await userAccountRepository.GetAllAccounts();

            // Assert
            int i = 1;

            foreach (UserAccountModel account in userAccounts)
            {
                if (account.Id == i)
                {
                    ++i;
                    continue;
                }
            }

            if (i == numAccounts + 1)
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.IsTrue(false);
            }
        }
        public async Task ChangeFontStyleAsync_UserFontStyleChange_UsersFontStyleChanges(int userId, string fontStyle)
        {
            IDataGateway                   dataGateway                   = new SQLServerGateway();
            IConnectionStringData          connectionString              = new ConnectionStringData();
            IUserAccountRepository         userAccountRepository         = new UserAccountRepository(dataGateway, connectionString);
            IUserAccountSettingsRepository userAccountSettingsRepository = new UserAccountSettingRepository(dataGateway, connectionString);
            ICryptographyService           cryptographyService           = new CryptographyService(userAccountRepository);
            IAuthenticationService         authenticationService         = new AuthenticationService(userAccountRepository);
            IAccountSettingsService        userAccountSettingsManager    = new AccountSettingsService(userAccountRepository, userAccountSettingsRepository, cryptographyService, authenticationService);

            bool result = await userAccountSettingsManager.ChangeFontStyleAsync(userId, fontStyle);

            if (!result)
            {
                Assert.IsTrue(false);
            }
            string newFontStyle = await userAccountSettingsRepository.GetFontStyleByID(userId);

            if (fontStyle == newFontStyle)
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.IsTrue(false);
            }
        }
        public async Task ChangeProfilePictureAsync_EditPhoto_PhotoSuccessfullyEdited(int userId, string photo)
        {
            IDataGateway              dataGateway              = new SQLServerGateway();
            IConnectionStringData     connectionString         = new ConnectionStringData();
            IPublicUserProfileRepo    publicUserProfileRepo    = new PublicUserProfileRepo(dataGateway, connectionString);
            IUserAccountRepository    userAccountRepository    = new UserAccountRepository(dataGateway, connectionString);
            IUserProfileRepository    userProfileRepository    = new UserProfileRepository(dataGateway, connectionString);
            IUserProfileService       userProfileService       = new UserProfileService(userProfileRepository);
            IUserAccountService       userAccountService       = new UserAccountService(userAccountRepository);
            IValidationService        validationService        = new ValidationService(userAccountService, userProfileService);
            IPublicUserProfileService publicUserProfileService = new PublicUserProfileService(publicUserProfileRepo, validationService);
            PublicUserProfileModel    model = new PublicUserProfileModel();


            try
            {
                model.UserId = userId;
                await publicUserProfileService.CeatePublicUserProfileAsync(model);

                model.Photo = photo;
                await publicUserProfileService.ChangeProfilePictureAsync(model);

                Assert.IsTrue(true);
            }
            catch
            {
                Assert.IsTrue(false);
            }
        }
        public async Task DeleteAccountByUserIDAsync_UserAccountIsDelted_UserAccountSuccessfulyDeletes(int userId, string password)
        {
            IDataGateway                   dataGateway                   = new SQLServerGateway();
            IConnectionStringData          connectionString              = new ConnectionStringData();
            IUserAccountRepository         userAccountRepository         = new UserAccountRepository(dataGateway, connectionString);
            IUserAccountSettingsRepository userAccountSettingsRepository = new UserAccountSettingRepository(dataGateway, connectionString);
            ICryptographyService           cryptographyService           = new CryptographyService(userAccountRepository);
            IAuthenticationService         authenticationService         = new AuthenticationService(userAccountRepository);
            IAccountSettingsService        userAccountSettingsManager    = new AccountSettingsService(userAccountRepository, userAccountSettingsRepository, cryptographyService, authenticationService);

            bool result = await userAccountSettingsManager.DeleteAccountByUserIDAsync(userId, password);

            if (!result)
            {
                Assert.IsTrue(false);
            }
            UserAccountModel model = await userAccountRepository.GetAccountById(userId);

            if (model.AccountStatus == "Deleted")
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.IsTrue(false);
            }
        }
Пример #22
0
        public IEnumerable <user_account> GetAccountInfo(int ID)
        {
            List <user_account> userAccountList = UserAccountRepository.GetUserAccountRepository().SelectByID();
            var result = from user in userAccountList where user.User_informationID == ID select user;

            return(result);
        }
        public async Task ChangeEmail_UserEmailChanges_EmailChangeCompletes(int userId, string password, string email)
        {
            IDataGateway                   dataGateway                   = new SQLServerGateway();
            IConnectionStringData          connectionString              = new ConnectionStringData();
            IUserAccountRepository         userAccountRepository         = new UserAccountRepository(dataGateway, connectionString);
            IUserAccountSettingsRepository userAccountSettingsRepository = new UserAccountSettingRepository(dataGateway, connectionString);
            ICryptographyService           cryptographyService           = new CryptographyService(userAccountRepository);
            IAuthenticationService         authenticationService         = new AuthenticationService(userAccountRepository);
            IAccountSettingsService        userAccountSettingsManager    = new AccountSettingsService(userAccountRepository, userAccountSettingsRepository, cryptographyService, authenticationService);

            bool result = await userAccountSettingsManager.ChangeEmailAsync(password, email, userId);

            if (!result)
            {
                Assert.IsTrue(false);
            }

            UserAccountModel model = await userAccountRepository.GetAccountById(userId);

            if (model.EmailAddress == email)
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.IsTrue(false);
            }
        }
        public async Task AddCode_AccountIdDoesntExists_ReturnTrue(string code,
                                                                   string expirationTime, int accountId, string username, string password, string salt, string emailAddress,
                                                                   string accountType, string accountStatus, string creationDate, string updationDate)
        {
            // Arrange
            IDataGateway               dataGateway               = new SQLServerGateway();
            IConnectionStringData      connectionString          = new ConnectionStringData();
            IUserAccountRepository     userAccountRepository     = new UserAccountRepository(dataGateway, connectionString);
            IUserAccountCodeRepository userAccountCodeRepository = new UserAccountCodeRepository(dataGateway, connectionString);

            var userAccountModel = new UserAccountModel();

            userAccountModel.Id            = accountId;
            userAccountModel.Username      = username;
            userAccountModel.Password      = password;
            userAccountModel.Salt          = salt;
            userAccountModel.EmailAddress  = emailAddress;
            userAccountModel.AccountType   = accountType;
            userAccountModel.AccountStatus = accountStatus;
            userAccountModel.CreationDate  = DateTimeOffset.Parse(creationDate);
            userAccountModel.UpdationDate  = DateTimeOffset.Parse(updationDate);

            await userAccountRepository.CreateAccount(userAccountModel);

            var expectedResult = true;

            IUserAccountCodeService userAccountCodeService = new UserAccountCodeService(userAccountCodeRepository);

            // Act
            var actualResult = await userAccountCodeService.AddCode(code, DateTimeOffset.Parse(expirationTime), accountId);

            // Assert
            Assert.IsTrue(actualResult == expectedResult);
        }
        public async Task ChangePasswordTest_UserPasswordChanges_PasswordChangeCompletes(int userId, string password, string newPassword)
        {
            IDataGateway                   dataGateway                   = new SQLServerGateway();
            IConnectionStringData          connectionString              = new ConnectionStringData();
            IUserAccountRepository         userAccountRepository         = new UserAccountRepository(dataGateway, connectionString);
            IUserAccountSettingsRepository userAccountSettingsRepository = new UserAccountSettingRepository(dataGateway, connectionString);
            ICryptographyService           cryptographyService           = new CryptographyService(userAccountRepository);
            IAuthenticationService         authenticationService         = new AuthenticationService(userAccountRepository);
            IAccountSettingsService        userAccountSettingsManager    = new AccountSettingsService(userAccountRepository, userAccountSettingsRepository, cryptographyService, authenticationService);

            bool result = await userAccountSettingsManager.ChangePasswordAsync(password, newPassword, userId);

            if (!result)
            {
                Assert.IsTrue(false);
            }

            UserAccountModel model = await userAccountRepository.GetAccountById(userId);

            UserAccountRepository userAccountRepo = new UserAccountRepository(new SQLServerGateway(), new ConnectionStringData());

            string encryptedNewPassword = await cryptographyService.EncryptPasswordAsync(newPassword, userId);

            if (model.Password == encryptedNewPassword)
            {
                Assert.IsTrue(true);
            }
            else
            {
                Assert.IsTrue(false);
            }
        }
Пример #26
0
        public void SearchUserTest()
        {
            try
            {
                var context = new EsContext(new Uri("http://192.168.99.100:32809"), "member");

                //var repoIndex = new IndexRepository(context.CreateClient());
                //repoIndex.IndexData<UserAccount>(userAccount, "member", "userAccount");

                var repo = new UserAccountRepository(context);

                IList <Tuple <Expression <Func <UserAccount, object> >, object> > paramValue =
                    new List <Tuple <Expression <Func <UserAccount, object> >, object> >()
                {
                    new Tuple <Expression <Func <UserAccount, object> >, object>(q => q.UserName, "pichit.sri"),
                    new Tuple <Expression <Func <UserAccount, object> >, object>(q => q.Password, "passord")
                };

                var user = repo.Search(paramValue).FirstOrDefault();


                //var user = repo.Search(s => s.Query(q => q.Term(p => p.UserName, "pichit.sri"))).FirstOrDefault();

                Assert.Equal("password", user.Password);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #27
0
        static void Main(string[] args)
        {
            var    userAccountRepository = new UserAccountRepository();
            var    authenticationService = new AuthenticationService(userAccountRepository);
            var    registrationService   = new RegistrationService(userAccountRepository);
            string input;

            while (true)
            {
                PrintMenu();

                input = Console.ReadLine();

                switch (input)
                {
                case "1":
                    registrationService.RegisterNewUser();
                    break;

                case "2":
                    authenticationService.GetCredentials();
                    break;

                case "3":
                    Console.Clear();
                    break;

                default:
                    return;
                }
            }
        }
Пример #28
0
        public async Task newPasswordEncryptAsync_EncryptNewPassword_NewPasswordEncryptSuccessful(string password, int UserID)
        {
            UserAccountRepository userAccountRepo = new UserAccountRepository(new SQLServerGateway(), new ConnectionStringData());


            // Act
            ICryptographyService CryptographyService = new CryptographyService(userAccountRepo);

            await CryptographyService.newPasswordEncryptAsync(password, UserID);


            var userAccount = await userAccountRepo.GetAccountById(UserID);

            var encryptedPassword = userAccount.Password;

            string salt = await userAccountRepo.GetSaltById(UserID);

            string SaltedPassword = password + salt;

            byte[] Data = System.Text.Encoding.ASCII.GetBytes(SaltedPassword);
            Data = new System.Security.Cryptography.SHA256Managed().ComputeHash(Data);
            string testPassword = System.Text.Encoding.ASCII.GetString(Data).ToString();


            //Assert
            Assert.IsTrue(testPassword == encryptedPassword);
        }
Пример #29
0
        public async Task CreateAccount_UsernameAndEmailDontExist_AccountExistsId(int expectedId, string username, string password, string salt,
                                                                                  string emailAddress, string accountType, string accountStatus, string creationDate, string updationDate)
        {
            //Arrange
            UserAccountModel userAccountModel = new UserAccountModel();

            userAccountModel.Id            = expectedId;
            userAccountModel.Username      = username;
            userAccountModel.Password      = password;
            userAccountModel.Salt          = salt;
            userAccountModel.EmailAddress  = emailAddress;
            userAccountModel.AccountType   = accountType;
            userAccountModel.AccountStatus = accountStatus;
            userAccountModel.CreationDate  = DateTimeOffset.Parse(creationDate);
            userAccountModel.UpdationDate  = DateTimeOffset.Parse(updationDate);

            IUserAccountRepository userAccountRepository = new UserAccountRepository(new SQLServerGateway(), new ConnectionStringData());

            //Act
            await userAccountRepository.CreateAccount(userAccountModel);

            var actualAccount = await userAccountRepository.GetAccountById(expectedId);

            //Assert
            Assert.IsTrue(actualAccount.Id == expectedId);
        }
Пример #30
0
        public async Task TrackFriendNumber_FriendRequest_GivenDay()
        {
            //arrange
            IDataGateway           dataGateway           = new SQLServerGateway();
            IConnectionStringData  connectionString      = new ConnectionStringData();
            IFriendListRepo        friendListRepo        = new FriendListRepo(dataGateway, connectionString);
            IFriendRequestListRepo friendRequestListRepo = new FriendRequestListRepo(dataGateway, connectionString);
            IUserAccountRepository userAccountRepository = new UserAccountRepository(dataGateway, connectionString);
            IFriendBlockListRepo   friendBlockListRepo   = new FriendBlockListRepo(dataGateway, connectionString);
            IPublicUserProfileRepo publicUserProfileRepo = new PublicUserProfileRepo(dataGateway, connectionString);
            IListingRepository     listingRepository     = new ListingRepository(dataGateway, connectionString);
            ILoginTrackerRepo      loginTrackerRepo      = new LoginTrackerRepo(dataGateway, connectionString);
            IPageVisitTrackerRepo  pageVisitTrackerRepo  = new PageVisitTrackerRepo(dataGateway, connectionString);
            ISearchTrackerRepo     searchTrackerRepo     = new SearchTrackerRepo(dataGateway, connectionString);
            IUserAnalysisService   userAnalysisService   = new UserAnalysisService(friendListRepo, listingRepository, userAccountRepository,
                                                                                   loginTrackerRepo, pageVisitTrackerRepo, friendRequestListRepo, searchTrackerRepo);
            IUserReportsRepo        userReportsRepo        = new UserReportsRepo(dataGateway, connectionString);
            IUserProfileRepository  userProfileRepository  = new UserProfileRepository(dataGateway, connectionString);
            IUserProfileService     userProfileService     = new UserProfileService(userProfileRepository);
            IUserAccountService     userAccountService     = new UserAccountService(userAccountRepository);
            IValidationService      validationService      = new ValidationService(userAccountService, userProfileService);
            IUserInteractionService userInteractionService = new UserInteractionService(friendBlockListRepo, friendListRepo, friendRequestListRepo, userReportsRepo, validationService);

            await userInteractionService.CreateFriendRequestAsync(1, 2);

            int avarageFriends = await userAnalysisService.FriendRequest_GivenDay(DateTimeOffset.UtcNow);

            if (avarageFriends != 1)
            {
                Assert.IsTrue(false);
            }
            Assert.IsTrue(true);
        }
Пример #31
0
 public AccountService(RequestContext c,
     UserAccountRepository userAccounts,
     AuthTokenRepository authTokens,
     ApiKeyRepository apiKeys,
     StoreUserRelationshipRepository adminUsersXStores,
     StoreRepository stores)
 {
     context = c;
     AdminUsers = userAccounts;
     AuthTokens = authTokens;
     ApiKeys = apiKeys;
     AdminUsersXStores = adminUsersXStores;
     Stores = stores;
 }