@@ -177,4 +177,78 @@ public void AppendErrors_ShouldLogWhenCreatedWithNoLogger()
177177 // Assert
178178 Assert . Equal ( 1 , testLogger . LogMessages . Count ) ;
179179 }
180+
181+ [ Fact ]
182+ public void AppendErrors_NonGenericSource_To_GenericTarget_Retains_Generic_Type_And_MergesErrors ( )
183+ {
184+ // Arrange
185+ var source = new OperationResult ( ) ;
186+ source . AppendError ( "E1" , 101 , LogLevel . Warning , "D1" ) ;
187+
188+ var target = new OperationResult < string > ( ) ;
189+ target . AppendError ( "E0" , 100 , LogLevel . Information , "D0" ) ;
190+
191+ // Act
192+ var returned = target . AppendErrors ( source ) ;
193+
194+ // Assert
195+ Assert . Same ( target , returned ) ;
196+ Assert . True ( target . Fail ) ;
197+ Assert . Equal ( 2 , target . Errors . Count ) ;
198+ Assert . NotNull ( target . Errors . Single ( e => e is { Code : 100 , Message : "E0" } ) ) ;
199+ Assert . NotNull ( target . Errors . Single ( e => e is { Code : 101 , Message : "E1" } ) ) ;
200+ }
201+
202+ [ Fact ]
203+ public void AppendErrors_GenericSource_To_GenericTarget_Retains_Generic_Type_And_MergesErrors ( )
204+ {
205+ // Arrange
206+ var source = new OperationResult < double > ( ) ;
207+ source . AppendError ( "E1" , 101 , LogLevel . Warning , "D1" ) ;
208+
209+ var target = new OperationResult < string > ( ) ;
210+ target . AppendError ( "E0" , 100 , LogLevel . Information , "D0" ) ;
211+
212+ // Act
213+ var returned = target . AppendErrors ( source ) ;
214+
215+ // Assert
216+ Assert . Same ( target , returned ) ;
217+ Assert . True ( target . Fail ) ;
218+ Assert . Equal ( 2 , target . Errors . Count ) ;
219+ Assert . NotNull ( target . Errors . Single ( e => e is { Code : 100 , Message : "E0" } ) ) ;
220+ Assert . NotNull ( target . Errors . Single ( e => e is { Code : 101 , Message : "E1" } ) ) ;
221+ }
222+
223+ [ Fact ]
224+ public void AppendErrors_WithNullSource_On_NonGenericTarget_Returns_Same_Instance_And_NoChange ( )
225+ {
226+ // Arrange
227+ var target = new OperationResult ( ) ;
228+ target . AppendError ( "E0" , 100 , LogLevel . Information , "D0" ) ;
229+ var beforeCount = target . Errors . Count ;
230+
231+ // Act
232+ var returned = target . AppendErrors ( null ) ;
233+
234+ // Assert
235+ Assert . Same ( target , returned ) ;
236+ Assert . Equal ( beforeCount , target . Errors . Count ) ;
237+ }
238+
239+ [ Fact ]
240+ public void AppendErrors_WithNullSource_On_GenericTarget_Returns_Same_Instance_And_NoChange ( )
241+ {
242+ // Arrange
243+ var target = new OperationResult < object > ( ) ;
244+ target . AppendError ( "E0" , 100 , LogLevel . Information , "D0" ) ;
245+ var beforeCount = target . Errors . Count ;
246+
247+ // Act
248+ var returned = target . AppendErrors ( ( OperationResult ) null ) ;
249+
250+ // Assert
251+ Assert . Same ( target , returned ) ;
252+ Assert . Equal ( beforeCount , target . Errors . Count ) ;
253+ }
180254}
0 commit comments