From dd5790d5e14500160c0a1fe76022e0b32621b4d2 Mon Sep 17 00:00:00 2001 From: Kevin J Lambert Date: Tue, 11 Jan 2022 08:35:18 -0500 Subject: [PATCH] Removed the hard-coded validation message id --- .../Exceptions/DomainValidationException.cs | 2 +- .../Extensions/AbstractValidatorExtensions.cs | 14 +++++--------- src/YuckQi.Domain.Validation/Result.cs | 2 +- src/YuckQi.Domain.Validation/ResultCode.cs | 2 +- src/YuckQi.Domain.Validation/ResultDetail.cs | 2 +- src/YuckQi.Domain.Validation/ResultMessage.cs | 2 +- src/YuckQi.Domain.Validation/ResultType.cs | 2 +- .../YuckQi.Domain.Validation.csproj | 2 +- 8 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/YuckQi.Domain.Validation/Exceptions/DomainValidationException.cs b/src/YuckQi.Domain.Validation/Exceptions/DomainValidationException.cs index 7bd01cd..baf4fd6 100644 --- a/src/YuckQi.Domain.Validation/Exceptions/DomainValidationException.cs +++ b/src/YuckQi.Domain.Validation/Exceptions/DomainValidationException.cs @@ -45,4 +45,4 @@ private static String GetErrorMessage(Result result) #endregion } -} \ No newline at end of file +} diff --git a/src/YuckQi.Domain.Validation/Extensions/AbstractValidatorExtensions.cs b/src/YuckQi.Domain.Validation/Extensions/AbstractValidatorExtensions.cs index e190e23..8c4bafa 100644 --- a/src/YuckQi.Domain.Validation/Extensions/AbstractValidatorExtensions.cs +++ b/src/YuckQi.Domain.Validation/Extensions/AbstractValidatorExtensions.cs @@ -8,9 +8,7 @@ namespace YuckQi.Domain.Validation.Extensions { public static class AbstractValidatorExtensions { - private const String AbstractValidatorFailedMessageId = "YQDV.01"; - - public static Result GetResult(this AbstractValidator validator, T item) + public static Result GetResult(this AbstractValidator validator, T item, String failedValidationMessageId) { var result = validator.Validate(item); if (result == null) @@ -19,14 +17,12 @@ public static Result GetResult(this AbstractValidator validator, T item if (result.IsValid) return new Result(item); - return new Result(default, GetResultDetail(result)); + return new Result(default, GetResultDetail(result, failedValidationMessageId)); } - private static IReadOnlyCollection GetResultDetail(ValidationResult result) + private static IReadOnlyCollection GetResultDetail(ValidationResult result, String failedValidationMessageId) { - return result?.Errors - .Select(t => new ResultDetail(ResultCode.InvalidRequestDetail, new ResultMessage(AbstractValidatorFailedMessageId, t.ErrorMessage), t.PropertyName)) - .ToList(); + return result?.Errors.Select(t => new ResultDetail(ResultCode.InvalidRequestDetail, new ResultMessage(failedValidationMessageId, t.ErrorMessage), t.PropertyName)).ToList(); } } -} \ No newline at end of file +} diff --git a/src/YuckQi.Domain.Validation/Result.cs b/src/YuckQi.Domain.Validation/Result.cs index d40192a..7183262 100644 --- a/src/YuckQi.Domain.Validation/Result.cs +++ b/src/YuckQi.Domain.Validation/Result.cs @@ -45,4 +45,4 @@ public Result(T payload, IReadOnlyCollection detail = null) : base #endregion } -} \ No newline at end of file +} diff --git a/src/YuckQi.Domain.Validation/ResultCode.cs b/src/YuckQi.Domain.Validation/ResultCode.cs index c3c337e..e697419 100644 --- a/src/YuckQi.Domain.Validation/ResultCode.cs +++ b/src/YuckQi.Domain.Validation/ResultCode.cs @@ -45,4 +45,4 @@ public ResultCode(String code) #endregion } -} \ No newline at end of file +} diff --git a/src/YuckQi.Domain.Validation/ResultDetail.cs b/src/YuckQi.Domain.Validation/ResultDetail.cs index bac565d..3c48f44 100644 --- a/src/YuckQi.Domain.Validation/ResultDetail.cs +++ b/src/YuckQi.Domain.Validation/ResultDetail.cs @@ -35,4 +35,4 @@ public ResultDetail(ResultCode code, ResultMessage message, String property = nu #endregion } -} \ No newline at end of file +} diff --git a/src/YuckQi.Domain.Validation/ResultMessage.cs b/src/YuckQi.Domain.Validation/ResultMessage.cs index a33c797..4bde9b5 100644 --- a/src/YuckQi.Domain.Validation/ResultMessage.cs +++ b/src/YuckQi.Domain.Validation/ResultMessage.cs @@ -22,4 +22,4 @@ public ResultMessage(String id, String text = null) #endregion } -} \ No newline at end of file +} diff --git a/src/YuckQi.Domain.Validation/ResultType.cs b/src/YuckQi.Domain.Validation/ResultType.cs index fcd3f59..f2519a0 100644 --- a/src/YuckQi.Domain.Validation/ResultType.cs +++ b/src/YuckQi.Domain.Validation/ResultType.cs @@ -6,4 +6,4 @@ public enum ResultType Warning = 1, Error = 2 } -} \ No newline at end of file +} diff --git a/src/YuckQi.Domain.Validation/YuckQi.Domain.Validation.csproj b/src/YuckQi.Domain.Validation/YuckQi.Domain.Validation.csproj index 177529d..8cd60d0 100644 --- a/src/YuckQi.Domain.Validation/YuckQi.Domain.Validation.csproj +++ b/src/YuckQi.Domain.Validation/YuckQi.Domain.Validation.csproj @@ -4,7 +4,7 @@ netstandard2.0 true Kevin J Lambert - 0.5.0 + 1.0.0 LICENSE A .NET library providing domain validation fundamentals.