public IHttpActionResult Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var errorList = ModelState.ToDictionary(kvp => kvp.Key.Replace("model.", ""), kvp => kvp.Value.Errors[0].ErrorMessage);
                return ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, errorList));
            }

            var pendingUser = _queryDispatcher.Dispatch(new GetPendingUserDetailsByGuidQuery { PendingUserId = model.PendingUserId });
            if (pendingUser == null)
            {
                return ResponseMessage(
                    Request.CreateErrorResponse(
                        HttpStatusCode.PreconditionFailed,
                        string.Format(PendingUserNotFound, model.PendingUserId)
                    )
                );
            }

            var peninsulaClient = _queryDispatcher.Dispatch(new GetPeninsulaClientIdByCanQuery { CAN = pendingUser.CAN });
            if (peninsulaClient == null)
            {
                return ResponseMessage(
                    Request.CreateErrorResponse(
                        HttpStatusCode.ExpectationFailed,
                        string.Format(PeninsulaClientNotFound, pendingUser.CAN)
                    )
                );
            }

            var existingUser = _queryDispatcher.Dispatch(new GetUserProfileByUserNameQuery { UserName = pendingUser.Email });
            if (existingUser != null)
            {
                return ResponseMessage(
                    Request.CreateErrorResponse(
                        HttpStatusCode.Conflict,
                        string.Format(UserAlreadyExists, pendingUser.Email)
                    )
                );
            }

            try
            {
                var registerCommand = new RegisterCommand
                {
                    Email = pendingUser.Email,
                    Password = model.Password,
                    ConfirmPassword = model.ConfirmPassword,
                    FirstName = pendingUser.FirstName,
                    LastName = pendingUser.LastName,
                    ClientId = peninsulaClient.ClientId
                };

                var sendRegistrationCompleteEmailCommand = new SendRegistrationCompleteEmailCommand
                {
                    Email = pendingUser.Email
                };

                _commandDispatcher.Dispatch(registerCommand);
                _commandDispatcher.Dispatch(sendRegistrationCompleteEmailCommand);

                DeletePendingUser(pendingUser.PendingUserId);
                return Ok(Success);
            }
            catch (Exception ex)
            {
                throw new ArgumentException(string.Format(Failed, model.PendingUserId));
            }
            #region attempted to hook into the default ApplicationUser to check if a user exists and enforce the password strength. will need some help with that
            //var user = new ApplicationUser { Email = model.Email, UserName = model.Email };
            //var result = ApplicationUserManager.Create(user, model.Password);
            //if (result.Succeeded)
            //{
            //    var ctx = this.Request.GetOwinContext();
            //    UserManager.AddClaim(user.Id, new Claim("PBS.ClientId", model.CAN));
            //    response = "Registration Successful";
            //}
            //else
            //{
            //    response = result.Errors;
            //}
            #endregion
        }
        public void Setup()
        {
            _registerViewModel = new RegisterViewModel();
            _emptyRegisterViewModel = new RegisterViewModel();
            _existingRegisterViewModel = new RegisterViewModel { PendingUserId = ExistingGuid };

            _mockCommandDispatcher = new Mock<ICommandDispatcher>();
            _mockCommandDispatcher
                .Setup(m => m.Dispatch(new RegisterCommand()))
                .Verifiable();

            _mockQueryDispatcher = new Mock<IQueryDispatcher>();
            _mockQueryDispatcher
                .Setup(m => m.Dispatch(It.IsAny<GetPendingUserDetailsByGuidQuery>()))
                .Returns((GetPendingUserDetailsByGuidQuery query) => TestData.PendingUsersList.First(p => p.Id == query.PendingUserId).ToRegisterViewModel());

            //_getGetUserProfileByUserNameQuery = new GetUserProfileByUserNameQuery {UserName = "******"};
            //_mockQueryDispatcher
            //    .Setup(m => m.Dispatch(_getGetUserProfileByUserNameQuery))
            //    .Returns(new UserViewModel() { UserName = "******" } );

            //_mockQueryDispatcher
            //    .Setup(m => m.Dispatch(new GetNewUserDetailsByGuidQuery() { Id = ExistingGuid }))
            //    .Returns(TestData.PendingUsersList);

            _controller = new AccountController(_mockCommandDispatcher.Object, _mockQueryDispatcher.Object);
        }
        //[Test]
        public void Test_Register_Returns_Valid_IHttpActionResult_To_Indicate_Method_Was_Called()
        {
            _registerViewModel = new RegisterViewModel() { PendingUserId = Guid.Parse("4b8086bb-6565-4ac9-b325-21c0f7c87fb8"), Password = "******", ConfirmPassword = "******" };
            var httpActionResult = _controller.Register(_registerViewModel);
            Assert.IsInstanceOf<OkNegotiatedContentResult<string>>(httpActionResult);

            var response = httpActionResult as OkNegotiatedContentResult<string>;
            Debug.Assert(response != null);
            Assert.IsNotNullOrEmpty(response.Content);
        }
        //[Test]
        public void Given_RegisterViewModel_Is_Valid_And_Not_Registered_Register_Method_Returns_Registration_Successful()
        {
            _registerViewModel = new RegisterViewModel() { PendingUserId = Guid.Parse("4b8086bb-6565-4ac9-b325-21c0f7c87fb8"), Password = "******", ConfirmPassword = "******" };

            var httpActionResult = _controller.Register(_registerViewModel);
            var response = httpActionResult as OkNegotiatedContentResult<string>;
            Debug.Assert(response != null);
            Assert.AreEqual("Registration Successful", response.Content);
        }