public string GetErrorInfo(Validation.ValidationException exc) { StringBuilder text = new StringBuilder(); if (exc.ErrorInfos.Count > 0) { foreach (ErrorInfo info in exc.ErrorInfos) { foreach (ErrorText error in info.Errors) { if (text.Length > 0) text.AppendLine(); string errorText = string.Format(RuntimeContext.Service.L10N.GetText(error.Text) + "。", error.Args); foreach (var f in info.FieldName) { text.Append(RuntimeContext.Service.L10N.GetText(f)); text.Append(" "); } text.Append(errorText); } } } else text.Append(exc.Message); return text.ToString(); }
public virtual RestResponse ActivateMonitors(int[] monitorIds, string tag, OutputType? output = null, Validation? validation = null) { var parameters = new Dictionary<string, object>(); AddIfNotNull(parameters, Params.monitorIds, string.Join(",", monitorIds)); AddIfNotNull(parameters, Params.tag, tag); RestResponse resp = MakePostRequest(GetAction(MonitorAction.activateMonitors), parameters, output: output, validation: validation); return resp; }
public BlockBase(string key, Line[] lines, string[] tags, GroupInfo group, Logger log) : base(-1, key, lines) { Group = group; Log = log; Valid = Validation.NeverRan; if (tags != null && tags.Length > 0) this.tags = new HashSet<string>(tags); }
protected override Dictionary<PropertyEditor, Validation.RuleType.RuleType> CollectPropertyEditors(IEnumerable<RuleSetValidationResultItem> result, Validation.RuleType.RuleType ruleType) { var propertyEditors = base.CollectPropertyEditors(result, ruleType); foreach (var keyValuePair in propertyEditors) { var baseEdit = keyValuePair.Key.Control as BaseEdit; if (baseEdit != null) baseEdit.ErrorIcon = CreateImageFromResources(keyValuePair.Value); } return propertyEditors; }
/// <summary> /// This action is used for contact activating. /// </summary> /// <param name="contactId">id of the contact to activate</param> /// <param name="output">Type of output - XML or JSON</param> /// <param name="validation">HMACSHA1 for checksum validation or token for authToken validation</param> public void ActivateContact(int contactId, OutputType? output = null, Validation? validation = null) { var parameters = new Dictionary<string, object>(); parameters.Add(Params.contactId, contactId); RestResponse response = MakePostRequest(ContactAction.contactActivate, parameters, output: output, validation: validation); Helper.CheckStatus(response, GetOutput(output)); }
public void Matches_GivenValidString_DontReturnErrors(string pis) { var person = new Person() { Pis = pis }; var errors = new Validation<Person>(person) .Matches(x => x.Pis, @"^\d+$", "Error {0}") .ToList(); Assert.Equal(0, errors.Count); }
public void IsTimespan_GivenValidField_DontReturnErrors(string timespan) { var person = new Person() { Hour = timespan }; var errors = new Validation<Person>(person) .IsTimespan(x => x.Hour) .ToList(); Assert.Equal(0, errors.Count); }
public void IsRequired_GivenValidString_DontReturnErrors() { var person = new Person() { Name = "Fernando" }; var errors = new Validation<Person>(person) .IsRequired(x => x.Name) .ToList(); Assert.Equal(0, errors.Count); }
public void IsUnique_GivenSameNameAndSameId_DontReturnErrors() { var person = new Person() { Id = 1, Name = "fernando" }; var errors = new Validation<Person>(person, context) .IsUnique(x => x.Name) .ToList(); Assert.Equal(0, errors.Count); }
public void IsRequired_GivenValidInt_DontReturnErrors() { var person = new Person() { Age = 21 }; var errors = new Validation<Person>(person) .IsRequired(x => x.Age) .ToList(); Assert.Equal(0, errors.Count); }
public void IsUnique_GivenNewAgeAndSameId_DontReturnErrors() { var person = new Person() { Id = 1, Age = 25 }; var errors = new Validation<Person>(person, context) .IsUnique(x => x.Age) .ToList(); Assert.Equal(0, errors.Count); }
public void IsBetween_GivenValidFloatValue_DontReturnErrors(int height) { var person = new Person() { Id = 2, Height = height}; var errors = new Validation<Person>(person, context) .IsBetween(x => x.Height, 100, 250) .ToList(); Assert.Equal(0, errors.Count); }
public void IsBetween_GivenValidIntValue_DontReturnErrors(int age) { var person = new Person() { Id = 2, Age = age }; var errors = new Validation<Person>(person, context) .IsBetween(x => x.Age, 18, 60) .ToList(); Assert.Equal(0, errors.Count); }
public void HasMaxLength_GivenValidField_DontReturnErrors(string name, int maxLength) { var person = new Person() { Name = name }; var errors = new Validation<Person>(person) .HasMaxLength(x => x.Name, maxLength) .ToList(); Assert.Equal(0, errors.Count); }
public void IsCnpj_GivenValidField_DontReturnErrors(string cnpj) { var person = new Person() { Cnpj = cnpj }; var errors = new Validation<Person>(person) .IsCnpj(x => x.Cnpj) .ToList(); Assert.Equal(0, errors.Count); }
public void HasSmallDateTime_GivenValidNullableField_DontReturnErrors(int year, int month, int day) { var person = new Person() { Death = new DateTime(year, month, day) }; var errors = new Validation<Person>(person) .IsSmallDateTime(x => x.Death) .ToList(); Assert.Equal(0, errors.Count); }
public virtual void DeleteMonitors(int[] monitorIds, OutputType? output = null, Validation? validation = null) { var parameters = new Dictionary<string, object>(); if (monitorIds != null) { parameters.Add(Params.monitorId, string.Join(",", monitorIds)); } RestResponse resp = MakePostRequest(GetAction(MonitorAction.deleteMonitor), parameters, output: output, validation: validation); }
public void IsUnique_GivenEmptyAgeField_DontReturnErrors() { var person = new Person() { Id = 2, Name = "alex" }; var errors = new Validation<Person>(person, context) .IsUnique(x => x.Age) .ToList(); Assert.Equal(0, errors.Count); }
public void IsEmail_GivenValidField_DontReturnErrors(string email) { var person = new Person() { Email = email }; var errors = new Validation<Person>(person) .IsEmail(x => x.Email) .ToList(); Assert.Equal(0, errors.Count); }
public void IsRequired_GivenValidDateTime_DontReturnErrors() { var person = new Person() { Birth = new DateTime(1990, 5, 15) }; var errors = new Validation<Person>(person) .IsRequired(x => x.Birth) .ToList(); Assert.Equal(0, errors.Count); }
public void HasCustomValidation_GivenSimpleFalseCondition_ReturnErrors() { var person = new Person(); var errors = new Validation<Person>(person, context) .HasCustomValidation(x => false, "Email", "Preencha o campo Email corretamente") .ToList(); Assert.Equal("Preencha o campo Email corretamente", errors[0].Message); }
public void HasCustomValidation_GivenTrueCondition_DontReturnErrors() { var person = new Person() { Id = 2, Age = 20, Email = "*****@*****.**" }; var errors = new Validation<Person>(person, context) .HasCustomValidation(x => true, "Email", "Preencha o campo Email corretamente") .ToList(); Assert.Equal(0, errors.Count); }
public void ShouldBeAbleToSaveAndGetAValidation() { var validation = new Validation<Person>() .Setup(v => v.IsNotNull(p => p.Name, "Name is mandatory")); var validationRepository = new ValidationRepository(); validationRepository.Save(validation); var fetchedValidation = validationRepository.Get<Person>("Default_Validation"); Assert.AreEqual(validation, fetchedValidation); }
public void IsPis_GivenValidField_DontReturnErrors(string pis) { var person = new Person() { Pis = pis }; var errors = new Validation<Person>(person) .IsPis(x => x.Pis) .ToList(); Assert.Equal(0, errors.Count); }
public void HasCustomValidation_GivenFalseCondition_ReturnErrors() { var person = new Person() { Id = 2, Age = 20, Email = "*****@*****.**" }; var errors = new Validation<Person>(person, context) .HasCustomValidation(x => !((x.Email == "*****@*****.**" || x.Id == 1) && x.Age > 0), "Email", "Preencha o campo Email corretamente") .ToList(); Assert.Equal(1, errors.Count); Assert.Equal("Preencha o campo Email corretamente", errors[0].Message); }
/// <summary> /// This action is used to add new pages for the specified sub account. /// </summary> /// <param name="userId">user id of the sub account to add pages to</param> /// <param name="pageNames">names of your pages you want to share with your sub account </param> /// <param name="output">Type of output - XML or JSON</param> /// <param name="validation">HMACSHA1 for checksum validation or token for authToken validation</param> public void AddPagesToSubAccount(int userId, string[] pageNames, OutputType? output = null, Validation? validation = null) { OutputType outputType = GetOutput(output); var parameters = new Dictionary<string, object>(); parameters.Add(Params.userId, userId); parameters.Add(Params.pageNames, string.Join(Helper.DataSeparator, pageNames)); RestResponse response = MakePostRequest(SubAccountAction.addPagesToSubAccount, parameters, output: outputType, validation: validation); Helper.CheckStatus(response, outputType); }
public void IsTimespan_GivenInvalidField_ReturnError(string timespan) { var person = new Person() { Hour = timespan }; var errors = new Validation<Person>(person) .IsTimespan(x => x.Hour) .ToList(); Assert.Equal(1, errors.Count); Assert.Equal("Hour", errors[0].Property); }
public void IsPis_GivenInvalidExpression_ThrowsException() { var person = new Person(); Assert.Throws<ArgumentException>("expression", () => { var erros = new Validation<Person>(person) .IsPis(x => "") .ToList(); }); }
public void IsPis_GivenInvalidField_ReturnError(string pis) { var person = new Person() { Pis = pis }; var errors = new Validation<Person>(person) .IsPis(x => x.Pis) .ToList(); Assert.Equal(1, errors.Count); Assert.Equal("Pis", errors[0].Property); }
public void IsCnpj_GivenInvalidField_ReturnError(string cnpj) { var person = new Person() { Cnpj = cnpj }; var errors = new Validation<Person>(person) .IsCnpj(x => x.Cnpj) .ToList(); Assert.Equal(1, errors.Count); Assert.Equal("Cnpj", errors[0].Property); }