public async Task TestQueryNull() { var query = new QueryA(); var self = new QueryAndValidator(query, null); var result = await QueryValidationSteps.Validate(self); result.ShouldBe(query); }
public async Task TestQueryValid() { var query = new QueryA(); var self = new QueryAndValidator(query, _validValidator); var result = await QueryValidationSteps.Validate(self); await _validValidator.Received().ValidateAsync(query); result.ShouldBe(query); }
public static async Task<IQuery> Validate(QueryAndValidator self) { if (self.Validator == null) { return self.Query; } var result = await self.Validator.ValidateAsync(self.Query); if (result.IsValid) { return self.Query; } var errors = result.Errors .Select(x => new Violation(x.PropertyName.ToCamelCase(), x.ErrorMessage)) .ToList(); throw new Qvc.Validation.ValidationException(errors); }
public void TestQueryInvalid() { var query = new QueryA(); var self = new QueryAndValidator(query, _invalidValidator); var result = Should.Throw<Qvc.Validation.ValidationException>(async () => await QueryValidationSteps.Validate(self)); _invalidValidator.Received().ValidateAsync(query); result.Violations.Single().FieldName.ShouldBe("fieldCamelCase"); result.Violations.Single().Message.ShouldBe("error"); }