예제 #1
0
        public void GivenValidLoginDetails_WhenCheckLoginDetailsCalled_ReturnUser()
        {
            // Arrange
            var signUpDetails = A.Fake <UserSignUpViewModel>();

            signUpDetails.Email    = "*****@*****.**";
            signUpDetails.Password = "******";

            List <User> users           = A.Fake <List <User> >();
            var         fakeUserDetails = A.Fake <User>();

            fakeUserDetails.Email    = "*****@*****.**";
            fakeUserDetails.Password = "******";
            users.Add(fakeUserDetails);

            A.CallTo(() => _userRepository.GetAll()).Returns(users);

            // Act
            var result = _signUpService.GetUserDetails(signUpDetails);

            // Assert
            Assert.That(result, Is.Not.Null);
            Assert.AreSame(result, fakeUserDetails);
            A.CallTo(() => _userRepository.GetAll()).MustHaveHappened(Repeated.Exactly.Once);
        }
예제 #2
0
        public ActionResult SigningUp(UserSignUpViewModel userSignUpDetails)
        {
            ValidationResult results = _validator.Validate(userSignUpDetails);

            if (results.IsValid)  //  valid signup, update DB and redirect to profile page
            {
                // add new user to db
                _signUpService.AddUser(userSignUpDetails);

                // retrieve newly added user's details from db
                User userProfile = _signUpService.GetUserDetails(userSignUpDetails);
                Session["userId"] = userProfile.UserId;

                return(RedirectToAction("MyProfile", "Profiles"));
            }
            else
            {
                foreach (ValidationFailure failure in results.Errors)
                {
                    ModelState.AddModelError(failure.PropertyName, failure.ErrorMessage);
                }

                ViewBag.Message = "Error in SignUp Occured";
                return(View(userSignUpDetails));
            }
        }