public static void A_ChangeOfFieldWithValueTypeForComplexReferenceTypePassedByReferenceIsTakeEffectInCaller() { var sourceTrainee = new TraineeReferenceType("Kate", 2); var expectedTrainee = new TraineeReferenceType("Kate", 2); Trace.TraceInformation( $"Create a variable of a complex reference type. Type: TraineeReferenceType, value = '{sourceTrainee}'."); Trace.TraceInformation("Pass it to the method, which increment property 'Assessment' (value type - int)."); var changedTrainer = TypesChanger.IncrementAssessmentOfTrainee(sourceTrainee); Trace.TraceInformation("Expected, that the value in the caller is incremented in the same way " + "as the value in the method, which was called." + "It occurs because an object of a reference type is passed by reference and " + "the called method did operate on the same object, which is declared in the caller."); Trace.TraceInformation( $"Compare the source assessment with expected (Assessment of a source trainee should be greater): source = '{sourceTrainee.Assessment}'; expected = '{expectedTrainee.Assessment}'."); sourceTrainee.Assessment .Should() .BeGreaterThan(expectedTrainee.Assessment); Trace.TraceInformation( "Compare changed assessment with the original (The changed value should be the same): " + $"changed = '{changedTrainer.Assessment}'; original = '{sourceTrainee.Assessment}'."); changedTrainer.Assessment .Should() .Be(sourceTrainee.Assessment); }
public static TraineeReferenceType IncrementAssessmentOfTrainee(TraineeReferenceType trainee) { trainee.Assessment++; return(trainee); }