internal static MaxLengthValidator ValidateContact(this MaxLengthValidator validator, IUpdateSolutionContact contact)
 => validator
 .Validate(contact?.FirstName, FirstNameMaxLength, "first-name")
 .Validate(contact?.LastName, LastNameMaxLength, "last-name")
 .Validate(contact?.Email, EmailMaxLength, "email-address")
 .Validate(contact?.PhoneNumber, PhoneMaxLength, "phone-number")
 .Validate(contact?.Department, DepartmentMaxLength, "department-name");
Ejemplo n.º 2
0
 internal static MaxLengthValidator ValidateContact(this MaxLengthValidator validator, UpdateSolutionContactViewModel contact, string contactTag)
 => validator
 .Validate(contact?.FirstName, FirstNameMaxLength, $"{contactTag}-first-name")
 .Validate(contact?.LastName, LastNameMaxLength, $"{contactTag}-last-name")
 .Validate(contact?.Email, EmailMaxLength, $"{contactTag}-email-address")
 .Validate(contact?.PhoneNumber, PhoneMaxLength, $"{contactTag}-phone-number")
 .Validate(contact?.Department, DepartmentMaxLength, $"{contactTag}-department-name");
Ejemplo n.º 3
0
        public void IfMaxLengthExceededValidationShouldBeFalse()
        {
            var element = new ElementBuilder()
                          .WithQuestionId("test-id")
                          .WithLabel("Label")
                          .WithNumeric(false)
                          .WithMaxLength(20)
                          .Build();


            var viewModel = new Dictionary <string, dynamic>()
            {
                { "test-id", "123456789012345678901234567890" }
            };

            var result = _validator.Validate(element, viewModel, new form_builder.Models.FormSchema());

            Assert.False(result.IsValid);
            Assert.Equal("Label has a maximum length of 20", result.Message);
        }
Ejemplo n.º 4
0
        public void MaxLengthValidator_Respects_MaxLength_Attribute_When_Value_Is_Null()
        {
            Place p = new Place();

            p.Name        = "Foo";
            p.Description = null;

            MaxLengthValidator maxLengthValidator = new MaxLengthValidator();

            maxLengthValidator.Validate(p);
        }
Ejemplo n.º 5
0
        public void MaxLengthValidator_Respects_MaxLength_Attribute_When_Length_Equal_To_MaxLength()
        {
            Place p = new Place();

            p.Name        = "Foo";
            p.Description = new string('a', 10);

            MaxLengthValidator maxLengthValidator = new MaxLengthValidator();

            maxLengthValidator.Validate(p);
        }
Ejemplo n.º 6
0
        public void MaxLengthValidator_Respects_MaxLength_Attribute_When_Length_Greater_Than_MaxLength()
        {
            Place p = new Place();

            p.Name        = "Foo";
            p.Description = new string('a', 11);

            MaxLengthValidator maxLengthValidator = new MaxLengthValidator();

            Assert.Throws <InvalidOperationException>(() => maxLengthValidator.Validate(p));
        }
Ejemplo n.º 7
0
        public MaxLengthResult Validate(UpdateSolutionFeaturesCommand updateSolutionFeaturesCommand)
        {
            var listing   = updateSolutionFeaturesCommand.UpdateSolutionFeaturesViewModel.Listing.ToList();
            var validator = new MaxLengthValidator();

            for (int i = 0; i < listing.Count(); i++)
            {
                validator.Validate(listing[i], 100, $"listing-{i + 1}");
            }

            return(validator.Result());
        }
Ejemplo n.º 8
0
        public virtual void testMaxLengthValidator()
        {
            var validator = new MaxLengthValidator();

            Assert.True(validator.Validate(null, null));

            Assert.True(validator.Validate("test", new TestValidatorContext("5")));
            Assert.IsFalse(validator.Validate("test", new TestValidatorContext("4")));

            try
            {
                validator.Validate("test", new TestValidatorContext("4.4"));
                Assert.Fail("exception expected");
            }
            catch (FormException e)
            {
                Assert.True(
                    e.Message.Contains(
                        "Cannot validate \"maxlength\": configuration 4.4 cannot be interpreted as Integer"));
            }
        }
        public ISimpleResult Validate(UpdateSolutionFeaturesCommand command)
        {
            var listing   = command.Data.Listing.ToList();
            var validator = new MaxLengthValidator();

            for (int i = 0; i < listing.Count; i++)
            {
                validator.Validate(listing[i], 100, $"listing-{i + 1}");
            }

            return(validator.Result());
        }
Ejemplo n.º 10
0
        public void Insert <T>(IDbConnection connection, IEnumerable <T> entities, IDbTransaction transaction, int?commandTimeout) where T : class
        {
            IClassMapper classMap   = SqlGenerator.Configuration.GetMap <T>();
            var          properties = classMap.Properties.Where(p => p.KeyType != KeyType.NotAKey);

            foreach (var e in entities)
            {
                _maxLengthValidator.Validate(e);

                foreach (var column in properties)
                {
                    if (column.KeyType == KeyType.Guid)
                    {
                        Guid comb = SqlGenerator.Configuration.GetNextGuid();
                        column.PropertyInfo.SetValue(e, comb, null);
                    }
                }
            }

            string sql = SqlGenerator.Insert(classMap);

            connection.Execute(sql, entities, transaction, commandTimeout, CommandType.Text);
        }
        public void Then_correct_errors_are_returned(string input, string maxLength, bool isValid)
        {
            var validator = new MaxLengthValidator
            {
                ValidationDefinition = new ValidationDefinition()
                {
                    ErrorMessage = "Length exceeded",
                    Name         = "MaxLength",
                    Value        = maxLength
                }
            };

            var question = new Question {
                QuestionId = "Q1"
            };
            var errors = validator.Validate(question, new Answer {
                Value = input, QuestionId = question.QuestionId
            });

            (errors.Count is 0).Should().Be(isValid);
        }