diff --git a/src/YuckQi.Domain.Validation/DomainValidationException.cs b/src/YuckQi.Domain.Validation/DomainValidationException.cs new file mode 100644 index 0000000..172cbea --- /dev/null +++ b/src/YuckQi.Domain.Validation/DomainValidationException.cs @@ -0,0 +1,48 @@ +using System; +using System.Linq; + +namespace YuckQi.Domain.Validation +{ + public class DomainValidationException : ApplicationException + { + #region Constants + + private const string DefaultErrorMessage = "Something went wrong."; + + #endregion + + + #region Properties + + public Result Result { get; } + + #endregion + + + #region Constructors + + public DomainValidationException(Result result) : base(GetErrorMessage(result)) + { + Result = result; + } + + #endregion + + + #region Supporting Methods + + private static string GetErrorMessage(Result result) + { + if (result == null) + return DefaultErrorMessage; + + var count = result.Detail.Count(t => t.Type == ResultType.Error); + var noun = count == 1 ? "error" : "errors"; + var message = $"Domain model has {count} {noun} after validation."; + + return message; + } + + #endregion + } +} \ 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 06c118d..572c35c 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.2.0 + 0.2.1 LICENSE diff --git a/src/YuckQi.Domain/YuckQi.Domain.csproj b/src/YuckQi.Domain/YuckQi.Domain.csproj index 12e68b1..6bc7aee 100644 --- a/src/YuckQi.Domain/YuckQi.Domain.csproj +++ b/src/YuckQi.Domain/YuckQi.Domain.csproj @@ -5,7 +5,7 @@ true Kevin J Lambert - 0.2.0 + 0.2.1 LICENSE