Skip to content

Commit

Permalink
Added DomainValidationException
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuck committed Dec 11, 2020
1 parent a392ee5 commit 748df21
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
48 changes: 48 additions & 0 deletions src/YuckQi.Domain.Validation/DomainValidationException.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>0.2.0</Version>
<Version>0.2.1</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/YuckQi.Domain/YuckQi.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Company />
<Version>0.2.0</Version>
<Version>0.2.1</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>

Expand Down

0 comments on commit 748df21

Please sign in to comment.