Skip to content

Commit 77e9c38

Browse files
Merge pull request #3 from OneBitSoftware/radi/append-errors-confusion-fix
AppendErrors confusion fix
2 parents d7ee5df + 2d15b0d commit 77e9c38

3 files changed

Lines changed: 49 additions & 4 deletions

File tree

src/OneBitSoftware.Utilities.OperationResult/OneBitSoftware.Utilities.OperationResult.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
3333
<PackageReadmeFile>README.md</PackageReadmeFile>
3434
<PackageTags>OneBitSoftware; OperationResult;</PackageTags>
35-
<Version>1.4.1</Version>
35+
<Version>1.4.2</Version>
3636
</PropertyGroup>
3737

3838
</Project>

src/OneBitSoftware.Utilities.OperationResult/OperationResult.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,12 @@ public OperationResult(TResult resultObject) : base()
305305
}
306306

307307
/// <summary>
308-
/// Appends error messages from <paramref name="otherOperationResult"/> to <paramref name="originalOperationResult"/>.
308+
/// Appends error messages from <paramref name="otherOperationResult"/> to the current instance.
309309
/// </summary>
310-
/// <param name="originalOperationResult">The <see cref="OperationResult"/> to append to.</param>
311310
/// <param name="otherOperationResult">The <see cref="OperationResult"/> to append from.</param>
312-
/// <typeparam name="TOriginal">A type that inherits from <see cref="OperationResult"/>.</typeparam>
313311
/// <typeparam name="TOther">A type that inherits from <see cref="OperationResult"/>.</typeparam>
314312
/// <returns>The original <see cref="OperationResult"/> with the appended messages from <paramref name="otherOperationResult"/>.</returns>
313+
[Obsolete("Please use AppendErrors instead. This method will be removed to avoid confusion.")]
315314
public OperationResult<TResult> AppendErrorMessages<TOther>(TOther otherOperationResult)
316315
where TOther : OperationResult
317316
{
@@ -320,6 +319,18 @@ public OperationResult<TResult> AppendErrorMessages<TOther>(TOther otherOperatio
320319
return this;
321320
}
322321

322+
/// <summary>
323+
/// Appends error from <paramref name="otherOperationResult"/> to the current instance.
324+
/// </summary>
325+
/// <param name="otherOperationResult">The <see cref="OperationResult"/> to append from.</param>
326+
/// <returns>The original <see cref="OperationResult"/> with the appended messages from <paramref name="otherOperationResult"/>.</returns>
327+
public new OperationResult<TResult> AppendErrors(OperationResult otherOperationResult)
328+
{
329+
base.AppendErrors(otherOperationResult);
330+
331+
return this;
332+
}
333+
323334
/// <summary>
324335
/// Appends an exception to the error message collection and logs the full exception as an Error <see cref="LogEventLevel"/> level. A call to this method will set the Success property to false.
325336
/// </summary>

tests/OneBitSoftware.Utilities.OperationResultTests/OperationResultAppendErrorsTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,40 @@ public void AppendErrorsT_ShouldListAllErrors()
6161
var operationResultBase = new OperationResult<object>();
6262
operationResultBase.AppendError(message2, errorCode2, LogLevel.Debug, detail2);
6363

64+
// Act - AppendErrorMessages is to be removed
65+
operationResultBase.AppendErrorMessages(operationResultTarget);
66+
67+
// Assert
68+
Assert.False(operationResultBase.Success);
69+
Assert.False(operationResultTarget.Success);
70+
Assert.True(operationResultBase.Fail);
71+
Assert.True(operationResultTarget.Fail);
72+
73+
Assert.Equal(3, operationResultBase.Errors.Count);
74+
Assert.Equal(2, operationResultTarget.Errors.Count);
75+
76+
Assert.NotNull(operationResultBase.Errors.Single(r => r.Code.Equals(errorCode2)));
77+
Assert.NotNull(operationResultBase.Errors.Single(r => r.Message.Equals(message2)));
78+
Assert.NotNull(operationResultBase.Errors.Single(r => r.Details is not null && r.Details.Equals(detail2)));
79+
}
80+
81+
[Fact]
82+
public void AppendErrorsStringInt_ShouldListAllErrors()
83+
{
84+
// Arrange
85+
var errorCode1 = 666;
86+
var message1 = "Error";
87+
var detail1 = "Detail";
88+
var operationResultTarget = new OperationResult<int>();
89+
operationResultTarget.AppendError(message1, errorCode1, LogLevel.Debug, detail1);
90+
operationResultTarget.AppendException(new Exception(message1));
91+
92+
var errorCode2 = 669;
93+
var message2 = "Error2";
94+
var detail2 = "Detail2";
95+
var operationResultBase = new OperationResult<string>();
96+
operationResultBase.AppendError(message2, errorCode2, LogLevel.Debug, detail2);
97+
6498
// Act
6599
operationResultBase.AppendErrors(operationResultTarget);
66100

0 commit comments

Comments
 (0)