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 Init() { 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); int i = 1; UserAccountModel userAccountModel = new UserAccountModel(); userAccountModel.Id = i; userAccountModel.Username = "******" + i; userAccountModel.Password = "" + i; userAccountModel.Salt = "" + 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); UserAccountRepository userAccountRepo = new UserAccountRepository(new SQLServerGateway(), new ConnectionStringData()); ICryptographyService cryptographyService = new CryptographyService(userAccountRepo); await cryptographyService.newPasswordEncryptAsync("Password", 1); UserAccountSettingsModel userAccountSettingsModel = new UserAccountSettingsModel(); userAccountSettingsModel.Id = 0; userAccountSettingsModel.UserId = 1; userAccountSettingsModel.FontSize = 12; userAccountSettingsModel.FontStyle = "Time New Roman"; userAccountSettingsModel.ThemeColor = "White"; IAuthenticationService authenticationService = new AuthenticationService(userAccountRepository); IAccountSettingsService userAccountSettingsManager = new AccountSettingsService(userAccountRepository, userAccountSettingsRepository, cryptographyService, authenticationService); await userAccountSettingsManager.CreateUserAccountSettingsAsync(userAccountSettingsModel); }
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); } }
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); } }
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 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); } }
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); } }
public async Task CreateDefaultUserAccountSettings_DefaultUserIsCreated_DefaultUserIsSuccessfulyCreated(int UserId, int FontSize, string ThemeColor, string FontStyle) { IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); IUserAccountRepository userAccountRepository = new UserAccountRepository(dataGateway, connectionString); int i = 2; UserAccountModel userAccountModel = new UserAccountModel(); userAccountModel.Id = i; userAccountModel.Username = "******" + i; userAccountModel.Password = "" + i; userAccountModel.Salt = "" + 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); UserAccountSettingsModel userAccountSettingsModel = new UserAccountSettingsModel(); IUserAccountSettingsRepository userAccountSettingsRepository = new UserAccountSettingRepository(dataGateway, connectionString); ICryptographyService cryptographyService = new CryptographyService(userAccountRepository); IAuthenticationService authenticationService = new AuthenticationService(userAccountRepository); IAccountSettingsService userAccountSettingsManager = new AccountSettingsService(userAccountRepository, userAccountSettingsRepository, cryptographyService, authenticationService); UserAccountSettingsModel model = new UserAccountSettingsModel(); userAccountSettingsModel.Id = 0; userAccountSettingsModel.UserId = UserId; userAccountSettingsModel.FontSize = FontSize; userAccountSettingsModel.FontStyle = FontStyle; userAccountSettingsModel.ThemeColor = ThemeColor; bool result = await userAccountSettingsManager.CreateDefaultUserAccountSettingsAsync(userAccountSettingsModel); if (!result) { Assert.IsTrue(false); } await userAccountSettingsManager.CreateDefaultUserAccountSettingsAsync(userAccountSettingsModel); model = await userAccountSettingsRepository.GetUserAccountSettingsByUserId(UserId); if (model.UserId == UserId && model.FontSize == 12 && model.FontStyle == "Defualt Font Style" && model.ThemeColor == "Default Theme Color") { Assert.IsTrue(true); } else { Assert.IsTrue(false); } }
public async Task ChangeFontStyleAsync_UserFontStyleChange_UsersFontStyleChanges(int userId, string fontStyle) { Mock <IUserAccountRepository> mockUserAccountRepository = new Mock <IUserAccountRepository>(); Mock <IUserAccountSettingsRepository> mockUserAccountSettingsRepository = new Mock <IUserAccountSettingsRepository>(); Mock <IAuthenticationService> mockAuthenticationService = new Mock <IAuthenticationService>(); Mock <ICryptographyService> mockCryptographyService = new Mock <ICryptographyService>(); IAccountSettingsService userAccountSettingsManager = new AccountSettingsService(mockUserAccountRepository.Object, mockUserAccountSettingsRepository.Object, mockCryptographyService.Object, mockAuthenticationService.Object); bool result = await userAccountSettingsManager.ChangeFontStyleAsync(userId, fontStyle); if (result == true) { Assert.IsTrue(true); } else { Assert.IsTrue(false); } }
public async Task ChangeThemeColor_UsersThemeColorChanges_UsersThemeColorIsChangedSuccessfully(int userId, string ThemeColor) { Mock <IUserAccountRepository> mockUserAccountRepository = new Mock <IUserAccountRepository>(); Mock <IUserAccountSettingsRepository> mockUserAccountSettingsRepository = new Mock <IUserAccountSettingsRepository>(); Mock <IAuthenticationService> mockAuthenticationService = new Mock <IAuthenticationService>(); Mock <ICryptographyService> mockCryptographyService = new Mock <ICryptographyService>(); IAccountSettingsService userAccountSettingsManager = new AccountSettingsService(mockUserAccountRepository.Object, mockUserAccountSettingsRepository.Object, mockCryptographyService.Object, mockAuthenticationService.Object); bool result = await userAccountSettingsManager.ChangeThemeColorAsync(userId, ThemeColor); if (result == true) { Assert.IsTrue(true); } else { Assert.IsTrue(false); } }
public async Task DeleteAccountByUserIDAsync_UserAccountIsDelted_UserAccountSuccessfulyDeletes(int userId, string password) { Mock <IUserAccountRepository> mockUserAccountRepository = new Mock <IUserAccountRepository>(); Mock <IUserAccountSettingsRepository> mockUserAccountSettingsRepository = new Mock <IUserAccountSettingsRepository>(); Mock <IAuthenticationService> mockAuthenticationService = new Mock <IAuthenticationService>(); Mock <ICryptographyService> mockCryptographyService = new Mock <ICryptographyService>(); mockAuthenticationService.Setup(x => x.AuthenticatePasswordWithUserId(password, userId)).Returns(Task.FromResult(true)); IAccountSettingsService userAccountSettingsManager = new AccountSettingsService(mockUserAccountRepository.Object, mockUserAccountSettingsRepository.Object, mockCryptographyService.Object, mockAuthenticationService.Object); bool result = await userAccountSettingsManager.DeleteAccountByUserIDAsync(userId, password); if (result == true) { Assert.IsTrue(true); } else { Assert.IsTrue(false); } }
public async Task ChangeEmail_UserEmailChanges_EmailChangeCompletes(int userId, string password, string email) { Mock <IUserAccountRepository> mockUserAccountRepository = new Mock <IUserAccountRepository>(); Mock <IUserAccountSettingsRepository> mockUserAccountSettingsRepository = new Mock <IUserAccountSettingsRepository>(); Mock <IAuthenticationService> mockAuthenticationService = new Mock <IAuthenticationService>(); Mock <ICryptographyService> mockCryptographyService = new Mock <ICryptographyService>(); mockUserAccountRepository.Setup(x => x.UpdateAccountEmail(userId, email)); mockAuthenticationService.Setup(x => x.AuthenticatePasswordWithUserId(password, userId)).Returns(Task.FromResult(true)); IAccountSettingsService userAccountSettingsManager = new AccountSettingsService(mockUserAccountRepository.Object, mockUserAccountSettingsRepository.Object, mockCryptographyService.Object, mockAuthenticationService.Object); bool result = await userAccountSettingsManager.ChangeEmailAsync(password, email, userId); if (result == true) { Assert.IsTrue(true); } else { Assert.IsTrue(false); } }
public async Task Init() { IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); IUserAccountSettingsRepository userAccountSettingsRepository = new UserAccountSettingRepository(dataGateway, connectionString); IUserChannelsRepo userChannelsRepo = new UserChannelsRepo(dataGateway, connectionString); var userChannels = await userChannelsRepo.GetAllUserChannelsAsync(); foreach (var userChannel in userChannels) { await userChannelsRepo.DeleteUserChannelsByIdAsync(userChannel.Id); } await DataAccessTestHelper.ReseedAsync("UserChannels", 0, connectionString, dataGateway); IMessagesRepo messagesRepo = new MessagesRepo(dataGateway, connectionString); var messages = await messagesRepo.GetAllMessagesAsync(); foreach (var message in messages) { await messagesRepo.DeleteMessageByIdAsync(message.Id); } await DataAccessTestHelper.ReseedAsync("Messages", 0, connectionString, dataGateway); IChannelsRepo channelsRepo = new ChannelsRepo(dataGateway, connectionString); var channels = await channelsRepo.GetAllChannelsAsync(); foreach (var channel in channels) { await channelsRepo.DeleteChannelbyIdAsync(channel.Id); } await DataAccessTestHelper.ReseedAsync("Channels", 0, connectionString, dataGateway); IUserReportsRepo userReportsRepo = new UserReportsRepo(dataGateway, connectionString); IEnumerable <UserReportsModel> reports = await userReportsRepo.GetAllReports(); foreach (var report in reports) { await userReportsRepo.DeleteReportById(report.Id); } await DataAccessTestHelper.ReseedAsync("UserReports", 0, connectionString, dataGateway); IFriendListRepo friendListRepo = new FriendListRepo(dataGateway, connectionString); IEnumerable <FriendsListJunctionModel> friends = await friendListRepo.GetAllFriends(); foreach (var friend in friends) { await friendListRepo.DeleteFriendListbyId(friend.Id); } await DataAccessTestHelper.ReseedAsync("FriendsList", 0, connectionString, dataGateway); IFriendRequestListRepo friendRequestListRepo = new FriendRequestListRepo(dataGateway, connectionString); IEnumerable <FriendsListJunctionModel> requets = await friendListRepo.GetAllFriends(); foreach (var request in requets) { await friendListRepo.DeleteFriendListbyId(request.Id); } await DataAccessTestHelper.ReseedAsync("FriendRequestList", 0, connectionString, dataGateway); 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); IPublicUserProfileRepo publicUserProfileRepo = new PublicUserProfileRepo(dataGateway, connectionString); var profiles = await publicUserProfileRepo.GetAllPublicProfiles(); foreach (var profile in profiles) { await publicUserProfileRepo.DeletePublicProfileById(profile.Id); } await DataAccessTestHelper.ReseedAsync("PublicUserProfile", 0, connectionString, dataGateway); int i = 1; UserAccountModel userAccountModel = new UserAccountModel(); userAccountModel.Id = i; userAccountModel.Username = "******" + i; userAccountModel.Password = "" + i; userAccountModel.Salt = "" + 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); UserAccountRepository userAccountRepo = new UserAccountRepository(new SQLServerGateway(), new ConnectionStringData()); ICryptographyService cryptographyService = new CryptographyService(userAccountRepo); await cryptographyService.newPasswordEncryptAsync("Password", 1); 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); PublicUserProfileManager publicUserProfileManager = new PublicUserProfileManager(publicUserProfileService); PublicUserProfileModel publicUserProfileModel = new PublicUserProfileModel(); publicUserProfileModel.UserId = i; await publicUserProfileManager.CeatePublicUserProfileAsync(publicUserProfileModel); UserAccountSettingsModel userAccountSettingsModel = new UserAccountSettingsModel(); userAccountSettingsModel.Id = 0; userAccountSettingsModel.UserId = 1; userAccountSettingsModel.FontSize = 12; userAccountSettingsModel.FontStyle = "Time New Roman"; userAccountSettingsModel.ThemeColor = "White"; IAuthenticationService authenticationService = new AuthenticationService(userAccountRepository); IAccountSettingsService userAccountSettingsManager = new AccountSettingsService(userAccountRepository, userAccountSettingsRepository, cryptographyService, authenticationService); await userAccountSettingsManager.CreateUserAccountSettingsAsync(userAccountSettingsModel); i = 2; userAccountModel.Id = i; userAccountModel.Username = "******" + i; userAccountModel.Password = "" + i; userAccountModel.Salt = "" + 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); publicUserProfileModel = new PublicUserProfileModel(); publicUserProfileModel.UserId = i; await publicUserProfileManager.CeatePublicUserProfileAsync(publicUserProfileModel); i = 3; userAccountModel.Id = i; userAccountModel.Username = "******" + i; userAccountModel.Password = "" + i; userAccountModel.Salt = "" + 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); await cryptographyService.newPasswordEncryptAsync("Password", 1); publicUserProfileModel = new PublicUserProfileModel(); publicUserProfileModel.UserId = i; await publicUserProfileManager.CeatePublicUserProfileAsync(publicUserProfileModel); userAccountSettingsModel.Id = 1; userAccountSettingsModel.UserId = 2; userAccountSettingsModel.FontSize = 12; userAccountSettingsModel.FontStyle = "Time New Roman"; userAccountSettingsModel.ThemeColor = "White"; await userAccountSettingsManager.CreateUserAccountSettingsAsync(userAccountSettingsModel); }