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); } }
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); }
public async Task GetUserProfileByAccountId_CorrectAccountId_ReturnsWebUserProfileModel(int profileId, string firstName, string surname, string dateOfBirth, int accountId) { // Arrange // Setting up each dependency of UserProfileService IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); IUserProfileRepository userProfileRepository = new UserProfileRepository(dataGateway, connectionString); var expectedResult = new WebUserProfileModel(); expectedResult.Id = profileId; expectedResult.FirstName = firstName; expectedResult.Surname = surname; expectedResult.DateOfBirth = DateTimeOffset.Parse(dateOfBirth); expectedResult.UserAccountId = accountId; // Finally, instantiate the actual class being tested and pass in the dependencies IUserProfileService userProfileService = new UserProfileService(userProfileRepository); // Arrange var actualResult = await userProfileService.GetUserProfileByAccountId(accountId); // Act Assert.IsTrue ( actualResult.Id == expectedResult.Id && actualResult.UserAccountId == expectedResult.UserAccountId ); }
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); }
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); } }
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 GetUserAccountByUsername_CorrectUsername_ReturnsWebUserAccountModel(int accountId, string username, string emailAddress, string accountType, string accountStatus, string creationDate, string updationDate) { // Arrange // Setting up each dependency of UserAccountService and dependencies of dependencies IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); IUserAccountRepository userAccountRepository = new UserAccountRepository(dataGateway, connectionString); var expectedResult = new WebUserAccountModel(); expectedResult.Id = accountId; expectedResult.Username = username; expectedResult.EmailAddress = emailAddress; expectedResult.AccountType = accountType; expectedResult.AccountStatus = accountStatus; expectedResult.CreationDate = DateTimeOffset.Parse(creationDate); expectedResult.UpdationDate = DateTimeOffset.Parse(updationDate); // Finally, instantiate the actual class being tested and pass in the dependencies IUserAccountService userAccountService = new UserAccountService(userAccountRepository); // Arrange var actualResult = await userAccountService.GetUserAccountByUsername(username); // Act Assert.IsTrue( actualResult.Id == expectedResult.Id && actualResult.Username == expectedResult.Username ); }
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 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 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 Init() { await TestCleaner.CleanDatabase(); var numTestRows = 20; IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); IResourceRepository resourceRepository = new ResourceRepository(dataGateway, connectionString); IAccessPolicyRepository accessPolicyRepository = new AccessPolicyRepository(dataGateway, connectionString); for (int i = 1; i <= numTestRows; ++i) { ResourceModel resourceModel = new ResourceModel(); resourceModel.Id = i; resourceModel.Name = "TestResource" + i; AccessPolicyModel accessPolicyModel = new AccessPolicyModel(); accessPolicyModel.Id = i; accessPolicyModel.Name = "TestAccessPolicy" + i; accessPolicyModel.ResourceId = i; accessPolicyModel.Priority = i % 4; await resourceRepository.CreateResource(resourceModel); await accessPolicyRepository.CreateAccessPolicy(accessPolicyModel); } }
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 CleanUp() { IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); IUserAccountRepository userAccountRepository = new UserAccountRepository(dataGateway, connectionString); await TestCleaner.CleanDatabase(); }
public async Task GetUserAccountCodeByAccountId_AccountIdExists_ReturnBusinessUserAccountCodeModel(int id, string code, string expirationTime, int accountId) { // Arrange IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); IUserAccountCodeRepository userAccountCodeRepository = new UserAccountCodeRepository(dataGateway, connectionString); var expectedResult = new BusinessUserAccountCodeModel(); expectedResult.Id = id; expectedResult.Code = code; expectedResult.ExpirationTime = DateTimeOffset.Parse(expirationTime); expectedResult.UserAccountId = accountId; IUserAccountCodeService userAccountCodeService = new UserAccountCodeService(userAccountCodeRepository); // Act var actualResult = await userAccountCodeService.GetUserAccountCodeByAccountId(accountId); // Assert Assert.IsTrue ( actualResult.Id == expectedResult.Id && actualResult.Code == expectedResult.Code && actualResult.ExpirationTime == expectedResult.ExpirationTime && actualResult.UserAccountId == expectedResult.UserAccountId ); }
public async Task IncrementLoginCounterByIpAddress_IpExists_ReturnTrue(string ipAddress) { // Arrange IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); ILoginAttemptsRepository loginAttemptsRepository = new LoginAttemptsRepository(dataGateway, connectionString); var oldLoginAttemptsModel = await loginAttemptsRepository.GetLoginAttemptsByIpAddress(ipAddress); var expectedResult = true; ILoginAttemptsService loginAttemptsService = new LoginAttemptsService(loginAttemptsRepository); // Act var actualResult = await loginAttemptsService.IncrementLoginCounterByIpAddress(ipAddress); var newLoginAttemptsModel = await loginAttemptsRepository.GetLoginAttemptsByIpAddress(ipAddress); // Assert Assert.IsTrue ( actualResult == expectedResult && newLoginAttemptsModel.LoginCounter == (oldLoginAttemptsModel.LoginCounter + 1) ); }
public async Task GetLoginAttemptsByIpAddress_IpExists_ReturnBusinessLoginAttemptsModel(int id, string ipAddress, int loginCounter, string suspensionEndtime) { // Arrange IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); ILoginAttemptsRepository loginAttemptsRepository = new LoginAttemptsRepository(dataGateway, connectionString); var expectedResult = new BusinessLoginAttemptsModel(); expectedResult.Id = id; expectedResult.IpAddress = ipAddress; expectedResult.LoginCounter = loginCounter; expectedResult.SuspensionEndTime = DateTimeOffset.Parse(suspensionEndtime); ILoginAttemptsService loginAttemptsService = new LoginAttemptsService(loginAttemptsRepository); // Act var actualResult = await loginAttemptsService.GetLoginAttemptsByIpAddress(ipAddress); // Assert Assert.IsTrue ( actualResult.Id == expectedResult.Id && actualResult.IpAddress == expectedResult.IpAddress && actualResult.LoginCounter == expectedResult.LoginCounter && actualResult.SuspensionEndTime == expectedResult.SuspensionEndTime ); }
public async Task GetUserProfileAsync_UserProfileGot_SuccessfulRecieved(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); Assert.IsTrue(true); } catch { 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 UpdateProfileAgeAsync_UpdateValue_ValueUpdated(int userId, int age) { 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); model.Age = age; await publicUserProfileService.UpdateProfileAgeAsync(model); Assert.IsTrue(true); } catch { 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 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 GetUserProfile_GetsProfile_ProfileGetSuccess(int userId, string description, string job, string goals, int age, string gender, string ethnicity, string sexualOrientation, string height, string visibility, string status, string photo, string intrests, string hobbies) { 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); PublicUserProfileManager publicUserProfileManager = new PublicUserProfileManager(publicUserProfileService); PublicUserProfileModel model = new PublicUserProfileModel(); model.UserId = userId; try { await publicUserProfileManager.CeatePublicUserProfileAsync(model); model.Description = description; model.Jobs = job; model.Goals = goals; model.Age = age; model.Gender = gender; model.Ethnicity = ethnicity; model.SexualOrientation = sexualOrientation; model.Height = height; model.Status = status; model.Photo = photo; model.Intrests = intrests; model.Hobbies = hobbies; await publicUserProfileManager.EditPublicUserProfileAsync(model); PublicUserProfileModel profile = await publicUserProfileManager.GetUserProfileAsync(userId); if (profile == null) { Assert.IsTrue(false); } if (profile.Description == description && profile.Hobbies == hobbies && profile.Jobs == job && profile.Goals == goals && profile.Age == age && profile.Gender == gender && profile.Ethnicity == ethnicity && profile.SexualOrientation == sexualOrientation && profile.Height == height && profile.Visibility == visibility && profile.Intrests == intrests) { Assert.IsTrue(true); } else { Assert.IsTrue(false); } } catch { Assert.IsTrue(false); } }
public async Task setUserOnline_SetOnline_UserSetOnline(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); PublicUserProfileManager publicUserProfileManager = new PublicUserProfileManager(publicUserProfileService); PublicUserProfileModel model = new PublicUserProfileModel(); model.UserId = userId; try { await publicUserProfileManager.CeatePublicUserProfileAsync(model); await publicUserProfileManager.SetUserOnlineAsync(userId); IEnumerable <PublicUserProfileModel> models = await publicUserProfileRepo.GetAllPublicProfiles(); if (models == null) { Assert.IsTrue(false); } if (models.Count() == 0) { Assert.IsTrue(false); } foreach (var profile in models) { if (profile.Status == "Online") { Assert.IsTrue(true); } else { Assert.IsTrue(false); } } } catch { Assert.IsTrue(false); } }
public async Task <string> GetFontSizeAsync([FromBody] string id) { Console.WriteLine("Fethcing Font Size" + id); IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); IUserAccountSettingsRepository userAccountSettingsRepository = new UserAccountSettingRepository(dataGateway, connectionString); return(await userAccountSettingsRepository.GetFontSizeByID(Int32.Parse(id))); }
public async Task Init() { await TestCleaner.CleanDatabase(); var numTestRows = 20; IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); IScopeRepository scopeRepository = new ScopeRepository(dataGateway, connectionString); IResourceRepository resourceRepository = new ResourceRepository(dataGateway, connectionString); IClaimRepository claimRepository = new ClaimRepository(dataGateway, connectionString); IAccessPolicyRepository accessPolicyRepository = new AccessPolicyRepository(dataGateway, connectionString); IAccessPolicyPairingRepository accessPolicyPairingRepository = new AccessPolicyPairingRepository(dataGateway, connectionString); for (int i = 1; i <= numTestRows; ++i) { ResourceModel resourceModel = new ResourceModel(); resourceModel.Id = i; resourceModel.Name = "TestResource" + i; ScopeModel scopeModel = new ScopeModel(); scopeModel.Id = i; scopeModel.Type = "TestScope" + i; scopeModel.Description = "TestDescription" + i; ClaimModel claimModel = new ClaimModel(); claimModel.Id = i; claimModel.Type = "TestClaim" + i; claimModel.Value = "TestDescription" + i; claimModel.IsDefault = true; var resourceId = await resourceRepository.CreateResource(resourceModel); var claimId = await claimRepository.CreateClaim(claimModel); var scopeId = await scopeRepository.CreateScope(scopeModel); AccessPolicyModel accessPolicyModel = new AccessPolicyModel(); accessPolicyModel.Id = i; accessPolicyModel.Name = "TestAccessPolicy" + i; accessPolicyModel.ResourceId = resourceId; accessPolicyModel.Priority = i % 4; var accessPolicyId = await accessPolicyRepository.CreateAccessPolicy(accessPolicyModel); AccessPolicyPairingModel accessPolicyPairingModel = new AccessPolicyPairingModel(); accessPolicyPairingModel.Id = i; accessPolicyPairingModel.ScopeId = scopeId; accessPolicyPairingModel.ClaimId = claimId; accessPolicyPairingModel.AccessPolicyId = accessPolicyId; await accessPolicyPairingRepository.CreateAccessPolicyPairing(accessPolicyPairingModel); } }
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 CleanUp() { IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); ITraditionalListingSearchRepository traditionalListingSearchRepository = new TraditionalListingSearchRepository(new SQLServerGateway(), new ConnectionStringData()); var accounts = await traditionalListingSearchRepository.GetAllListings(); // Delete Listing is not cooperating... place it here once its working. await DataAccessTestHelper.ReseedAsync("Listing", 0, connectionString, dataGateway); }