Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        public void Extract_String_ShouldMapFromString(string value)
        {
            // Assert
            string       stringValue  = value;
            uint         stringLength = (uint)stringValue.Length;
            RfcErrorInfo errorInfo;
            var          resultCodeQueue = new Queue <RfcResultCode>();

            resultCodeQueue.Enqueue(RfcResultCode.RFC_BUFFER_TOO_SMALL);
            resultCodeQueue.Enqueue(RfcResultCode.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
            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);
            _interopMock.Verify(
                x => x.GetString(DataHandle, "STRINGVALUE", It.IsAny <char[]>(), stringLength + 1, out discard, out errorInfo),
                Times.Once);
            result.Should().NotBeNull();
            result.StringValue.Should().Be(stringValue);
        }