protected override void Context()
        {
            base.Context();
            _createAccountRequest = new CreateAccountRequest
                                        {
                                            FirstName = "Colin",
                                            LastName = "Callahan",
                                            EmailAddress = "*****@*****.**",
                                            Username = "******",
                                            Role = Role.Employee,
                                        };

            AuthorizationService.Stub(
                x => x.CanExecute(Arg<string>.Is.Equal(Username), Arg<Type>.Is.Equal(typeof (CreateAccountRequest)))).
                Return(true);

            _createAccountRequestValidator = MockRepository.GenerateStub<CreateAccountRequestValidator>();
            _createAccountRequestValidator.Stub(
                x => x.Validate(Arg<CreateAccountRequest>.Is.Equal(_createAccountRequest)))
                .Return(new ValidationResult());

            ValidatorFactory.Stub(
                x => x.GetValidator<CreateAccountRequest>())
                .Return(_createAccountRequestValidator);

            AccountRepository.Stub(x => x.UserNameExists(Arg<string>.Is.Equal(_createAccountRequest.Username)))
                .Return(false);

            CryptographyService.Stub(x => x.Encrypt(Arg<string>.Is.Equal(_createAccountRequest.Username + "_password")))
                .Return(EncryptedPassword);

            AccountRepository.Stub(
                x => x.Create(Arg<CreateAccountRequest>.Is.Equal(_createAccountRequest),
                         Arg<string>.Is.Equal(EncryptedPassword)))
                .WhenCalled(x => _createAccountRequestPassedToRepository = x.Arguments[0] as CreateAccountRequest)
                .WhenCalled(x => _encryptedPasswordPassedToRepository = x.Arguments[1].ToString());

            SettingsProvider.Stub(x => x.GetEmailSettings())
                .Return(new EmailSettings
                            {
                                AdminEmailAddress = AdminEmailAddress,
                            });

            EmailService.Stub(x => x.SendEmail(Arg<SendMailRequest>.Is.Anything))
                .WhenCalled(x => _sendMailRequestPassedToMailService = x.Arguments[0] as SendMailRequest);

            _expectedCreateAccountResponse = new CreateAccountResponse
                                                 {
                                                     Success = true,
                                                 };

            _expectedCreateAccountRequest = new CreateAccountRequest
                                                {
                                                    FirstName = "Colin",
                                                    LastName = "Callahan",
                                                    EmailAddress = "*****@*****.**",
                                                    Username = "******",
                                                    Role = Role.Employee,
                                                };
        }
        protected override void Context()
        {
            Username = "******";
            base.Context();

            _createAccountInputModel = new CreateAccountInputModel
                                           {
                                               FirstName = "Catherine",
                                               LastName = "Weir",
                                               EmailAddress = "*****@*****.**",
                                               Username = "******",
                                               Role = Role.Administrator,
                                           };

            _createAccountRequestReturnedFromMappingEngine = new CreateAccountRequest
            {
                FirstName = _createAccountInputModel.FirstName,
                LastName = _createAccountInputModel.LastName,
                EmailAddress = _createAccountInputModel.LastName,
                Username = _createAccountInputModel.Username,
                Role = _createAccountInputModel.Role,
            };

            MappingEngine.Stub(
                x => x.Map<CreateAccountInputModel, CreateAccountRequest>(
                    Arg<CreateAccountInputModel>.Is.Equal(_createAccountInputModel)))
                .Return(_createAccountRequestReturnedFromMappingEngine);

            AccountCreator.Stub(
                x => x.Execute(Arg<string>.Is.Anything, Arg<CreateAccountRequest>.Is.Anything))
                .Throw(_exceptionThrownByDomain);

            Logger.Stub(x => x.LogException(Arg<Exception>.Is.Equal(_exceptionThrownByDomain)))
                .WhenCalled(x => _exceptionPassedToLogger = x.Arguments[0] as Exception);
        }
        protected override void Context()
        {
            base.Context();
            _createAccountRequest = new CreateAccountRequest
                                        {
                                            FirstName = "Colin",
                                            LastName = "Callahan",
                                            EmailAddress = "*****@*****.**",
                                        };

            AuthorizationService.Stub(
                x => x.CanExecute(Arg<string>.Is.Equal(Username), Arg<Type>.Is.Equal(typeof (CreateAccountRequest)))).
                Return(true);

            _createAccountRequestValidator = MockRepository.GenerateStub<CreateAccountRequestValidator>();
            _createAccountRequestValidator.Stub(
                x => x.Validate(Arg<CreateAccountRequest>.Is.Equal(_createAccountRequest)))
                .Return(new ValidationResult());

            ValidatorFactory.Stub(
                x => x.GetValidator<CreateAccountRequest>())
                .Return(_createAccountRequestValidator);

            AccountRepository.Stub(x => x.UserNameExists(Arg<string>.Is.Equal(_createAccountRequest.Username)))
                .Return(true);

            _expectedCreateAccountResponse = new CreateAccountResponse
                                                 {
                                                     Success = false,
                                                     Errors = new List<string>{"The username " + _createAccountRequest.Username + " is unavailable.",}
                                                 };
        }
        protected override void Context()
        {
            Username = "******";
            base.Context();
            _createAccountInputModel = new CreateAccountInputModel
                                           {
                                               FirstName = "Catherine",
                                               LastName = "Weir",
                                               EmailAddress = "*****@*****.**",
                                               Username = "******",
                                               Role = Role.Administrator,
                                           };

            _createAccountRequestReturnedFromMappingEngine = new CreateAccountRequest
                                                                 {
                                                                     FirstName = _createAccountInputModel.FirstName,
                                                                     LastName = _createAccountInputModel.LastName,
                                                                     EmailAddress = _createAccountInputModel.LastName,
                                                                     Username = _createAccountInputModel.Username,
                                                                     Role = _createAccountInputModel.Role,
                                                                 };
            MappingEngine.Stub(
                x =>
                x.Map<CreateAccountInputModel, CreateAccountRequest>(
                    Arg<CreateAccountInputModel>.Is.Equal(_createAccountInputModel)))
                .Return(_createAccountRequestReturnedFromMappingEngine);

            AccountCreator.Stub(
                x => x.Execute(Arg<string>.Is.Anything, Arg<CreateAccountRequest>.Is.Anything))
                .WhenCalled(
                    x => _actualCreateAccountRequestPassedToDomainService = x.Arguments[1] as CreateAccountRequest)
                .Return(new CreateAccountResponse {Success = true,});
        }
Esempio n. 5
0
        public CreateAccountResponse Execute(string username, CreateAccountRequest createAccountRequest)
        {
            if (!_authorizationService.CanExecute(username, "CreateAccounts"))
                return new CreateAccountResponse
                           {
                               Success = false,
                               Errors = new List<string>
                                            {
                                                "User is not authorized to Create Accounts",
                                            },
                           };

            IValidator<CreateAccountRequest> createAccountValidator =
                _validatorFactory.GetValidator<CreateAccountRequest>();
            ValidationResult validationResult = createAccountValidator.Validate(createAccountRequest);
            if (!validationResult.IsValid)
                return new CreateAccountResponse
                           {
                               Success = false,
                               Errors = validationResult.Errors.Select(x => x.ErrorMessage),
                           };

            if (_accountRepository.UserNameExists(createAccountRequest.Username))
                return new CreateAccountResponse
                           {
                               Success = false,
                               Errors =
                                   new List<string>
                                       {"The username " + createAccountRequest.Username + " is unavailable."}
                           };

            string tempPassword = createAccountRequest.Username + "_password";
            string encryptedTempPassword = _cryptographyService.Encrypt(tempPassword);

            _accountRepository.Create(createAccountRequest, encryptedTempPassword);

            string loginUrl = ConfigurationManager.AppSettings["HostUrl"];

            var message = new StringBuilder();
            message.Append("<html><head><title></title></head><body>");
            message.Append("<div style='font-size: 12px;font-weight: bold;font-style: italic;'>");
            message.Append("Please login at " + loginUrl + " using the following information<br/>");
            message.Append("Username: "******"<br/>");
            message.Append("Password: "******"</div></body></html>");
            _emailService.SendEmail(new SendMailRequest
                                        {
                                            To = createAccountRequest.EmailAddress,
                                            Subject = "Your Brand Journalists Employee account has been created",
                                            Message = message.ToString(),
                                        });

            return new CreateAccountResponse
                       {
                           Success = true,
                       };
        }
        protected override void Context()
        {
            base.Context();

            _createAccountRequest = new CreateAccountRequest
                                        {
                                            EmailAddress = "someinvalidemailaddress",
                                            Username = "******",
                                        };

            _expectedResult = new ValidationResult(new List<ValidationFailure>
                                                       {
                                                           new ValidationFailure("EmailAddress", "Email address is not valid."),
                                                           new ValidationFailure("Username", "Username has some invalid characters."),
                                                       });
        }
Esempio n. 7
0
        public void Create(CreateAccountRequest createAccountRequest, string encryptedPassword)
        {
            using (var context = new PRToolsEntities())
            {
                string roleName = createAccountRequest.Role.ToString();
                Role roleEntity = context.Roles.SingleOrDefault(x => x.RoleName == roleName);
                var accountEntity = new Account
                                        {
                                            FirstName = createAccountRequest.FirstName,
                                            LastName = createAccountRequest.LastName,
                                            Username = createAccountRequest.Username,
                                            Password = encryptedPassword,
                                            Email = createAccountRequest.EmailAddress,
                                            Role = roleEntity,
                                            MustChangePassword = true,
                                        };

                context.Accounts.AddObject(accountEntity);
                context.SaveChanges();
            }
        }
        protected override void Context()
        {
            base.Context();

            _createAccountRequest = new CreateAccountRequest();

            AuthorizationService.Stub(
                x => x.CanExecute(Arg<string>.Is.Equal(Username), Arg<Type>.Is.Equal(typeof (CreateAccountRequest)))).
                Return(true);

            _validationResultReturnedFromValidator = new ValidationResult(new List<ValidationFailure>
                                                                              {
                                                                                  new ValidationFailure("FirstName",
                                                                                                        "First Name cannot be empty."),
                                                                                  new ValidationFailure("LastName",
                                                                                                        "Last Name cannot be empty."),
                                                                                  new ValidationFailure("EmailAddress",
                                                                                                        "Email Address cannot be empty."),
                                                                                  new ValidationFailure("Username",
                                                                                                        "Username cannot be empty."),
                                                                                  new ValidationFailure("Role",
                                                                                                        "Role cannot be empty."),

                                                                              });

            _createAccountRequestValidator = MockRepository.GenerateStub<CreateAccountRequestValidator>();
            _createAccountRequestValidator.Stub(
                x => x.Validate(Arg<CreateAccountRequest>.Is.Equal(_createAccountRequest)))
                .Return(_validationResultReturnedFromValidator);

            ValidatorFactory.Stub(
                x => x.GetValidator<CreateAccountRequest>())
                .Return(_createAccountRequestValidator);

            _expectedCreateAccountResponse = new CreateAccountResponse
                                                 {
                                                     Success = false,
                                                     Errors = _validationResultReturnedFromValidator.Errors.Select(x=>x.ErrorMessage),
                                                 };
        }