Skip to content

Commit

Permalink
Updated how result codes are interrogated
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuck committed Jan 22, 2022
1 parent b930dbb commit 64cab1e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/YuckQi.Domain.Services/YuckQi.Domain.Services.csproj
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>1.2.0</Version>
<Version>1.3.0</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Description>A .NET library for bootstrapping a domain services project.</Description>
</PropertyGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/YuckQi.Domain.Validation/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public class Result<T> : Result

#region Constructors

public Result(ResultDetail detail) : base(new List<ResultDetail> { detail }) { }
public Result(ResultDetail detail) : this(new List<ResultDetail> { detail }) { }

public Result(IReadOnlyCollection<ResultDetail> detail) : base(detail) { }

public Result(T payload, IReadOnlyCollection<ResultDetail> detail = null) : base(detail)
{
Expand All @@ -50,9 +52,7 @@ public Result(T payload, IReadOnlyCollection<ResultDetail> detail = null) : base

public static Result<T> ConstraintViolation<TKey>(TKey key, String message = null) where TKey : struct => new Result<T>(ResultDetail.ConstraintViolation<T, TKey>(key, message));

public Boolean IsConstraintViolation => Detail.Any(t => String.Equals(t.Code, ResultCode.ConstraintViolation));

public Boolean IsNotFound => Detail.Any(t => String.Equals(t.Code, ResultCode.NotFound));
public Boolean HasResultCode(ResultCode resultCode) => Detail.Any(t => t.Code == resultCode);

public static Result<T> NotFound<TKey>(TKey key, String message = null) where TKey : struct => new Result<T>(ResultDetail.NotFound<T, TKey>(key, message));

Expand Down
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>1.2.0</Version>
<Version>1.3.0</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Description>A .NET library providing domain validation fundamentals.</Description>
</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 @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Kevin J Lambert</Authors>
<Version>1.2.0</Version>
<Version>1.3.0</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Description>A .NET library for bootstrapping a domain model project.</Description>
</PropertyGroup>
Expand Down
10 changes: 10 additions & 0 deletions test/YuckQi.Domain.Validation.UnitTests/ResultTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ public class ResultTests
[SetUp]
public void Setup() { }

[Test]
public void Result_NotFound_HasNotFoundResultCode()
{
var detail = new List<ResultDetail> { ResultDetail.NotFound<String, Int32>(1), ResultDetail.ConstraintViolation<String, Int32>(1) }.AsReadOnly();
var result = new Result<String>(detail);
var hasNotFoundResultCode = result.HasResultCode(ResultCode.NotFound);

Assert.IsTrue(hasNotFoundResultCode);
}

[Test]
public void Result_WithErrors_IsNotValid()
{
Expand Down

0 comments on commit 64cab1e

Please sign in to comment.