public void Extract_TableWithLessRowsThanAnnounced_ShouldReturnExtractedRows() { // Arrange var tableHandle = (IntPtr)3334; var rowHandle = (IntPtr)4445; uint rowCount = 3; int intValue = 888; RfcErrorInfo errorInfo; _interopMock.Setup(x => x.GetTable(It.IsAny <IntPtr>(), It.IsAny <string>(), out tableHandle, out errorInfo)); _interopMock.Setup(x => x.GetRowCount(It.IsAny <IntPtr>(), out rowCount, out errorInfo)); _interopMock.Setup(x => x.GetCurrentRow(It.IsAny <IntPtr>(), out errorInfo)).Returns(rowHandle); _interopMock.Setup(x => x.GetInt(It.IsAny <IntPtr>(), It.IsAny <string>(), out intValue, out errorInfo)); _interopMock .Setup(x => x.MoveToNextRow(It.IsAny <IntPtr>(), out errorInfo)) .Returns(RfcResultCode.RFC_TABLE_MOVE_EOF); // Act ArrayModel result = OutputMapper.Extract <ArrayModel>(_interopMock.Object, DataHandle); // Assert result.Should().NotBeNull(); result.Elements.Should().HaveCount(1); }
public void Extract_TimeSpan_ShouldMapFromTime() { // Arrange const string VALUE = "123456"; RfcErrorInfo errorInfo; _interopMock .Setup(x => x.GetTime(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <char[]>(), out errorInfo)) .Callback(new GetTimeCallback((IntPtr dataHandle, string name, char[] buffer, out RfcErrorInfo ei) => { Array.Copy(VALUE.ToCharArray(), buffer, VALUE.Length); ei = default; })); // Act TimeSpanModel result = OutputMapper.Extract <TimeSpanModel>(_interopMock.Object, DataHandle); // Assert _interopMock.Verify( x => x.GetTime(DataHandle, "TIMESPANVALUE", It.IsAny <char[]>(), out errorInfo), Times.Once); _interopMock.Verify( x => x.GetTime(DataHandle, "NULLABLETIMESPANVALUE", It.IsAny <char[]>(), out errorInfo), Times.Once); result.Should().NotBeNull(); result.TimeSpanValue.Should().Be(new TimeSpan(12, 34, 56)); result.NullableTimeSpanValue.Should().Be(new TimeSpan(12, 34, 56)); }
public void Extract_TableWithRows_ShouldMapToArrayOfElements() { // Arrange var tableHandle = (IntPtr)3334; var rowHandle = (IntPtr)4445; uint rowCount = 3; int intValue = 888; RfcErrorInfo errorInfo; _interopMock.Setup(x => x.GetTable(It.IsAny <IntPtr>(), It.IsAny <string>(), out tableHandle, out errorInfo)); _interopMock.Setup(x => x.GetRowCount(It.IsAny <IntPtr>(), out rowCount, out errorInfo)); _interopMock.Setup(x => x.GetCurrentRow(It.IsAny <IntPtr>(), out errorInfo)).Returns(rowHandle); _interopMock.Setup(x => x.GetInt(It.IsAny <IntPtr>(), It.IsAny <string>(), out intValue, out errorInfo)); // Act ArrayModel result = OutputMapper.Extract <ArrayModel>(_interopMock.Object, DataHandle); // Assert _interopMock.Verify( x => x.GetTable(DataHandle, "ELEMENTS", out tableHandle, out errorInfo), Times.Once); _interopMock.Verify( x => x.GetRowCount(tableHandle, out rowCount, out errorInfo), Times.Once); _interopMock.Verify( x => x.GetCurrentRow(tableHandle, out errorInfo), Times.Exactly(3)); _interopMock.Verify( x => x.GetInt(rowHandle, "VALUE", out intValue, out errorInfo), Times.Exactly(3)); _interopMock.Verify(x => x.MoveToNextRow(tableHandle, out errorInfo), Times.Exactly(3)); result.Should().NotBeNull(); result.Elements.Should().HaveCount(3); result.Elements.First().Value.Should().Be(888); }
public void Extract_DateTime_ShouldMapFromDate() { // Arrange const string VALUE = "20200405"; RfcErrorInfo errorInfo; _interopMock .Setup(x => x.GetDate(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <char[]>(), out errorInfo)) .Callback(new GetDateCallback((IntPtr dataHandle, string name, char[] buffer, out RfcErrorInfo ei) => { Array.Copy(VALUE.ToCharArray(), buffer, VALUE.Length); ei = default; })); // Act DateTimeModel result = OutputMapper.Extract <DateTimeModel>(_interopMock.Object, DataHandle); // Assert _interopMock.Verify( x => x.GetDate(DataHandle, "DATETIMEVALUE", It.IsAny <char[]>(), out errorInfo), Times.Once); _interopMock.Verify( x => x.GetDate(DataHandle, "NULLABLEDATETIMEVALUE", It.IsAny <char[]>(), out errorInfo), Times.Once); result.Should().NotBeNull(); result.DateTimeValue.Should().Be(new DateTime(2020, 04, 05)); result.NullableDateTimeValue.Should().Be(new DateTime(2020, 04, 05)); }
public void Extract_UnknownTypeThatCannotBeExtracted_ShouldThrowException() { // Arrange & Act Action action = () => OutputMapper.Extract <UnknownTypeModel>(_interopMock.Object, DataHandle); // Assert action.Should().Throw <InvalidOperationException>() .WithMessage("No matching extract method found for type Single"); }
public static TableField <T> Extract <T>(RfcInterop interop, IntPtr dataHandle, string name) { RfcResultCode resultCode = interop.GetTable( dataHandle: dataHandle, name: name, tableHandle: out IntPtr tableHandle, errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); resultCode = interop.GetRowCount( tableHandle: tableHandle, rowCount: out uint rowCount, errorInfo: out errorInfo); resultCode.ThrowOnError(errorInfo); if (rowCount == 0) { return(new TableField <T>(name, Array.Empty <T>())); } var rows = new T[rowCount]; resultCode = interop.MoveToFirstRow( tableHandle: tableHandle, errorInfo: out errorInfo); resultCode.ThrowOnError(errorInfo); for (int i = 0; i < rowCount; i++) { IntPtr rowHandle = interop.GetCurrentRow( tableHandle: tableHandle, errorInfo: out errorInfo); errorInfo.ThrowOnError(); rows[i] = OutputMapper.Extract <T>(interop, rowHandle); resultCode = interop.MoveToNextRow( tableHandle: tableHandle, errorInfo: out errorInfo); if (resultCode == RfcResultCode.RFC_TABLE_MOVE_EOF) { Array.Resize(ref rows, i + 1); break; } resultCode.ThrowOnError(errorInfo); } return(new TableField <T>(name, rows)); }
public static StructureField <T> Extract <T>(IRfcInterop interop, IntPtr dataHandle, string name) { RfcResultCodes resultCode = interop.GetStructure( dataHandle: dataHandle, name: name, structHandle: out IntPtr structHandle, out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); T structValue = OutputMapper.Extract <T>(interop, structHandle); return(new StructureField <T>(name, structValue)); }
public void Extract_Double_ShouldMapFromFloat(double value) { // Arrange var doubleValue = value; RfcErrorInfo errorInfo; _interopMock.Setup(x => x.GetFloat(DataHandle, "DOUBLEVALUE", out doubleValue, out errorInfo)); // Act DoubleModel result = OutputMapper.Extract <DoubleModel>(_interopMock.Object, DataHandle); // Assert result.Should().NotBeNull(); result.DoubleValue.Should().Be(doubleValue); }
public void Extract_PropertyWithSapNameAttribute_ShouldMapUsingRfcName() { // Arrange int value = 334; RfcErrorInfo errorInfo; _interopMock.Setup(x => x.GetInt(DataHandle, "I34", out value, out errorInfo)); // Act IntAttributeModel result = OutputMapper.Extract <IntAttributeModel>(_interopMock.Object, DataHandle); // Assert result.Should().NotBeNull(); result.IntValue.Should().Be(334); }
public void Extract_Long_ShouldMapFromInt8(long value) { // Arrange var longValue = value; RfcErrorInfo errorInfo; _interopMock.Setup(x => x.GetInt8(DataHandle, "LONGVALUE", out longValue, out errorInfo)); // Act LongModel result = OutputMapper.Extract <LongModel>(_interopMock.Object, DataHandle); // Assert result.Should().NotBeNull(); result.LongValue.Should().Be(longValue); }
public void Extract_Int_ShouldMapFromInt(int value) { // Arrange int intValue = value; RfcErrorInfo errorInfo; _interopMock.Setup(x => x.GetInt(DataHandle, "INTVALUE", out intValue, out errorInfo)); // Act IntModel result = OutputMapper.Extract <IntModel>(_interopMock.Object, DataHandle); // Assert result.Should().NotBeNull(); result.IntValue.Should().Be(intValue); }
public void Extract_PropertyWithIgnoreAttribute_ShouldBeIgnored() { // Arrange int value = 123; RfcErrorInfo errorInfo; _interopMock.Setup(x => x.GetInt(DataHandle, "VALUE", out value, out errorInfo)); // Act IgnoreAttributeModel result = OutputMapper.Extract <IgnoreAttributeModel>(_interopMock.Object, DataHandle); // Assert _interopMock.Verify(x => x.GetInt(DataHandle, "VALUE", out value, out errorInfo), Times.Never); result.Should().NotBeNull(); result.Value.Should().Be(0); }
public void Extract_EmptyCharArray_ShouldMapAsEmptyCharArray() { // Arrange RfcErrorInfo errorInfo; uint bufferLength = 0; _interopMock.Setup(x => x.GetChars(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <char[]>(), bufferLength, out errorInfo)); // Act EmptyCharsModel result = OutputMapper.Extract <EmptyCharsModel>(_interopMock.Object, DataHandle); // Assert _interopMock.Verify( x => x.GetChars(DataHandle, "CHARSVALUE", Array.Empty <char>(), 0, out errorInfo), Times.Never); result.Should().NotBeNull(); result.CharsValue.Should().BeEmpty(); }
public static TableField <T> Extract <T>(IRfcInterop interop, IntPtr dataHandle, string name) { RfcResultCodes resultCode = interop.GetTable( dataHandle: dataHandle, name: name, tableHandle: out IntPtr tableHandle, errorInfo: out RfcErrorInfo errorInfo); resultCode.ThrowOnError(errorInfo); resultCode = interop.GetRowCount( tableHandle: tableHandle, out uint rowCount, out errorInfo); resultCode.ThrowOnError(errorInfo); var rows = new T[rowCount]; for (int i = 0; i < rowCount; i++) { IntPtr rowHandle = interop.GetCurrentRow( tableHandle: tableHandle, errorInfo: out errorInfo); errorInfo.ThrowOnError(); rows[i] = OutputMapper.Extract <T>(interop, rowHandle); resultCode = interop.MoveToNextRow( tableHandle: tableHandle, errorInfo: out errorInfo); if (resultCode == RfcResultCodes.RFC_TABLE_MOVE_EOF) { return(new TableField <T>(name, rows.Take(i + 1).ToArray())); } resultCode.ThrowOnError(errorInfo); } return(new TableField <T>(name, rows)); }
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_EmptyString_ShouldMapAsEmptyString() { // Arrange RfcErrorInfo errorInfo; uint stringLength = 0; _interopMock.Setup(x => x.GetString(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <char[]>(), It.IsAny <uint>(), out stringLength, out errorInfo)); // Act StringModel result = OutputMapper.Extract <StringModel>(_interopMock.Object, DataHandle); // Assert uint discard; _interopMock.Verify( x => x.GetString(DataHandle, "STRINGVALUE", Array.Empty <char>(), 0, out discard, out errorInfo), Times.Once); result.Should().NotBeNull(); result.StringValue.Should().BeEmpty(); }
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); }
public void Extract_CharArray_ShouldMapFromCharArray(char[] value) { // Arrange RfcErrorInfo errorInfo; _interopMock .Setup(x => x.GetChars(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <char[]>(), It.IsAny <uint>(), out errorInfo)) .Callback(new GetCharsCallback((IntPtr dataHandle, string name, char[] buffer, uint bufferLength, out RfcErrorInfo ei) => { Array.Copy(value, buffer, value.Length); ei = default; })); // Act CharsModel result = OutputMapper.Extract <CharsModel>(_interopMock.Object, DataHandle); // Assert _interopMock.Verify( x => x.GetChars(DataHandle, "CHARSVALUE", It.IsAny <char[]>(), 3, out errorInfo), Times.Once); result.Should().NotBeNull(); result.CharsValue.Should().BeEquivalentTo(value); }
public void Extract_NullableTimeSpan_ZeroOrEmptyOrInvalidTime_ShouldMapToNullTimeSpan(string value) { // Arrange RfcErrorInfo errorInfo; _interopMock .Setup(x => x.GetTime(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <char[]>(), out errorInfo)) .Callback(new GetTimeCallback((IntPtr dataHandle, string name, char[] buffer, out RfcErrorInfo ei) => { Array.Copy(value.ToCharArray(), buffer, value.Length); ei = default; })); // Act TimeSpanModel result = OutputMapper.Extract <TimeSpanModel>(_interopMock.Object, DataHandle); // Assert _interopMock.Verify( x => x.GetTime(DataHandle, "NULLABLETIMESPANVALUE", It.IsAny <char[]>(), out errorInfo), Times.Once); result.Should().NotBeNull(); result.NullableTimeSpanValue.Should().BeNull(); }
public void Extract_TableWithZeroRows_ShouldNotCallMoveToFirstRow() { // Arrange var tableHandle = (IntPtr)3334; var rowHandle = (IntPtr)4445; uint rowCount = 0; RfcErrorInfo errorInfo; _interopMock.Setup(x => x.GetTable(It.IsAny <IntPtr>(), It.IsAny <string>(), out tableHandle, out errorInfo)); _interopMock.Setup(x => x.GetRowCount(It.IsAny <IntPtr>(), out rowCount, out errorInfo)); _interopMock.Setup(x => x.MoveToFirstRow(It.IsAny <IntPtr>(), out errorInfo)); _interopMock.Setup(x => x.GetCurrentRow(It.IsAny <IntPtr>(), out errorInfo)).Returns(rowHandle); _interopMock .Setup(x => x.MoveToNextRow(It.IsAny <IntPtr>(), out errorInfo)) .Returns(RfcResultCode.RFC_TABLE_MOVE_EOF); // Act ArrayModel result = OutputMapper.Extract <ArrayModel>(_interopMock.Object, DataHandle); // Assert _interopMock.Verify( x => x.GetTable(DataHandle, "ELEMENTS", out tableHandle, out errorInfo), Times.Once); _interopMock.Verify( x => x.GetRowCount(tableHandle, out rowCount, out errorInfo), Times.Once); _interopMock.Verify( x => x.MoveToFirstRow(tableHandle, out errorInfo), Times.Never); _interopMock.Verify( x => x.GetCurrentRow(tableHandle, out errorInfo), Times.Never); _interopMock.Verify(x => x.MoveToNextRow(tableHandle, out errorInfo), Times.Never); result.Should().NotBeNull(); result.Elements.Should().HaveCount(0); }
public void Extract_Structure_ShouldMapToNestedObject() { // Arrange var structHandle = (IntPtr)443534; var intValue = 123; RfcErrorInfo errorInfo; _interopMock.Setup(x => x.GetStructure(It.IsAny <IntPtr>(), It.IsAny <string>(), out structHandle, out errorInfo)); _interopMock.Setup(x => x.GetInt(It.IsAny <IntPtr>(), It.IsAny <string>(), out intValue, out errorInfo)); // Act NestedModel result = OutputMapper.Extract <NestedModel>(_interopMock.Object, DataHandle); // Assert _interopMock.Verify( x => x.GetStructure(DataHandle, "INNERMODEL", out structHandle, out errorInfo), Times.Once); _interopMock.Verify( x => x.GetInt(structHandle, "VALUE", out intValue, out errorInfo), Times.Once); result.Should().NotBeNull(); result.InnerModel.Should().NotBeNull(); result.InnerModel.Value.Should().Be(123); }
/// <inheritdoc cref="ISapFunction"/> public TOutput Invoke <TOutput>(object input) { Invoke(input); return(OutputMapper.Extract <TOutput>(_interop, _functionHandle)); }
public async Task <TOutput> InvokeAsync <TOutput>(object input) { await InvokeAsync(input); return(OutputMapper.Extract <TOutput>(_interop, _functionHandle)); }
/// <inheritdoc cref="ISapServerFunction"/> public TOutput GetParameters <TOutput>() { return(OutputMapper.Extract <TOutput>(_interop, _functionHandle)); }
public virtual TOutput Invoke <TOutput>() { Invoke(); return(OutputMapper.Extract <TOutput>(_interop, _functionHandle)); }
public TOutput ReadSubmitResult <TOutput>() { return(OutputMapper.Extract <TOutput>(_interop, _functionHandle)); }