private void ApplyOutAndRefParametersValues(IInterceptedFakeObjectCall fakeObjectCall) { if (this.OutAndRefParametersValues == null) { return; } var indexes = GetIndexesOfOutAndRefParameters(fakeObjectCall); if (this.OutAndRefParametersValues.Count != indexes.Count) { throw new InvalidOperationException(ExceptionMessages.NumberOfOutAndRefParametersDoesNotMatchCall); } foreach (var argument in indexes.Zip(this.OutAndRefParametersValues)) { if (this.DoEvaluateOutAndRefFuncs) { Func <object> getter = argument.Item2 as Func <object>; if (getter != null) { object value = getter(); fakeObjectCall.SetArgumentValue(argument.Item1, value); } } else { fakeObjectCall.SetArgumentValue(argument.Item1, argument.Item2); } } }
private static void ApplyOutputArguments(IInterceptedFakeObjectCall call, CallMetadata callToApply) { foreach (var outputArgument in GetIndicesAndValuesOfOutputParameters(call, callToApply.RecordedCall)) { call.SetArgumentValue(outputArgument.Item1, outputArgument.Item2); } }
private void ApplyOutAndRefParametersValueProducer(IInterceptedFakeObjectCall fakeObjectCall) { if (this.OutAndRefParametersValueProducer == null) { return; } var indexes = GetIndexesOfOutAndRefParameters(fakeObjectCall); ICollection <object> values; try { values = this.OutAndRefParametersValueProducer(fakeObjectCall); } catch (Exception ex) when(!(ex is FakeConfigurationException)) { throw new UserCallbackException(ExceptionMessages.UserCallbackThrewAnException("Out and ref parameter value producer"), ex); } if (values.Count != indexes.Count) { throw new InvalidOperationException(ExceptionMessages.NumberOfOutAndRefParametersDoesNotMatchCall); } foreach (var argument in indexes.Zip(values, (index, value) => new { Index = index, Value = value })) { fakeObjectCall.SetArgumentValue(argument.Index, argument.Value); } }
private static void ApplyOutputArguments(IInterceptedFakeObjectCall call, CallDataMetadata callToApply) { foreach (var outputArgument in call.Method.GetParameters() .Select((parameter, index) => new { Parameter = parameter, Index = index }) .Where(argument => argument.Parameter.ParameterType.IsByRef) .Select(argument => argument.Index).Zip(callToApply.RecordedCall.OutputArguments, (index, outputArgument) => new { Index = index, Value = outputArgument })) { call.SetArgumentValue(outputArgument.Index, outputArgument.Value); } }
private static void SetOutAndRefValues(IInterceptedFakeObjectCall fakeObjectCall, RecordedCall recordedCall) { int outOrRefIndex = 0; for (int parameterIndex = 0; parameterIndex < fakeObjectCall.Method.GetParameters().Length; parameterIndex++) { var parameter = fakeObjectCall.Method.GetParameters()[parameterIndex]; if (parameter.ParameterType.IsByRef) { fakeObjectCall.SetArgumentValue(parameterIndex, recordedCall.OutAndRefValues[outOrRefIndex++]); } } }
private static void ApplyRecordedCall(RecordedCall recordedCall, IInterceptedFakeObjectCall fakeObjectCall) { fakeObjectCall.SetReturnValue(recordedCall.ReturnValue); int outAndRefIndex = 0; int parameterIndex = 0; foreach (var parameter in fakeObjectCall.Method.GetParameters()) { if (parameter.ParameterType.IsByRef) { fakeObjectCall.SetArgumentValue(parameterIndex, recordedCall.OutAndRefValues[outAndRefIndex++]); } ++parameterIndex; } }
private void ApplyOutAndRefParametersValues(IInterceptedFakeObjectCall fakeObjectCall) { if (this.OutAndRefParametersValues == null) { return; } var indexes = GetIndexesOfOutAndRefParameters(fakeObjectCall); if (this.OutAndRefParametersValues.Count != indexes.Count) { throw new InvalidOperationException(ExceptionMessages.NumberOfOutAndRefParametersDoesNotMatchCall); } foreach (var argument in indexes.Zip(this.OutAndRefParametersValues)) { fakeObjectCall.SetArgumentValue(argument.Item1, argument.Item2); } }
private void ApplyOutAndRefParametersValueProducer(IInterceptedFakeObjectCall fakeObjectCall) { if (this.OutAndRefParametersValueProducer == null) { return; } var indexes = GetIndexesOfOutAndRefParameters(fakeObjectCall); var values = this.OutAndRefParametersValueProducer(fakeObjectCall); if (values.Count != indexes.Count) { throw new InvalidOperationException(ExceptionMessages.NumberOfOutAndRefParametersDoesNotMatchCall); } foreach (var argument in indexes.Zip(values, (index, value) => new { Index = index, Value = value })) { fakeObjectCall.SetArgumentValue(argument.Index, argument.Value); } }
private static void ApplyOutputArguments(IInterceptedFakeObjectCall call, CallDataMetadata callToApply) { foreach (var outputArgument in call.Method.GetParameters() .Select((parameter, index) => new { Parameter = parameter, Index = index }) .Where(argument => argument.Parameter.ParameterType.IsByRef) .Select(argument => argument.Index).Zip(callToApply.RecordedCall.OutputArguments, (index, outputArgument) => new { Index = index, Value = outputArgument })) { call.SetArgumentValue(outputArgument.Index, outputArgument.Value); } }
private void ApplyOutAndRefParametersValues(IInterceptedFakeObjectCall fakeObjectCall) { if (this.OutAndRefParametersValues == null) { return; } var indexes = GetIndexesOfOutAndRefParameters(fakeObjectCall); if (this.OutAndRefParametersValues.Count != indexes.Count) { throw new InvalidOperationException(ExceptionMessages.NumberOfOutAndRefParametersDoesNotMatchCall); } foreach (var argument in indexes.Zip(this.OutAndRefParametersValues)) { fakeObjectCall.SetArgumentValue(argument.Item1, argument.Item2); } }
private void ApplyOutAndRefParametersValueProducer(IInterceptedFakeObjectCall fakeObjectCall) { if (this.OutAndRefParametersValueProducer == null) { return; } var indexes = GetIndexesOfOutAndRefParameters(fakeObjectCall); var values = this.OutAndRefParametersValueProducer(fakeObjectCall); if (values.Count != indexes.Count) { throw new InvalidOperationException(ExceptionMessages.NumberOfOutAndRefParametersDoesNotMatchCall); } foreach (var argument in indexes.Zip(values, (index, value) => new { Index = index, Value = value })) { fakeObjectCall.SetArgumentValue(argument.Index, argument.Value); } }
private static void ApplyOutputArguments(IInterceptedFakeObjectCall call, CallDataMetadata callToApply) { foreach (var outputArgument in GetIndicesAndValuesOfOutputParameters(call, callToApply.RecordedCall)) { call.SetArgumentValue(outputArgument.Item1, outputArgument.Item2); } }
private void ApplyOutAndRefParametersValues(IInterceptedFakeObjectCall fakeObjectCall) { if (this.OutAndRefParametersValues == null) { return; } var indexes = GetIndexesOfOutAndRefParameters(fakeObjectCall); if (this.OutAndRefParametersValues.Count != indexes.Count) { throw new InvalidOperationException(ExceptionMessages.NumberOfOutAndRefParametersDoesNotMatchCall); } foreach (var argument in indexes.Zip(this.OutAndRefParametersValues)) { if (this.DoEvaluateOutAndRefFuncs) { Func<object> getter = argument.Item2 as Func<object>; if (getter != null) { object value = getter(); fakeObjectCall.SetArgumentValue(argument.Item1, value); } } else { fakeObjectCall.SetArgumentValue(argument.Item1, argument.Item2); } } }