public void EmailIsValidFormat_ValidEmail_Succeeds() { var mockSvc = new MockUserAccountService(); var acct = new MockUserAccount(); var result = UserAccountValidation.EmailIsValidFormat.Validate(mockSvc.Object, acct.Object, "*****@*****.**"); Assert.IsNull(result); }
public void EmailIsValidFormat_InValidEmail_Fails() { var mockSvc = new MockUserAccountService(); var acct = new MockUserAccount(); var result = UserAccountValidation.EmailIsValidFormat.Validate(mockSvc.Object, acct.Object, "test"); Assert.IsNotNull(result); }
public void EmailIsValidFormat_ValidEmail_Succeeds() { var mockSvc = new MockUserAccountService(); var acct = new MockUserAccount(); var result = UserAccountValidation.EmailIsValidFormat.Validate(mockSvc.Object, acct.Object, "*****@*****.**"); Assert.IsNull(result); }
public void EmailIsValidFormat_InValidEmail_Fails() { var mockSvc = new MockUserAccountService(); var acct = new MockUserAccount(); var result = UserAccountValidation.EmailIsValidFormat.Validate(mockSvc.Object, acct.Object, "test"); Assert.IsNotNull(result); }
public void EmailMustNotAlreadyExist_EmailDoesNotExistsInService_Succeeds() { var mockSvc = new MockUserAccountService(); var acct1 = new MockUserAccount(mockSvc.SecuritySettings.DefaultTenant, "u1", "p1", "*****@*****.**"); mockSvc.MockUserAccounts(acct1); var acct2 = new MockUserAccount(mockSvc.SecuritySettings.DefaultTenant, "u1", "p1", "*****@*****.**"); var result = UserAccountValidation.EmailMustNotAlreadyExist.Validate(mockSvc.Object, acct2.Object, acct2.Object.Email); Assert.IsNull(result); }
public void UsernameMustNotAlreadyExist_UsernameExistsInService_Fails() { var mockSvc = new MockUserAccountService(); var acct1 = new MockUserAccount(mockSvc.SecuritySettings.DefaultTenant, "u1", "p1", "*****@*****.**"); mockSvc.MockUserAccounts(acct1); var acct2 = new MockUserAccount(mockSvc.SecuritySettings.DefaultTenant, "u1", "p1", "*****@*****.**"); var result = UserAccountValidation.UsernameMustNotAlreadyExist.Validate(mockSvc.Object, acct2.Object, acct2.Object.Username); Assert.IsNotNull(result); }
public void BasicProperties_Assigned() { var sub = new MockUserAccount("ten", "user", "pass", "email"); var now = new DateTime(2000, 2, 3, 8, 30, 0); sub.Setup(x => x.UtcNow).Returns(now); Assert.AreEqual("ten", sub.Object.Tenant); Assert.AreEqual("user", sub.Object.Username); Assert.AreEqual("email", sub.Object.Email); Assert.AreEqual(now, sub.Object.Created); sub.Verify(x => x.SetPassword("pass")); }
public void EmailMustNotAlreadyExist_EmailDoesNotExistsInService_Succeeds() { var mockSvc = new MockUserAccountService(); var acct1 = new MockUserAccount(mockSvc.SecuritySettings.DefaultTenant, "u1", "p1", "*****@*****.**"); mockSvc.MockUserAccounts(acct1); var acct2 = new MockUserAccount(mockSvc.SecuritySettings.DefaultTenant, "u1", "p1", "*****@*****.**"); var result = UserAccountValidation.EmailMustNotAlreadyExist.Validate(mockSvc.Object, acct2.Object, acct2.Object.Email); Assert.IsNull(result); }
public void UsernameMustNotAlreadyExist_UsernameExistsInService_Fails() { var mockSvc = new MockUserAccountService(); var acct1 = new MockUserAccount(mockSvc.SecuritySettings.DefaultTenant, "u1", "p1", "*****@*****.**"); mockSvc.MockUserAccounts(acct1); var acct2 = new MockUserAccount(mockSvc.SecuritySettings.DefaultTenant, "u1", "p1", "*****@*****.**"); var result = UserAccountValidation.UsernameMustNotAlreadyExist.Validate(mockSvc.Object, acct2.Object, acct2.Object.Username); Assert.IsNotNull(result); }
public void PasswordMustBeDifferentThanCurrent_NewAccount_Succeeds() { var mockSvc = new MockUserAccountService(); var acct = new MockUserAccount(mockSvc.SecuritySettings.DefaultTenant, "u1", "p1", "*****@*****.**"); acct.Object.LastLogin = null; mockSvc.MockUserAccounts(acct); var result = UserAccountValidation.PasswordMustBeDifferentThanCurrent.Validate(mockSvc.Object, acct.Object, "p1"); Assert.IsNull(result); }
public void Process_FormatReturnsNoMessage_DoesNotSendMessage() { var mockMF = new Mock<IMessageFormatter>(); var mockMD = new Mock<IMessageDelivery>(); var sub = new EmailEventHandler(mockMF.Object, mockMD.Object); var mockAcct = new MockUserAccount(); var mockEvt = new Mock<UserAccountEvent>(); mockEvt.Object.Account = mockAcct.Object; sub.Process(mockEvt.Object); mockMD.Verify(x => x.Send(It.IsAny<Message>()), Times.Never()); }
public void Process_FormatReturnsNoMessage_DoesNotSendMessage() { var mockMF = new Mock <IMessageFormatter>(); var mockMD = new Mock <IMessageDelivery>(); var sub = new EmailEventHandler(mockMF.Object, mockMD.Object); var mockAcct = new MockUserAccount(); var mockEvt = new Mock <UserAccountEvent>(); mockEvt.Object.Account = mockAcct.Object; sub.Process(mockEvt.Object); mockMD.Verify(x => x.Send(It.IsAny <Message>()), Times.Never()); }
public void Process_FormatReturnsMessage_SendsMessage() { var msg = new Message(); var mockMF = new Mock<IMessageFormatter>(); var mockMD = new Mock<IMessageDelivery>(); mockMF.Setup(x => x.Format(It.IsAny<UserAccountEvent>())).Returns(msg); var sub = new EmailEventHandler(mockMF.Object, mockMD.Object); var mockAcct = new MockUserAccount(); var mockEvt = new Mock<UserAccountEvent>(); mockEvt.Object.Account = mockAcct.Object; sub.Process(mockEvt.Object); mockMD.Verify(x => x.Send(msg)); }
public void Process_ExplicitEmailParam_UsesExplicitEmail() { var msg = new Message(); var mockMF = new Mock<IMessageFormatter>(); var mockMD = new Mock<IMessageDelivery>(); mockMF.Setup(x => x.Format(It.IsAny<UserAccountEvent>())).Returns(msg); var sub = new EmailEventHandler(mockMF.Object, mockMD.Object); var mockAcct = new MockUserAccount(); mockAcct.Object.Email = "foo"; var mockEvt = new Mock<UserAccountEvent>(); mockEvt.Object.Account = mockAcct.Object; sub.Process(mockEvt.Object, "bar"); Assert.AreEqual("bar", msg.To); }
public void Validate_AllCallsSucceed_CallsAllValidators() { var mockVal1 = new Mock<IValidator>(); var mockVal2 = new Mock<IValidator>(); var sub = new AggregateValidator(); sub.Add(mockVal1.Object); sub.Add(mockVal2.Object); var svc = new MockUserAccountService(); var ua = new MockUserAccount(); var val = "test"; var result = sub.Validate(svc.Object, ua.Object, val); mockVal1.Verify(x=>x.Validate(svc.Object, ua.Object, val)); mockVal2.Verify(x=>x.Validate(svc.Object, ua.Object, val)); }
public void Process_FormatReturnsMessage_SendsMessage() { var msg = new Message(); var mockMF = new Mock <IMessageFormatter>(); var mockMD = new Mock <IMessageDelivery>(); mockMF.Setup(x => x.Format(It.IsAny <UserAccountEvent>())).Returns(msg); var sub = new EmailEventHandler(mockMF.Object, mockMD.Object); var mockAcct = new MockUserAccount(); var mockEvt = new Mock <UserAccountEvent>(); mockEvt.Object.Account = mockAcct.Object; sub.Process(mockEvt.Object); mockMD.Verify(x => x.Send(msg)); }
public void Validate_AllCallsSucceed_CallsAllValidators() { var mockVal1 = new Mock <IValidator>(); var mockVal2 = new Mock <IValidator>(); var sub = new AggregateValidator(); sub.Add(mockVal1.Object); sub.Add(mockVal2.Object); var svc = new MockUserAccountService(); var ua = new MockUserAccount(); var val = "test"; var result = sub.Validate(svc.Object, ua.Object, val); mockVal1.Verify(x => x.Validate(svc.Object, ua.Object, val)); mockVal2.Verify(x => x.Validate(svc.Object, ua.Object, val)); }
public void Process_ExplicitEmailParam_UsesExplicitEmail() { var msg = new Message(); var mockMF = new Mock <IMessageFormatter>(); var mockMD = new Mock <IMessageDelivery>(); mockMF.Setup(x => x.Format(It.IsAny <UserAccountEvent>())).Returns(msg); var sub = new EmailEventHandler(mockMF.Object, mockMD.Object); var mockAcct = new MockUserAccount(); mockAcct.Object.Email = "foo"; var mockEvt = new Mock <UserAccountEvent>(); mockEvt.Object.Account = mockAcct.Object; sub.Process(mockEvt.Object, "bar"); Assert.AreEqual("bar", msg.To); }
public void AccountFound_DeleteAccountCalled() { var sub = new MockUserAccountService(); var account = new MockUserAccount(); sub.Mock.Setup(x => x.GetByUsername(It.IsAny<string>(), It.IsAny<string>())).Returns(account.Object); var result = sub.Object.DeleteAccount("user"); sub.Mock.Verify(x => x.DeleteAccount(account.Object)); }
public void AccountFound_ReturnsSuccess() { var sub = new MockUserAccountService(); var account = new MockUserAccount(); sub.Mock.Setup(x => x.GetByUsername(It.IsAny<string>(), It.IsAny<string>())).Returns(account.Object); var result = sub.Object.DeleteAccount("user"); Assert.IsTrue(result); }
public void KeysMatch_DeleteAccountCalled() { var sub = new MockUserAccountService(); var account = new MockUserAccount(); sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object); account.Object.VerificationKey = "key"; sub.Object.CancelNewAccount("key"); sub.Mock.Verify(x => x.DeleteAccount(account.Object)); }
public void KeysMatch_ReturnsTrue() { var sub = new MockUserAccountService(); var account = new MockUserAccount(); sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object); account.Object.VerificationKey = "key"; Assert.IsTrue(sub.Object.CancelNewAccount("key")); }
public void UserAccountChangeEmailRequestFails_DoesNotCallSendChangeEmailRequestNotice() { var sub = new MockUserAccountService(); sub.NotificationService = new Mock<INotificationService>(); var account = new MockUserAccount(); sub.Mock.Setup(x => x.GetByUsername(It.IsAny<string>(), It.IsAny<string>())).Returns(account.Object); account.Setup(x => x.ChangeEmailRequest(It.IsAny<string>())).Returns(false); sub.Object.ChangeEmailRequest("user", "*****@*****.**"); sub.NotificationService.Verify(x => x.SendChangeEmailRequestNotice(It.IsAny<UserAccount>(), It.IsAny<string>()), Times.Never()); }
public void CallsSaveChangesOnRepo() { var sub = new MockUserAccountService(); var account = new MockUserAccount(); sub.Object.Authenticate(account.Object, "pass", 10, TimeSpan.FromDays(1)); sub.UserAccountRepository.Verify(x => x.SaveChanges()); }
public void AllowAccountDeletionDisabled_AccountIsVerified_CallsCloseOnAccount() { SecuritySettings.Instance.AllowAccountDeletion = false; var sub = new MockUserAccountService(); var account = new MockUserAccount(); account.Object.IsLoginAllowed = true; account.Object.IsAccountVerified = true; sub.Object.DeleteAccount(account.Object); sub.UserAccountRepository.Verify(x => x.Remove(account.Object), Times.Never()); account.Verify(x => x.CloseAccount()); }
public void VerifyAccountReturnsFalse_ReturnsFalse() { var sub = new MockUserAccountService(); var account = new MockUserAccount(); sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object); account.Setup(x => x.VerifyAccount(It.IsAny<string>())).Returns(false); Assert.IsFalse(sub.Object.VerifyAccount("key")); }
public void Success_CallsVerifyAccountOnUserAccountAndSaveOnRepository() { var sub = new MockUserAccountService(); var account = new MockUserAccount(); sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object); sub.Object.VerifyAccount("key"); account.Verify(x => x.VerifyAccount("key")); sub.UserAccountRepository.Verify(x => x.SaveChanges()); }
public void EmailIsUsername_AllowEmailChangeWhenEmailIsUsername_WhenFail_DoesNotUpdatesUsername() { SecuritySettings.Instance.EmailIsUsername = true; SecuritySettings.Instance.AllowEmailChangeWhenEmailIsUsername = true; var sub = new MockUserAccountService(); var account = new MockUserAccount(); sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object); sub.Mock.Setup(x => x.Authenticate(It.IsAny<UserAccount>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<TimeSpan>())).Returns(true); account.Setup(x => x.ChangeEmailFromKey(It.IsAny<string>(), It.IsAny<string>())).Returns(false); sub.Object.ChangeEmailFromKey("pass", "key", "*****@*****.**"); Assert.AreNotEqual("*****@*****.**", account.Object.Username); }
public void UserAccountChangeEmailFromKeyFail_SendEmailChangedNoticeNotCalled() { var sub = new MockUserAccountService(); sub.NotificationService = new Mock<INotificationService>(); var account = new MockUserAccount(); sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object); sub.Mock.Setup(x => x.Authenticate(It.IsAny<UserAccount>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<TimeSpan>())).Returns(true); account.Setup(x => x.ChangeEmailFromKey(It.IsAny<string>(), It.IsAny<string>())).Returns(false); sub.Object.ChangeEmailFromKey("pass", "key", "*****@*****.**"); sub.NotificationService.Verify(x => x.SendEmailChangedNotice(It.IsAny<UserAccount>(), It.IsAny<string>()), Times.Never()); }
public void UserAccountChangeEmailFromKeySuccess_SaveChangesCalled() { var sub = new MockUserAccountService(); var account = new MockUserAccount(); sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object); sub.Mock.Setup(x => x.Authenticate(It.IsAny<UserAccount>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<TimeSpan>())).Returns(true); account.Setup(x => x.ChangeEmailFromKey(It.IsAny<string>(), It.IsAny<string>())).Returns(true); sub.Object.ChangeEmailFromKey("pass", "key", "*****@*****.**"); sub.UserAccountRepository.Verify(x => x.SaveChanges()); }
public void UserAccountChangeEmailFromKeyFail_ReturnFail() { var sub = new MockUserAccountService(); var account = new MockUserAccount(); sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object); sub.Mock.Setup(x => x.Authenticate(It.IsAny<UserAccount>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<TimeSpan>())).Returns(true); account.Setup(x => x.ChangeEmailFromKey(It.IsAny<string>(), It.IsAny<string>())).Returns(false); Assert.IsFalse(sub.Object.ChangeEmailFromKey("pass", "key", "*****@*****.**")); }
public void AllowAccountDeletion_CallsRemoveOnRepo() { SecuritySettings.Instance.AllowAccountDeletion = true; var sub = new MockUserAccountService(); var account = new MockUserAccount(); sub.Object.DeleteAccount(account.Object); sub.UserAccountRepository.Verify(x => x.Remove(account.Object)); }
public void VerifyFails_DoesNotCallNotificationService() { var sub = new MockUserAccountService(); sub.NotificationService = new Mock<INotificationService>(); var account = new MockUserAccount(); sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object); account.Setup(x => x.VerifyAccount(It.IsAny<string>())).Returns(false); sub.Object.VerifyAccount("key"); sub.NotificationService.Verify(x => x.SendAccountVerified(It.IsAny<UserAccount>()), Times.Never()); }
public void AllowAccountDeletionDisabled_AccountIsNotVerified_CallsRemoveOnRepo() { SecuritySettings.Instance.AllowAccountDeletion = false; var sub = new MockUserAccountService(); var account = new MockUserAccount(); account.Object.IsAccountVerified = false; sub.Object.DeleteAccount(account.Object); sub.UserAccountRepository.Verify(x => x.Remove(account.Object)); }
public void VerifySucceeds_CallsNotificationService() { var sub = new MockUserAccountService(); sub.NotificationService = new Mock<INotificationService>(); var account = new MockUserAccount(); sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object); account.Setup(x => x.VerifyAccount(It.IsAny<string>())).Returns(true); sub.Object.VerifyAccount("key"); sub.NotificationService.Verify(x => x.SendAccountVerified(account.Object)); }
public void CallsAuthenticateOnUserAccount() { var sub = new MockUserAccountService(); var account = new MockUserAccount(); sub.Object.Authenticate(account.Object, "pass", 10, TimeSpan.FromDays(1)); account.Verify(x => x.Authenticate("pass", 10, TimeSpan.FromDays(1))); }
public void AccountVerified_ReturnsFalse() { var sub = new MockUserAccountService(); var account = new MockUserAccount(); sub.Mock.Setup(x => x.GetByVerificationKey(It.IsAny<string>())).Returns(account.Object); account.Object.IsAccountVerified = true; Assert.IsFalse(sub.Object.CancelNewAccount("key")); }
public void EmailIsUsername_AllowEmailChangeWhenEmailIsUsername_ReturnsSuccess() { SecuritySettings.Instance.EmailIsUsername = true; SecuritySettings.Instance.AllowEmailChangeWhenEmailIsUsername = true; var sub = new MockUserAccountService(); var account = new MockUserAccount(); sub.Mock.Setup(x => x.GetByUsername(It.IsAny<string>(), It.IsAny<string>())).Returns(account.Object); account.Setup(x => x.ChangeEmailRequest(It.IsAny<string>())).Returns(true); Assert.IsTrue(sub.Object.ChangeEmailRequest("user", "*****@*****.**")); }
public void UserAccountChangeEmailRequestSuccess_CallsSendChangeEmailRequestNotice() { var sub = new MockUserAccountService(); sub.NotificationService = new Mock<INotificationService>(); var account = new MockUserAccount(); sub.Mock.Setup(x => x.GetByUsername(It.IsAny<string>(), It.IsAny<string>())).Returns(account.Object); account.Setup(x => x.ChangeEmailRequest(It.IsAny<string>())).Returns(true); sub.Object.ChangeEmailRequest("user", "*****@*****.**"); sub.NotificationService.Verify(x => x.SendChangeEmailRequestNotice(account.Object, "*****@*****.**")); }