protected virtual Task <ActionResult> InvokeConfirm( TAccountsController controller, TUser account, Func <Fakes, User> getCurrentUser, string token = "token", EntityException exception = null) { // Arrange controller.SetCurrentUser(getCurrentUser(Fakes)); var userService = GetMock <IUserService>(); userService.Setup(u => u.FindByUsername(account.Username, false)) .Returns(account as User); var confirmSetup = userService.Setup(u => u.ConfirmEmailAddress(It.IsAny <User>(), It.IsAny <string>())); if (exception == null) { confirmSetup.Returns(Task.FromResult(token == account.EmailConfirmationToken)); } else { confirmSetup.Throws(exception); } GetMock <IMessageService>() .Setup(m => m.SendMessageAsync( It.IsAny <EmailChangeNoticeToPreviousEmailAddressMessage>(), It.IsAny <bool>(), It.IsAny <bool>())) .Returns(Task.CompletedTask) .Verifiable(); // Act return(controller.Confirm(account.Username, token)); }
protected virtual Task <ActionResult> InvokeConfirmationRequiredPostAsync( TAccountsController controller, TUser account, Func <Fakes, User> getCurrentUser, string confirmationUrl = null) { // Arrange controller.SetCurrentUser(getCurrentUser(Fakes)); var userService = GetMock <IUserService>(); userService.Setup(u => u.FindByUsername(account.Username, false)) .Returns(account as User); GetMock <IMessageService>() .Setup(m => m.SendMessageAsync( It.Is <NewAccountMessage>( msg => msg.User == account && msg.ConfirmationUrl == confirmationUrl), false, false)) .Returns(Task.CompletedTask) .Verifiable(); // Act return(controller.ConfirmationRequiredPost(account.Username)); }
protected virtual async Task <ActionResult> InvokeChangeEmailSubscription( TAccountsController controller, Func <Fakes, User> getCurrentUser, bool emailAllowed = true, bool notifyPackagePushed = true) { // Arrange controller.SetCurrentUser(getCurrentUser(Fakes)); var account = GetAccount(controller); account.Username = "******"; account.EmailAddress = "*****@*****.**"; account.EmailAllowed = !emailAllowed; account.NotifyPackagePushed = !notifyPackagePushed; var userService = GetMock <IUserService>(); userService.Setup(u => u.FindByUsername(account.Username, false)) .Returns(account as User); userService.Setup(u => u.ChangeEmailSubscriptionAsync(account, emailAllowed, notifyPackagePushed)) .Returns(Task.CompletedTask); var viewModel = Activator.CreateInstance <TAccountViewModel>(); viewModel.AccountName = account.Username; viewModel.ChangeNotifications = new ChangeNotificationsViewModel { EmailAllowed = emailAllowed, NotifyPackagePushed = notifyPackagePushed }; // Act return(await controller.ChangeEmailSubscription(viewModel)); }
protected virtual Task <ActionResult> InvokeChangeEmail( TAccountsController controller, TUser account, Func <Fakes, User> getCurrentUser, TAccountViewModel model = null, bool newEmailIsConfirmed = false, EntityException exception = null) { // Arrange controller.SetCurrentUser(getCurrentUser(Fakes)); var messageService = GetMock <IMessageService>(); messageService.Setup(m => m.SendMessageAsync(It.IsAny <EmailChangeConfirmationMessage>(), It.IsAny <bool>(), It.IsAny <bool>())) .Returns(Task.CompletedTask) .Verifiable(); var userService = GetMock <IUserService>(); userService.Setup(u => u.FindByUsername(account.Username, false)) .Returns(account as User); var setup = userService.Setup(u => u.ChangeEmailAddress(It.IsAny <User>(), It.IsAny <string>())) .Callback <User, string>((acct, newEmail) => { if (newEmailIsConfirmed) { acct.EmailAddress = newEmail; } else { acct.UnconfirmedEmailAddress = newEmail; } }); if (exception != null) { setup.Throws(exception); } else { setup.Returns(Task.CompletedTask).Verifiable(); } model = model ?? CreateViewModel(account); var password = account.Credentials.FirstOrDefault(c => CredentialTypes.IsPassword(c.Type)); if (password != null) { model.ChangeEmail.Password = Fakes.Password; } // Act return(controller.ChangeEmail(model)); }
private ActionResult InvokeAccountInternal(TAccountsController controller, Func <Fakes, User> getCurrentUser) { var account = GetAccount(controller); controller.SetCurrentUser(getCurrentUser(Fakes)); var userService = GetMock <IUserService>(); userService.Setup(u => u.FindByUsername(account.Username, false)) .Returns(account as User); return(InvokeAccount(controller)); }
protected virtual ActionResult InvokeConfirmationRequired( TAccountsController controller, TUser account, Func <Fakes, User> getCurrentUser) { // Arrange controller.SetCurrentUser(getCurrentUser(Fakes)); var userService = GetMock <IUserService>(); userService.Setup(u => u.FindByUsername(account.Username, false)) .Returns(account as User); // Act return(controller.ConfirmationRequired(account.Username)); }
protected virtual ActionResult InvokeConfirmationRequiredPost( TAccountsController controller, TUser account, Func <Fakes, User> getCurrentUser, string confirmationUrl = null) { // Arrange controller.SetCurrentUser(getCurrentUser(Fakes)); var userService = GetMock <IUserService>(); userService.Setup(u => u.FindByUsername(account.Username, false)) .Returns(account as User); GetMock <IMessageService>() .Setup(m => m.SendNewAccountEmail( account, string.IsNullOrEmpty(confirmationUrl) ? It.IsAny <string>() : confirmationUrl)) .Verifiable(); // Act return(controller.ConfirmationRequiredPost(account.Username)); }
protected virtual Task <ActionResult> InvokeCancelChangeEmail( TAccountsController controller, TUser account, TAccountViewModel model = null) { // Arrange controller.SetCurrentUser(GetCurrentUser(controller)); var userService = GetMock <IUserService>(); userService.Setup(u => u.FindByUsername(account.Username)) .Returns(account as User); userService.Setup(u => u.CancelChangeEmailAddress(It.IsAny <User>())) .Returns(Task.CompletedTask) .Verifiable(); model = model ?? Activator.CreateInstance <TAccountViewModel>(); model.AccountName = account.Username; // Act return(controller.CancelChangeEmail(model)); }