public void Arrange()
        {
            _user = new User
            {
                Id = UserId
            };

            _mediator = new Mock <IMediator>();
            _mediator.Setup(m => m.SendAsync(It.Is <GetUserByIdQuery>(q => q.UserId == UserId)))
            .Returns(Task.FromResult(_user));
            _mediator.Setup(m => m.SendAsync(It.IsAny <ChangeEmailCommand>()))
            .ThrowsAsync(new Exception("Called mediator with incorrect ChangeEmailCommand"));
            _mediator.Setup(m => m.SendAsync(It.Is <ChangeEmailCommand>(c => c.User == _user && c.SecurityCode == SecurityCode && c.Password == Password)))
            .Returns(Task.FromResult(new ChangeEmailCommandResult
            {
                ReturnUrl = ReturnUrl
            }));

            _owinWrapper = new Mock <IOwinWrapper>();
            _logger      = new Mock <ILogger>();

            _orchestrator = new AccountOrchestrator(_mediator.Object, _owinWrapper.Object, _logger.Object);

            _model = new ConfirmChangeEmailViewModel
            {
                UserId       = UserId,
                SecurityCode = SecurityCode,
                Password     = Password
            };
        }
예제 #2
0
        public override void Arrange()
        {
            base.Arrange();

            AddUserToContext(UserId);

            _accountOrchestrator = new Mock <AccountOrchestrator>();
            _accountOrchestrator.Setup(o => o.ConfirmChangeEmail(It.IsAny <ConfirmChangeEmailViewModel>()))
            .Returns((ConfirmChangeEmailViewModel model) => Task.FromResult(new ConfirmChangeEmailViewModel
            {
                SecurityCode = model.SecurityCode,
                Password     = model.Password,
                UserId       = model.UserId,
                ReturnUrl    = ReturnUrl
            }));

            _owinWrapper = new Mock <IOwinWrapper>();

            _controller = new AccountController(_accountOrchestrator.Object, _owinWrapper.Object, new IdentityServerConfiguration(), _logger.Object);
            _controller.ControllerContext = _controllerContext.Object;

            _model = new ConfirmChangeEmailViewModel
            {
                SecurityCode = SecurityCode,
                Password     = Password
            };
        }
        public virtual async Task <ConfirmChangeEmailViewModel> ConfirmChangeEmail(ConfirmChangeEmailViewModel model)
        {
            try
            {
                var user = await _mediator.SendAsync(new GetUserByIdQuery
                {
                    UserId = model.UserId
                });

                var changeEmailResult = await _mediator.SendAsync(new ChangeEmailCommand
                {
                    User         = user,
                    SecurityCode = model.SecurityCode,
                    Password     = model.Password
                });

                model.ReturnUrl = changeEmailResult.ReturnUrl;
            }
            catch (InvalidRequestException ex)
            {
                model.ErrorDictionary = ex.ErrorMessages;
            }
            catch (Exception ex)
            {
                model.ErrorDictionary.Add("", ex.Message);
            }
            return(model);
        }
예제 #4
0
        public async Task <ActionResult> ConfirmChangeEmail(ConfirmChangeEmailViewModel model)
        {
            model.UserId = GetLoggedInUserId();

            model = await _accountOrchestrator.ConfirmChangeEmail(model);

            if (model.Valid)
            {
                return(Redirect(model.ReturnUrl));
            }

            model.SecurityCode = string.Empty;
            model.Password     = string.Empty;
            return(View(new OrchestratorResponse <ConfirmChangeEmailViewModel>()
            {
                Data = model
            }));
        }
        public virtual async Task <bool> ResendLastConfirmationCode(ConfirmChangeEmailViewModel model)
        {
            try
            {
                await _mediator.SendAsync(new ResendActivationCodeCommand
                {
                    UserId = model.UserId
                });

                return(true);
            }
            catch (InvalidRequestException ex)
            {
                _logger.Info(ex, ex.Message);
                return(false);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, ex.Message);
                return(false);
            }
        }