lundi 19 septembre 2016

Setup byref parameters in VB from MOQ with C#

The code to be tested looks like this in VB. Simplified

Public Interface IFwCompressor
  Function Calculate(ByVal condenserPower As Double,
                     ByVal evaporatingTemp As Double,
                     ByVal condensingTemp As Double,
                     ByRef rotationalSpeed As Double,
                     ByRef compressorPower As Double,
                     ByRef electricalPower As Double) As CalculationResult

  Enum CalculationResult
    ActivateNextCircuit = 3
    Off = 2
    Ok = 0
    UnknownError = -1
    MaxRps = -6
  End Enum
End Interface

Public Class Compressor
  Private ReadOnly _fwCompressor As IFwCompressor

  Public Sub New(ByVal fwCompressor As IFwCompressor)
    _fwCompressor = fwCompressor                
  End Sub

  Public Function CalculateIntermittentResult(ByVal compressorInput As CompressorIntermittenInput) As StatusAndResult(Of CompressorStatus, CompressorResult)

    Dim meanCompressorPower, meanRotationalSpeed, meanElectricalPower As Double

    Dim result = _fwCompressor.CalculateIntermittentResult( _
      compressorInput.RotationalSpeed,
      compressorInput.RunningTimeFraction,
      compressorInput.CompressorPower,
      meanRotationalSpeed,
      meanCompressorPower,
      meanElectricalPower)

    Return New StatusAndResult(Of CompressorStatus, CompressorResult)(
      CompressorStatus.Ok,
      New CompressorResult(CompressorRunMode.Intermittent,
                           meanRotationalSpeed,
                           meanCompressorPower,
                           meanElectricalPower))
End Function

The test I've written like this. C# and the MOQ framework.

double meanRotationalSpeed = 15;
double meanCompressorPower = 1000; 
double meanElectricalPower = 500; 

fwCompressor.Setup(e => e.CalculateIntermittentResult(It.IsAny<double>(),
                                                      It.IsAny<double>(),
                                                      It.IsAny<double>(),
                                                      ref meanRotationalSpeed,
                                                      ref meanCompressorPower,
                                                      ref meanElectricalPower)).Returns(MaxRps);

My problem is that when the method gets invoke inside CalculateIntermittentResult, the parameters meanRotationalSpeed, MeanCompressorPower, MeanElectricalPower and the result return 0?

ByRef Parameters in MOQ, is it possible from C# to VB?

Aucun commentaire:

Enregistrer un commentaire