コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public void AUserWithAnNameAllWhitespacesIsInvalid()
        {
            // Arrange
            var user = new User() { PartitionKey = "windowsliveid", RowKey = "user.test-windowsliveid", Name = " " };

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

            // Assert
            Assert.IsFalse(validationResult);
        }