Skip to content

Commit

Permalink
Added 'Error' property with joined error messages (#82)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Klaus <[email protected]>
  • Loading branch information
AKlaus and Alex Klaus authored Dec 23, 2024
1 parent c086c70 commit cac903d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ It's built around `IDomainResult` interface that has 3 properties:

```csharp
IReadOnlyCollection<string> Errors { get; } // Collection of error messages if any
string Error { get; } // Error messages (if any) joined into a line for simplicity
bool IsSuccess { get; } // Flag, whether the current status is successful or not
DomainOperationStatus Status { get; } // Current status of the domain operation: Success, Failed, NotFound, Unauthorized, etc.
```
Expand Down
7 changes: 7 additions & 0 deletions src/Common/IDomainResultBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;

namespace DomainResults.Common
{
Expand All @@ -11,6 +12,12 @@ public interface IDomainResultBase
/// Collection of error messages if any
/// </summary>
IReadOnlyCollection<string> Errors { get; }

/// <summary>
/// Error messages joined into a single line ('.'-separated messages)
/// </summary>
string Error => !Errors.Any() ? string.Empty : string.Join(". ", Errors);

/// <summary>
/// Flag, whether the current status is successful or not
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion tests/DomainResults.Tests/Common/IDomainResultTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class IDomainResult_Tests

[Theory]
[MemberData(nameof(TestCasesWithNoValue))]
public void IDomainResult_Response_Test(Func<IDomainResult> method, DomainOperationStatus expectedStatus, IEnumerable<string> expectedErrMessages)
public void IDomainResult_Response_Test(Func<IDomainResult> method, DomainOperationStatus expectedStatus, string[] expectedErrMessages)
{
var domainResult = method();

Expand All @@ -26,6 +26,7 @@ public void IDomainResult_Response_Test(Func<IDomainResult> method, DomainOperat

Assert.Equal(expectedStatus, domainResult.Status);
Assert.Equal(expectedErrMessages, domainResult.Errors);
Assert.Equal(string.Join(". ", expectedErrMessages), domainResult.Error);
}

public static IEnumerable<object[]> TestCasesWithNoValue
Expand Down

0 comments on commit cac903d

Please sign in to comment.