public ActionResult HomePost(IPrincipal principal)
        {
            var user = new User();

            try
            {
                TryUpdateModel(user);

                // User name cannot have the character '-' because it is used to concatenate the user name and indentity provider in the Users table.
                if (user.Name.Contains("-"))
                {
                    ViewBag.ValidationErrors = new List<ValidationResult> { new ValidationResult("User name cannot have the character '-'") };
                    return View(user);
                }

                if (user.IsValid())
                {
                    _usersService.FillAuthenticationInfo(user, principal);
                    _usersService.Create(user);
                    Session["CurrentUser"] = user;
                    return RedirectToAction("Index", "TaskLists");
                }
                else
                {
                    ViewBag.ValidationErrors = user.GetValidationErrors();
                }
            }
            catch (Exception ex)
            {
                ViewBag.ValidationErrors = new List<ValidationResult> { new ValidationResult(string.Format("User creation exception: {0}", ex.Message)) };
            }

            return View(user);
        }
        public void AUserWithAnNameThatHasTheCharacterPlusIsInvalid()
        {
            // Arrange
            var user = new User() { PartitionKey = "windowsliveid", RowKey = "user.test-windowsliveid", Name = "user+name" };

            // Act
            var validationResult = user.IsValid();

            // Assert
            Assert.IsFalse(validationResult);
        }
        public void AUserWithAValidEmailIsValid()
        {
            // Arrange
            var user = new User() { PartitionKey = "windowsliveid", RowKey = "user.test-windowsliveid", Name = "usertest", Email = "*****@*****.**" };

            // Act
            var validationResult = user.IsValid();

            // Assert
            Assert.IsTrue(validationResult);
        }
        public void AUserWithAnNameAllWhitespacesIsInvalid()
        {
            // Arrange
            var user = new User() { PartitionKey = "windowsliveid", RowKey = "user.test-windowsliveid", Name = " " };

            // Act
            var validationResult = user.IsValid();

            // Assert
            Assert.IsFalse(validationResult);
        }