Skip to content

Commit

Permalink
Fixed a defect in the Result.IsValid logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuck committed Jan 21, 2022
1 parent 492af94 commit b930dbb
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 8 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.1.1</Version>
<Version>1.2.0</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Description>A .NET library for bootstrapping a domain services project.</Description>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/YuckQi.Domain.Validation/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Result

public IReadOnlyCollection<ResultDetail> Detail { get; }

public Boolean IsValid => Detail != null && Detail.Any(t => t.Type == ResultType.Error);
public Boolean IsValid => Detail.All(t => t.Type != ResultType.Error);

#endregion

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.1.1</Version>
<Version>1.2.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.1.1</Version>
<Version>1.2.0</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Description>A .NET library for bootstrapping a domain model project.</Description>
</PropertyGroup>
Expand Down
8 changes: 4 additions & 4 deletions test/YuckQi.Domain.Validation.UnitTests/ResultCodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public void Setup() { }
[Test]
public void ResultCode_WithSameCode_HasSameHashCode()
{
var a = new ResultCode("test");
var hashCodeA = a.GetHashCode();
var b = new ResultCode("test");
var hashCodeB = b.GetHashCode();
var resultCodeA = new ResultCode("test");
var hashCodeA = resultCodeA.GetHashCode();
var resultCodeB = new ResultCode("test");
var hashCodeB = resultCodeB.GetHashCode();

Assert.AreEqual(hashCodeA, hashCodeB);
}
Expand Down
40 changes: 40 additions & 0 deletions test/YuckQi.Domain.Validation.UnitTests/ResultTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;

namespace YuckQi.Domain.Validation.UnitTests;

public class ResultTests
{
[SetUp]
public void Setup() { }

[Test]
public void Result_WithErrors_IsNotValid()
{
var detail = new List<ResultDetail> { new(new ResultCode("test"), new ResultMessage("id")) };
var result = new Result<String>("test", detail);
var isValid = result.IsValid;

Assert.IsFalse(isValid);
}

[Test]
public void Result_WithNoDetail_IsValid()
{
var result = new Result<String>("test");
var isValid = result.IsValid;

Assert.IsTrue(isValid);
}

[Test]
public void Result_WithOnlyWarnings_IsValid()
{
var detail = new List<ResultDetail> { new(new ResultCode("test"), new ResultMessage("id"), type: ResultType.Warning) };
var result = new Result<String>("test", detail);
var isValid = result.IsValid;

Assert.IsTrue(isValid);
}
}

0 comments on commit b930dbb

Please sign in to comment.