public void CreateFromDescriptionHandle_ShouldCreateFunction()
        {
            // Act
            ISapFunction function = SapFunction.CreateFromDescriptionHandle(_interopMock.Object, RfcConnectionHandle, FunctionDescriptionHandle);

            // Assert
            function.Should().NotBeNull();
            RfcErrorInfo errorInfo;

            _interopMock.Verify(x => x.CreateFunction(FunctionDescriptionHandle, out errorInfo), Times.Once);
        }
        public void Invoke_NoInput_NoOutput_ShouldInvokeFunction()
        {
            // Arrange
            RfcErrorInfo errorInfo;

            _interopMock.Setup(x => x.CreateFunction(FunctionDescriptionHandle, out errorInfo)).Returns(FunctionHandle);
            ISapFunction function = SapFunction.CreateFromDescriptionHandle(_interopMock.Object, RfcConnectionHandle, FunctionDescriptionHandle);

            // Act
            function.Invoke();

            // Assert
            _interopMock.Verify(x => x.Invoke(RfcConnectionHandle, FunctionHandle, out errorInfo), Times.Once);
        }
        public void Dispose_ShouldDestroyFunction()
        {
            // Arrange
            RfcErrorInfo errorInfo;

            _interopMock.Setup(x => x.CreateFunction(FunctionDescriptionHandle, out errorInfo)).Returns(FunctionHandle);
            ISapFunction function = SapFunction.CreateFromDescriptionHandle(_interopMock.Object, RfcConnectionHandle, FunctionDescriptionHandle);

            // Act
            function.Dispose();

            // Assert
            _interopMock.Verify(x => x.DestroyFunction(FunctionHandle, out errorInfo), Times.Once);
        }
        public void Invoke_WithInput_NoOutput_ShouldMapInput()
        {
            // Arrange
            RfcErrorInfo errorInfo;

            _interopMock.Setup(x => x.CreateFunction(FunctionDescriptionHandle, out errorInfo)).Returns(FunctionHandle);
            ISapFunction function = SapFunction.CreateFromDescriptionHandle(_interopMock.Object, RfcConnectionHandle, FunctionDescriptionHandle);

            // Act
            function.Invoke(new { Value = 123 });

            // Assert
            _interopMock.Verify(x => x.SetInt(FunctionHandle, "VALUE", 123, out errorInfo), Times.Once);
            _interopMock.Verify(x => x.Invoke(RfcConnectionHandle, FunctionHandle, out errorInfo), Times.Once);
        }
Exemple #5
0
        public void HasParameter_ParameterDoesNotExist_ShouldReturnFalse()
        {
            // Arrange
            RfcParameterDescription parameterDescHandle;
            RfcErrorInfo            errorInfo;

            _interopMock
            .Setup(x => x.GetParameterDescByName(It.IsAny <IntPtr>(), "PAR123", out parameterDescHandle, out errorInfo))
            .Returns(RfcResultCode.RFC_NOT_FOUND);
            ISapFunction function = SapFunction.CreateFromDescriptionHandle(_interopMock.Object, RfcConnectionHandle, FunctionDescriptionHandle);

            // Act
            var result = function.HasParameter("PAR123");

            // Assert
            result.Should().BeFalse();
        }
        public void Apply_WithInput_WithOutput_ShouldMapInputAndOutput()
        {
            // Arrange
            int          value = 456;
            RfcErrorInfo errorInfo;

            _interopMock.Setup(x => x.CreateFunction(FunctionDescriptionHandle, out errorInfo)).Returns(FunctionHandle);
            _interopMock.Setup(x => x.GetInt(It.IsAny <IntPtr>(), It.IsAny <string>(), out value, out errorInfo));
            ISapFunction function = SapFunction.CreateFromDescriptionHandle(_interopMock.Object, RfcConnectionHandle, FunctionDescriptionHandle);

            // Act
            OutputModel result = function.Invoke <OutputModel>(new { Value = 123 });

            // Assert
            _interopMock.Verify(x => x.SetInt(FunctionHandle, "VALUE", 123, out errorInfo), Times.Once);
            _interopMock.Verify(x => x.Invoke(RfcConnectionHandle, FunctionHandle, out errorInfo), Times.Once);
            _interopMock.Verify(x => x.GetInt(FunctionHandle, "VALUE", out value, out errorInfo), Times.Once);
        }
        public void Invoke_NoInput_WithOutput_ShouldMapOutput()
        {
            // Arrange
            int          value = 456;
            RfcErrorInfo errorInfo;

            _interopMock.Setup(x => x.CreateFunction(FunctionDescriptionHandle, out errorInfo)).Returns(FunctionHandle);
            _interopMock.Setup(x => x.GetInt(FunctionHandle, "VALUE", out value, out errorInfo));
            ISapFunction function = SapFunction.CreateFromDescriptionHandle(_interopMock.Object, RfcConnectionHandle, FunctionDescriptionHandle);

            // Act
            OutputModel result = function.Invoke <OutputModel>();

            // Assert
            result.Should().NotBeNull();
            result.Value.Should().Be(value);
            _interopMock.Verify(x => x.GetInt(FunctionHandle, "VALUE", out value, out errorInfo), Times.Once);
            _interopMock.Verify(x => x.Invoke(RfcConnectionHandle, FunctionHandle, out errorInfo), Times.Once);
        }
Exemple #8
0
        /// <inheritdoc cref="ISapPooledConnection"/>
        public TOutput InvokeFunction <TOutput>(string name, CancellationToken cancellationToken = default)
        {
            try
            {
                _connection = _connection ?? _pool.GetConnection(cancellationToken);
                using (ISapFunction function = _connection.CreateFunction(name))
                    return(function.Invoke <TOutput>());
            }
            catch (SapCommunicationFailedException)
            {
                // Let the pool collect the dead connection
                _pool.ForgetConnection(_connection);

                // Retry invocation with new connection from the pool
                _connection = _pool.GetConnection(cancellationToken);
                using (ISapFunction function = _connection.CreateFunction(name))
                    return(function.Invoke <TOutput>());
            }
        }
Exemple #9
0
        /// <inheritdoc cref="ISapPooledConnection"/>
        public void InvokeFunction(string name, object input, CancellationToken cancellationToken = default)
        {
            try
            {
                _connection = _connection ?? _pool.GetConnection(cancellationToken);
                using (ISapFunction function = _connection.CreateFunction(name))
                    function.Invoke(input);
            }
            catch (SapCommunicationFailedException)
            {
                // Let the pool collect the dead connection
                _pool.ForgetConnection(_connection);

                // Retry invocation with new connection from the pool
                _connection = _pool.GetConnection(cancellationToken);
                using (ISapFunction function = _connection.CreateFunction(name))
                    function.Invoke(input);
            }
        }
        public void CreateFunction_ShouldCreateFunction()
        {
            // Arrange
            var          connection = new SapConnection(_interopMock.Object, new SapConnectionParameters());
            RfcErrorInfo errorInfo;

            _interopMock
            .Setup(x => x.OpenConnection(It.IsAny <RfcConnectionParameter[]>(), It.IsAny <uint>(), out errorInfo))
            .Returns(RfcConnectionHandle);
            _interopMock
            .Setup(x => x.GetFunctionDesc(RfcConnectionHandle, "FunctionA", out errorInfo))
            .Returns(FunctionDescriptionHandle);

            connection.Connect();

            // Act
            ISapFunction function = connection.CreateFunction("FunctionA");

            // Assert
            function.Should().NotBeNull();
            _interopMock.Verify(x => x.CreateFunction(FunctionDescriptionHandle, out errorInfo), Times.Once);
        }