| | 1 | | using Fluorite.Strainer.Models.Configuration; |
| | 2 | |
|
| | 3 | | namespace Fluorite.Strainer.Services.Validation; |
| | 4 | |
|
| | 5 | | /// <inheritdoc/> |
| | 6 | | public class StrainerConfigurationValidator : IStrainerConfigurationValidator |
| | 7 | | { |
| | 8 | | private readonly IFilterOperatorValidator _filterOperatorValidator; |
| | 9 | | private readonly ISortExpressionValidator _sortExpressionValidator; |
| | 10 | |
|
| 13 | 11 | | public StrainerConfigurationValidator( |
| 13 | 12 | | IFilterOperatorValidator filterOperatorValidator, |
| 13 | 13 | | ISortExpressionValidator sortExpressionValidator) |
| | 14 | | { |
| 13 | 15 | | _filterOperatorValidator = Guard.Against.Null(filterOperatorValidator); |
| 13 | 16 | | _sortExpressionValidator = Guard.Against.Null(sortExpressionValidator); |
| 13 | 17 | | } |
| | 18 | |
|
| | 19 | | /// <inheritdoc/> |
| | 20 | | /// <exception cref="ArgumentNullException"> |
| | 21 | | /// <paramref name="strainerConfiguration"/> is <see langword="null"/>. |
| | 22 | | /// </exception> |
| | 23 | | /// <exception cref="InvalidOperationException"> |
| | 24 | | /// <paramref name="strainerConfiguration"/> is not valid. |
| | 25 | | /// </exception> |
| | 26 | | public void Validate(IStrainerConfiguration strainerConfiguration) |
| | 27 | | { |
| 11 | 28 | | Guard.Against.Null(strainerConfiguration); |
| | 29 | |
|
| | 30 | | try |
| | 31 | | { |
| 10 | 32 | | _filterOperatorValidator.Validate(strainerConfiguration.FilterOperators.Values, strainerConfiguration.Exclud |
| 10 | 33 | | _sortExpressionValidator.Validate(strainerConfiguration.PropertyMetadata); |
| 9 | 34 | | } |
| 1 | 35 | | catch (Exception exception) |
| | 36 | | { |
| 1 | 37 | | throw new InvalidOperationException( |
| 1 | 38 | | "Invalid Strainer configuration. See inner exception for details.", |
| 1 | 39 | | exception); |
| | 40 | | } |
| 9 | 41 | | } |
| | 42 | | } |