-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Splitting the validation result models from the main package
- Loading branch information
Showing
11 changed files
with
125 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/YuckQi.Domain.Validation/Extensions/AbstractValidatorExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Linq; | ||
using FluentValidation; | ||
|
||
namespace YuckQi.Domain.Validation.Extensions | ||
{ | ||
public static class AbstractValidatorExtensions | ||
{ | ||
private const string AbstractValidatorFailedMessageId = "YQDV.01"; | ||
|
||
public static Result<T> GetResult<T>(this AbstractValidator<T> validator, T item) | ||
{ | ||
var result = validator.Validate(item); | ||
if (result == null) | ||
throw new ArgumentNullException(nameof(result)); | ||
|
||
if (result.IsValid) | ||
return new Result<T>(item); | ||
|
||
return new Result<T>(default, result.Errors.Select(t => new ResultDetail(ResultCode.InvalidRequestDetail, new ResultMessage(AbstractValidatorFailedMessageId, t.ErrorMessage), t.PropertyName)).ToList()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace YuckQi.Domain.Validation | ||
{ | ||
public class ResultDetail | ||
{ | ||
#region Properties | ||
|
||
public ResultCode Code { get; } | ||
public ResultMessage Message { get; } | ||
public string Property { get; } | ||
public ResultType Type { get; } | ||
|
||
#endregion | ||
|
||
|
||
#region Constructors | ||
|
||
public ResultDetail(ResultCode code, ResultMessage message, string property = null, ResultType type = ResultType.Error) | ||
{ | ||
Code = code; | ||
Message = message; | ||
Property = property; | ||
Type = type; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace YuckQi.Domain.Validation | ||
{ | ||
public readonly struct ResultMessage | ||
{ | ||
#region Properties | ||
|
||
public string Id { get; } | ||
public string Text { get; } | ||
|
||
#endregion | ||
|
||
|
||
#region Constructors | ||
|
||
public ResultMessage(string id, string text = null) | ||
{ | ||
Id = id; | ||
Text = text; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
....Domain/Application/Results/ResultType.cs → src/YuckQi.Domain.Validation/ResultType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace YuckQi.Domain.Application.Results | ||
namespace YuckQi.Domain.Validation | ||
{ | ||
public enum ResultType | ||
{ | ||
|
22 changes: 22 additions & 0 deletions
22
src/YuckQi.Domain.Validation/YuckQi.Domain.Validation.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Authors>Kevin J Lambert</Authors> | ||
<Version>0.2.0</Version> | ||
<PackageLicenseFile>LICENSE</PackageLicenseFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\LICENSE"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentValidation" Version="9.3.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters