コード例 #1
0
        public void GetUsersFullName_returns_full_name_if_available()
        {
            var user = new User
                           {
                               Email = "[email protected]",
                               UserProfile = new UserProfile
                                                 {
                                                     FirstName = "FirstName",
                                                     LastName = "LastName"
                                                 }
                           };
            _users.Add(user);

            Assert.IsNotNullOrEmpty(user.Email);
            Assert.IsNotNullOrEmpty(user.UserProfile.FirstName);
            Assert.IsNotNullOrEmpty(user.UserProfile.LastName);

            var expectedFullName = string.Format("{0} {1}",
                                                 _users[0].UserProfile.FirstName,
                                                 _users[0].UserProfile.LastName).Trim();
            Assert.IsNotNullOrEmpty(expectedFullName);

            _mockUserRepository.Setup(x => x.GetAll()).Returns(_users.AsQueryable);

            _mockHttpContextBase.Setup(x => x.User.Identity.Name).Returns(user.Email);
            Assert.IsNotNullOrEmpty(_mockHttpContextBase.Object.User.Identity.Name);

            _accountController = new AccountController(null, null,
                                                       _mockUserRepository.Object,
                                                       _mockHttpContextBase.Object);

            var fullName = _accountController.GetUsersFullName();
            Assert.AreEqual(expectedFullName, fullName);
        }
コード例 #2
0
        public ActionResult Register(User user)
        {
            if (ModelState.IsValid) {
                var createAccountStatus = _userCudTasks.RegisterUser(user);

                if (createAccountStatus == MembershipCreateStatus.Success)
                    return RedirectToAction("List", "Product");

                ModelState.AddModelError("",
                                         AuthenticationTasks.AccountValidation.ErrorCodeToString(createAccountStatus));
            }

            var errors = ModelState
                .Where(x => x.Value.Errors.Count > 0)
                .Select(x => new {x.Key, x.Value.Errors})
                .ToArray();

            foreach (var modelError in errors.SelectMany(error => error.Errors)) {
                ModelState.AddModelError(string.Empty, modelError.ErrorMessage);
            }

            return View("Register", _userCudTasks.CreateEditViewModel(user));
        }
コード例 #3
0
        public void GetUsersFullName_returns_email_if_full_name_not_available()
        {
            var user = new User
                           {
                               Email = "[email protected]",
                               UserProfile = new UserProfile()
                           };
            _users.Add(user);

            Assert.IsNotNullOrEmpty(user.Email);
            Assert.IsNullOrEmpty(user.UserProfile.FirstName);
            Assert.IsNullOrEmpty(user.UserProfile.LastName);

            _mockUserRepository.Setup(x => x.GetAll()).Returns(_users.AsQueryable);

            _mockHttpContextBase.Setup(x => x.User.Identity.Name).Returns(user.Email);
            Assert.IsNotNullOrEmpty(_mockHttpContextBase.Object.User.Identity.Name);
            _accountController = new AccountController(null, null,
                                                       _mockUserRepository.Object,
                                                       _mockHttpContextBase.Object);

            var email = _accountController.GetUsersFullName();
            Assert.AreEqual(user.Email, email);
        }
コード例 #4
0
        public override MembershipUser CreateUser(string username, string password, string email,
                                                  string passwordQuestion, string passwordAnswer, bool isApproved,
                                                  object providerUserKey, out MembershipCreateStatus status)
        {
            var args = new ValidatePasswordEventArgs(username, password, true);
            OnValidatingPassword(args);

            if (args.Cancel) {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            if (RequiresUniqueEmail && GetUserNameByEmail(email) != string.Empty) {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            var user = GetUser(email, true /* is online */);

            if (user == null) {
                var shoppingCart = new ShoppingCart();
                var userProfile = new UserProfile();

                var salt = CreateSalt();
                var userObj = new User
                                  {
                                      Email = email,
                                      Password = ComputePasswordHash(password, salt),
                                      Salt = salt,
                                      ShoppingCart = shoppingCart,
                                      UserProfile = userProfile
                                  };

                UserRepository.SaveOrUpdate(userObj);

                status = MembershipCreateStatus.Success;

                return GetUser(userObj.Email, true);
            }

            status = MembershipCreateStatus.DuplicateEmail;

            return null;
        }