//Call the Web service and validate the result. if the result is not valid prepare the validation message. public async Task <GroupedPetResult> GetAsync(string petType) { var result = new GroupedPetResult(); var persons = await GetPersons(); if (persons != null) { var validator = new PersonListValidator(); var validationResult = validator.Validate(persons); result.IsSuccess = validationResult.IsValid; if (validationResult.IsValid) { result.Message = ""; result.GroupedPetVms = GroupPets(persons, petType); } else { result.Message = string.Join("\n", validationResult.Errors.Select(x => $"{x.PropertyName}: Error: {x.ErrorMessage}")); Logger.Error($"Validation Error:-{result.Message}"); result.IsSuccess = false; } } return(result); }
public void LengthyPetType() { var data = GetNormalTestPersons().ToList(); data.FirstOrDefault().Pets.FirstOrDefault().Type = "ChrocodlieDinasourEagle"; var validator = new PersonListValidator(); var validationResult = validator.Validate(data); // Assert Assert.IsFalse(validationResult.IsValid); }
public void LengthyPetName() { var data = GetNormalTestPersons().ToList(); data.FirstOrDefault().Pets.FirstOrDefault().Name = "Abcdefghijlmnopq123456"; var validator = new PersonListValidator(); var validationResult = validator.Validate(data); // Assert Assert.IsFalse(validationResult.IsValid); }
public void NullEmptyGender() { var data = GetNormalTestPersons().ToList(); data.FirstOrDefault().Gender = string.Empty; var validator = new PersonListValidator(); var validationResult = validator.Validate(data); // Assert Assert.IsFalse(validationResult.IsValid); }
public void NonAlphaNumericName() { var data = GetNormalTestPersons().ToList(); data.FirstOrDefault().Name = "Ali1"; var validator = new PersonListValidator(); var validationResult = validator.Validate(data); // Assert Assert.IsFalse(validationResult.IsValid); }
public void LengthyName() { var data = GetNormalTestPersons().ToList(); data.FirstOrDefault().Name = "Alighghfghfghfghgfhfghfdhfhfdhfhfghfhdfhfgh"; var validator = new PersonListValidator(); var validationResult = validator.Validate(data); // Assert Assert.IsFalse(validationResult.IsValid); }