public ActionResult Create(UserProfile model)
        {
            var validator = new UserProfileValidator();

            var result = validator.Validate(model);

            if (result.IsValid)
            {
                userProfileService.SaveProfile(model);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Пример #2
0
        public void Should_FailValidationWithMessage_When_DisplayNameIsNull()
        {
            // Arrange
            var userProfileValidator = new UserProfileValidator();
            var userProfile          = new UserProfile()
            {
                DisplayName = null
            };

            // Act
            var result  = userProfileValidator.Validate(userProfile, ruleSet: "CreateUser");
            var isValid = result.IsValid;

            // Assert
            isValid.Should().Be(false);
        }
Пример #3
0
        public void Should_PassValidation_When_AllRulesPass()
        {
            // Arrange
            var userProfileValidator = new UserProfileValidator();
            var userProfile          = new UserProfile()
            {
                DisplayName = "displayname"
            };

            // Act
            var result  = userProfileValidator.Validate(userProfile, ruleSet: "CreateUser");
            var isValid = result.IsValid;

            // Assert
            isValid.Should().Be(true);
        }