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));
            }
示例#2
0
            private Task <JsonResult> InvokeDeleteMember(
                OrganizationsController controller,
                Organization account,
                string memberName         = defaultMemberName,
                EntityException exception = null)
            {
                // Arrange
                controller.SetCurrentUser(GetCurrentUser(controller));

                var userService = GetMock <IUserService>();

                userService.Setup(u => u.FindByUsername(account.Username))
                .Returns(account as User);
                var setup = userService.Setup(u => u.DeleteMemberAsync(It.IsAny <Organization>(), memberName));

                if (exception != null)
                {
                    setup.Throws(exception);
                }
                else
                {
                    setup.Returns(Task.CompletedTask).Verifiable();
                }

                // Act
                return(controller.DeleteMember(account.Username, memberName));
            }
示例#3
0
            private Task <JsonResult> InvokeUpdateMember(
                OrganizationsController controller,
                Organization account,
                string memberName         = defaultMemberName,
                bool isAdmin              = false,
                EntityException exception = null)
            {
                // Arrange
                controller.SetCurrentUser(GetCurrentUser(controller));

                var userService = GetMock <IUserService>();

                userService.Setup(u => u.FindByUsername(account.Username))
                .Returns(account as User);
                var setup = userService.Setup(u => u.UpdateMemberAsync(It.IsAny <Organization>(), memberName, isAdmin));

                if (exception != null)
                {
                    setup.Throws(exception);
                }
                else
                {
                    var membership = new Membership
                    {
                        Organization = account,
                        Member       = new User(memberName),
                        IsAdmin      = isAdmin
                    };
                    setup.Returns(Task.FromResult(membership)).Verifiable();
                }

                // Act
                return(controller.UpdateMember(account.Username, memberName, isAdmin));
            }
示例#4
0
            private Task <JsonResult> InvokeCancelMemberRequestMember(
                OrganizationsController controller,
                Organization account,
                string memberName         = defaultMemberName,
                EntityException exception = null)
            {
                // Arrange
                controller.SetCurrentUser(GetCurrentUser(controller));

                var userService = GetMock <IUserService>();

                userService.Setup(u => u.FindByUsername(account.Username))
                .Returns(account as User);
                var setup = userService.Setup(u => u.CancelMembershipRequestAsync(account, memberName));

                if (exception != null)
                {
                    setup.Throws(exception);
                }
                else
                {
                    setup.Returns(Task.FromResult(new User(memberName))).Verifiable();
                }

                // Act
                return(controller.CancelMemberRequest(account.Username, memberName));
            }
            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));
            }
示例#6
0
            private Task <ActionResult> InvokeRejectMember(
                OrganizationsController controller,
                Organization account,
                bool isAdmin,
                string confirmationToken  = defaultConfirmationToken,
                EntityException exception = null)
            {
                // Arrange
                controller.SetCurrentUser(GetCurrentUser(controller));

                var currentUser = controller.GetCurrentUser();

                var userService = GetMock <IUserService>();

                if (account != null)
                {
                    userService.Setup(u => u.FindByUsername(account.Username))
                    .Returns(account as User);
                }
                var setup = userService.Setup(u => u.RejectMembershipRequestAsync(It.IsAny <Organization>(), currentUser.Username, confirmationToken));

                if (exception != null)
                {
                    setup.Throws(exception);
                }
                else
                {
                    var membership = new Membership
                    {
                        Organization = account,
                        Member       = currentUser,
                        IsAdmin      = isAdmin,
                    };
                    setup.Returns(Task.CompletedTask).Verifiable();
                }

                // Act
                return(controller.RejectMemberRequest(account?.Username, confirmationToken));
            }