public void Can_Get_Users_Guid_By_UserName_Expecting_Valid_Guid() { var variableToken = DateTime.Now.ToLongTimeString(); var myGuid = Guid.NewGuid(); var username = "******" + variableToken; const string email = "*****@*****.**"; const string woFs = "myTwoFactorSecret"; const string pwd = "password"; _uow = new SimpleMembershipUnitOfWorkAsync(_dataContextAsync, _loggingService); _simpleMembershipService = new WebSecurity(_uow, _loggingService); if (!_simpleMembershipService.FoundUser(username)) { var token = _simpleMembershipService.CreateUserAndAccount(username, pwd, email, myGuid, true); CreatedTestUsers.Add(username); Assert.IsNotNull(token, "Token for selected username: [ " + username + " ] was *null*. "); } var foundGuid = _simpleMembershipService.GetUserProfileGuidByUserName(username); // We expect to get a valid user Guid... Assert.IsTrue(foundGuid.HasValue, "No Guid was found. "); Assert.IsTrue(foundGuid.Value.ToString().Length > 0, "Length of found Guid was 0. "); Assert.AreEqual(myGuid, foundGuid.Value, "Guids do not match. Expected: [ " + myGuid + " ], but instead found: [ " + foundGuid.Value + " ]. "); }
public void Can_Get_Email_By_UserName_Expecting_Valid_Email() { var variableToken = DateTime.Now.ToLongTimeString(); const string username = "******"; const string email = "*****@*****.**"; const string woFs = "myTwoFactorSecret"; const string pwd = "password"; _uow = new SimpleMembershipUnitOfWorkAsync(_dataContextAsync, _loggingService); _simpleMembershipService = new WebSecurity(_uow, _loggingService); if (!_simpleMembershipService.FoundUser(username)) { var token = _simpleMembershipService.CreateUserAndAccount(username, pwd, email, true); CreatedTestUsers.Add(username); Assert.IsNotNull(token, "Token for selected username: [ " + username + " ] was *null*. "); } var actualEmail = _simpleMembershipService.GetEmail(username); // We expect to get a valid email address... Assert.AreEqual(actualEmail, email, "Emails do not match. Expected: [ " + email + " ], but instead found: [ " + actualEmail.Trim() + " ]. "); }
public void Can_Confirm_Account_Using_Token_Recieved_While_Registering_Expecting_True() { var variableToken = DateTime.Now.ToLongTimeString(); var username = "******" + variableToken; const string email = "*****@*****.**"; const string woFs = "myTwoFactorSecret"; const string pwd = "password"; _uow = new SimpleMembershipUnitOfWorkAsync(_dataContextAsync, _loggingService); _simpleMembershipService = new WebSecurity(_uow, _loggingService); if (!_simpleMembershipService.FoundUser(username)) { var token = _simpleMembershipService.CreateUserAndAccount(username, pwd, email, true); CreatedTestUsers.Add(username); Assert.IsNotNull(token, "Token for selected username: [ " + username + " ] was *null*. "); } // Getting the confirmation token... var actualToken = _simpleMembershipService.GetConfirmationToken(username); // Passing the confirmation token and confirming the account... // We expect the user to be confirmed var isConfirmed = _simpleMembershipService.ConfirmAccount(actualToken); Assert.IsTrue(isConfirmed, "The requested users acount: [ " + username + " ] could *not* be confirmed. "); }
public void TestInitialize() { // Not fake... _dataContextAsync = new SimpleMembershipDataContextAsync(); // Is fake... _fakeConfigurationRepository = new FakeConfigFileConfigurationRepository(); _fakeConfigurationRepository.FakeSettingsDictionary.Clear(); _fakeConfigurationRepository.FakeSettingsDictionary.Add("Log4NetSettingsFile", "Log4Net.config.xml"); _fakeConfigurationRepository.FakeSettingsDictionary.Add("LogEverythingViaWCF", "false"); _fakeConfigurationRepository.FakeSettingsDictionary.Add("DontLogAnythingViaWCF", "false"); _fakeConfigurationRepository.FakeSettingsDictionary.Add("LogEverythingToFile", "true"); _fakeConfigurationRepository.FakeSettingsDictionary.Add("LoggingServiceURL", "http://localhost:63247/LogWCF.svc"); var dir = Directory.GetCurrentDirectory(); var resourceFileInfo = new FileInfo(Path.Combine(dir, "Log4Net.config.xml")); // Is fake... _fakeContextService = new FakeThreadContextService { FakeGetContextualFullFilePath = resourceFileInfo.FullName, FakeUserNameForTestingPurposes = "SimpleMembershipServiceUnitTest" }; // Is fake... _fakewcfAppenderService = new FakeWcfAppenderService(_fakeConfigurationRepository); // Is fake... _loggingService = new Log4NetLoggingService(_fakeConfigurationRepository, _fakeContextService, _fakewcfAppenderService, true); // Not fake... _uow = new SimpleMembershipUnitOfWorkAsync(_dataContextAsync, _loggingService); // Not fake... _simpleMembershipService = new WebSecurity(_uow, _loggingService); InitDb(); }
public void Can_Update_User_By_Updating_The_UserName_Property_Expecting_Success() { var variableToken = DateTime.Now.ToLongTimeString(); var username = "******"; const string email = "*****@*****.**"; const string woFs = "myTwoFactorSecret"; const string pwd = "password"; const string updatedUserName = "******"; _uow = new SimpleMembershipUnitOfWorkAsync(_dataContextAsync, _loggingService); _simpleMembershipService = new WebSecurity(_uow, _loggingService); if (!_simpleMembershipService.FoundUser(username)) { var token = _simpleMembershipService.CreateUserAndAccount(username, pwd, email, true); CreatedTestUsers.Add(username); Assert.IsNotNull(token, "Token for selected username: [ " + username + " ] was *null*. "); } var userProfileOriginal = _simpleMembershipService.GetUserByUserName(username); var originalOne = userProfileOriginal.RowVersion; Assert.IsNotNull(userProfileOriginal, "Could *not* find the user account by user name: [ " + username + " ], before the update. "); userProfileOriginal.UserName = updatedUserName; var isUpdated = _simpleMembershipService.UpdateUser(userProfileOriginal); Assert.IsNotNull(isUpdated, "The user: [ " + userProfileOriginal.UserName + " ] was *not* updated. "); var userProfileAfterTheUpdate = _simpleMembershipService.GetUserByUserName(updatedUserName); // We expect to find that this users enitity was indeed updated... Assert.IsNotNull(userProfileAfterTheUpdate, "Could *not* find the user account by user name: [ " + updatedUserName + " ] after the update. "); Assert.AreEqual(updatedUserName, userProfileAfterTheUpdate.UserName, "User Names after update do *not* match. Expected: [ " + updatedUserName + "], but instead found: [ " + userProfileAfterTheUpdate.UserName.Trim() + " ]. "); }
Can_Generate_Password_Retrieve_Token_That_Expires_In_1_Minute_And_Reset_Password_After_Time_Limit_Expected_Fail () { var variableToken = DateTime.Now.ToLongTimeString(); var username = "******" + variableToken; const string email = "*****@*****.**"; const string woFs = "myTwoFactorSecret"; const string pwd = "password"; _uow = new SimpleMembershipUnitOfWorkAsync(_dataContextAsync, _loggingService); _simpleMembershipService = new WebSecurity(_uow, _loggingService); if (!_simpleMembershipService.FoundUser(username)) { var token = _simpleMembershipService.CreateUserAndAccount(username, pwd, email, true); CreatedTestUsers.Add(username); Assert.IsNotNull(token, "Token for selected username: [ " + username + " ] was *null*. "); } var actualToken = _simpleMembershipService.GetConfirmationToken(username); Assert.IsNotNull(actualToken, "Confirmation token for selected username: [ " + username + " ] was *null*. "); var isConfirmed = _simpleMembershipService.ConfirmAccount(actualToken); Assert.IsTrue(isConfirmed, "The requested users acount: [ " + username + " ] could *not* be confirmed. "); // We expect the account to already be confirmed at this point... var passwordResetToken = _simpleMembershipService.GeneratePasswordResetToken(username, 1); Assert.IsTrue(passwordResetToken.Length > 1, "Password reset token was *not* generated. "); Thread.Sleep(65000); // Minute and a half... // We expect the password reset to fail due to the timeout period expiry... var passwordWasReset = _simpleMembershipService.ResetPassword(passwordResetToken, "newPassword"); Assert.IsFalse(passwordWasReset, "Password should *not* have been reset - due to timeout. "); }
public void Can_Logout() { var variableToken = DateTime.Now.ToLongTimeString(); const string username = "******"; const string email = "*****@*****.**"; const string woFs = "myTwoFactorSecret"; const string pwd = "logout"; _uow = new SimpleMembershipUnitOfWorkAsync(_dataContextAsync, _loggingService); _simpleMembershipService = new WebSecurity(_uow, _loggingService); if (!_simpleMembershipService.FoundUser(username)) { var token = _simpleMembershipService.CreateUserAndAccount(username, pwd, email, true); CreatedTestUsers.Add(username); Assert.IsNotNull(token, "Token for selected username: [ " + username + " ] was *null*. "); } _simpleMembershipService.Logout(); // TODO: how to test user logging out???? need to mock HttpContext? }
public void Can_Login() { var variableToken = DateTime.Now.ToLongTimeString(); const string username = "******"; const string email = "*****@*****.**"; const string woFs = "myTwoFactorSecret"; const string pwd = "login"; _uow = new SimpleMembershipUnitOfWorkAsync(_dataContextAsync, _loggingService); _simpleMembershipService = new WebSecurity(_uow, _loggingService); if (!_simpleMembershipService.FoundUser(username)) { var token = _simpleMembershipService.CreateUserAndAccount(username, pwd, email, true); CreatedTestUsers.Add(username); Assert.IsNotNull(token, "Token for selected username: [ " + username + " ] was *null*. "); } var hasLoggedIn = _simpleMembershipService.Login(username, pwd); Assert.IsTrue(hasLoggedIn, "The user login for: [ " + username + " ] was *not* successfull. "); }
public void Can_Get_Current_User_Expecting_Current_User() { var variableToken = DateTime.Now.ToLongTimeString(); var username = "******"; const string email = "*****@*****.**"; const string woFs = "myTwoFactorSecret"; const string pwd = "password"; _uow = new SimpleMembershipUnitOfWorkAsync(_dataContextAsync, _loggingService); _simpleMembershipService = new WebSecurity(_uow, _loggingService); if (!_simpleMembershipService.FoundUser(username)) { var token = _simpleMembershipService.CreateUserAndAccount(username, pwd, email, true); CreatedTestUsers.Add(username); Assert.IsNotNull(token, "Token for selected username: [ " + username + " ] was *null*. "); } // TODO: needs to mock the context in order to test this... // Context.User.Identity.Name // var currentUser = _simpleMembershipService.GetCurrentUser(); }
public void Can_Get_Confirmation_Token_For_UserName_Expecting_Token() { var variableToken = DateTime.Now.ToLongTimeString(); const string username = "******"; const string email = "*****@*****.**"; const string woFs = "myTwoFactorSecret"; const string pwd = "password"; _uow = new SimpleMembershipUnitOfWorkAsync(_dataContextAsync, _loggingService); _simpleMembershipService = new WebSecurity(_uow, _loggingService); if (!_simpleMembershipService.FoundUser(username)) { var token = _simpleMembershipService.CreateUserAndAccount(username, pwd, email, true); CreatedTestUsers.Add(username); Assert.IsNotNull(token, "Token for selected username: [ " + username + " ] was *null*. "); } var actualToken = _simpleMembershipService.GetConfirmationToken(username); // The confirmation token should be generated... Assert.IsNotNull(actualToken, "Token for requested username: [ " + username + " ] is *null*. "); }