public void Extract_Decimal_EmptyString_ShouldMapToDecimalZero() { // Assert uint stringLength = 0; RfcErrorInfo errorInfo; _interopMock.Setup(x => x.GetString(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <char[]>(), It.IsAny <uint>(), out stringLength, out errorInfo)); // Act DecimalModel result = OutputMapper.Extract <DecimalModel>(_interopMock.Object, DataHandle); // Assert uint discard; _interopMock.Verify( x => x.GetString(DataHandle, "DECIMALVALUE", Array.Empty <char>(), 0, out discard, out errorInfo), Times.Once); result.Should().NotBeNull(); result.DecimalValue.Should().Be(0M); }
public void Extract_Decimal_ShouldMapFromDecimalString(double val) { decimal value = (decimal)val; // Assert string stringValue = value.ToString("G", CultureInfo.InvariantCulture); uint stringLength = (uint)stringValue.Length; RfcErrorInfo errorInfo; var resultCodeQueue = new Queue <RfcResultCodes>(); resultCodeQueue.Enqueue(RfcResultCodes.RFC_BUFFER_TOO_SMALL); resultCodeQueue.Enqueue(RfcResultCodes.RFC_OK); _interopMock .Setup(x => x.GetString(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <char[]>(), It.IsAny <uint>(), out stringLength, out errorInfo)) .Callback(new GetStringCallback((IntPtr dataHandle, string name, char[] buffer, uint bufferLength, out uint sl, out RfcErrorInfo ei) => { ei = default; sl = stringLength; if (buffer.Length <= 0 || bufferLength <= 0) { return; } Array.Copy(stringValue.ToCharArray(), buffer, stringValue.Length); })) .Returns(resultCodeQueue.Dequeue); // Act DecimalModel result = OutputMapper.Extract <DecimalModel>(_interopMock.Object, DataHandle); // Assert uint discard; _interopMock.Verify( x => x.GetString(DataHandle, "DECIMALVALUE", Array.Empty <char>(), 0, out discard, out errorInfo), Times.Once); _interopMock.Verify( x => x.GetString(DataHandle, "DECIMALVALUE", It.IsAny <char[]>(), stringLength + 1, out discard, out errorInfo), Times.Once); result.Should().NotBeNull(); result.DecimalValue.Should().Be(value); }