From 64cab1ea3de0abc28ebf4518904597915d13f3cb Mon Sep 17 00:00:00 2001 From: Kevin J Lambert Date: Sat, 22 Jan 2022 11:26:55 -0500 Subject: [PATCH] Updated how result codes are interrogated --- .../YuckQi.Domain.Services.csproj | 2 +- src/YuckQi.Domain.Validation/Result.cs | 8 ++++---- .../YuckQi.Domain.Validation.csproj | 2 +- src/YuckQi.Domain/YuckQi.Domain.csproj | 2 +- test/YuckQi.Domain.Validation.UnitTests/ResultTests.cs | 10 ++++++++++ 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/YuckQi.Domain.Services/YuckQi.Domain.Services.csproj b/src/YuckQi.Domain.Services/YuckQi.Domain.Services.csproj index dfced00..f3734d7 100644 --- a/src/YuckQi.Domain.Services/YuckQi.Domain.Services.csproj +++ b/src/YuckQi.Domain.Services/YuckQi.Domain.Services.csproj @@ -4,7 +4,7 @@ netstandard2.0 true Kevin J Lambert - 1.2.0 + 1.3.0 LICENSE A .NET library for bootstrapping a domain services project. diff --git a/src/YuckQi.Domain.Validation/Result.cs b/src/YuckQi.Domain.Validation/Result.cs index 1954b06..796ce3b 100644 --- a/src/YuckQi.Domain.Validation/Result.cs +++ b/src/YuckQi.Domain.Validation/Result.cs @@ -36,7 +36,9 @@ public class Result : Result #region Constructors - public Result(ResultDetail detail) : base(new List { detail }) { } + public Result(ResultDetail detail) : this(new List { detail }) { } + + public Result(IReadOnlyCollection detail) : base(detail) { } public Result(T payload, IReadOnlyCollection detail = null) : base(detail) { @@ -50,9 +52,7 @@ public Result(T payload, IReadOnlyCollection detail = null) : base public static Result ConstraintViolation(TKey key, String message = null) where TKey : struct => new Result(ResultDetail.ConstraintViolation(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 NotFound(TKey key, String message = null) where TKey : struct => new Result(ResultDetail.NotFound(key, message)); diff --git a/src/YuckQi.Domain.Validation/YuckQi.Domain.Validation.csproj b/src/YuckQi.Domain.Validation/YuckQi.Domain.Validation.csproj index 7fc8e5f..f56e229 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 - 1.2.0 + 1.3.0 LICENSE A .NET library providing domain validation fundamentals. diff --git a/src/YuckQi.Domain/YuckQi.Domain.csproj b/src/YuckQi.Domain/YuckQi.Domain.csproj index 6976b4b..7d9c6a6 100644 --- a/src/YuckQi.Domain/YuckQi.Domain.csproj +++ b/src/YuckQi.Domain/YuckQi.Domain.csproj @@ -4,7 +4,7 @@ netstandard2.0 true Kevin J Lambert - 1.2.0 + 1.3.0 LICENSE A .NET library for bootstrapping a domain model project. diff --git a/test/YuckQi.Domain.Validation.UnitTests/ResultTests.cs b/test/YuckQi.Domain.Validation.UnitTests/ResultTests.cs index be9a8d2..527196c 100644 --- a/test/YuckQi.Domain.Validation.UnitTests/ResultTests.cs +++ b/test/YuckQi.Domain.Validation.UnitTests/ResultTests.cs @@ -9,6 +9,16 @@ public class ResultTests [SetUp] public void Setup() { } + [Test] + public void Result_NotFound_HasNotFoundResultCode() + { + var detail = new List { ResultDetail.NotFound(1), ResultDetail.ConstraintViolation(1) }.AsReadOnly(); + var result = new Result(detail); + var hasNotFoundResultCode = result.HasResultCode(ResultCode.NotFound); + + Assert.IsTrue(hasNotFoundResultCode); + } + [Test] public void Result_WithErrors_IsNotValid() {