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));
            }
示例#2
0
            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));
            }