public static void Run() { string connStr = "connectionstring"; using var connection = new SapConnection(connStr); connection.Connect(); using var someFunction = connection.CreateFunction("MySapfunction"); var result = someFunction.Invoke <SomeFunctionResult>(new { VBELN = "partnumber", }); }
public void Disconnect_Connected_ShouldDisconnect() { // 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); connection.Connect(); // Act connection.Disconnect(); // Assert _interopMock.Verify(x => x.CloseConnection(RfcConnectionHandle, out errorInfo), Times.Once); }
public void Connect_ConnectionFailed_ShouldThrow() { // Arrange var connection = new SapConnection(_interopMock.Object, new SapConnectionParameters()); var errorInfo = new RfcErrorInfo { Code = RfcResultCode.RFC_TIMEOUT }; _interopMock .Setup(x => x.OpenConnection(It.IsAny <RfcConnectionParameter[]>(), It.IsAny <uint>(), out errorInfo)); // Act Action action = () => connection.Connect(); // Assert action.Should().Throw <SapException>() .WithMessage("SAP RFC Error: RFC_TIMEOUT"); }
public void Connect_ConnectionSucceeds_ShouldOpenConnection() { // Arrange var parameters = new SapConnectionParameters { AppServerHost = "my-server.com" }; var connection = new SapConnection(_interopMock.Object, parameters); // Act connection.Connect(); // Assert RfcErrorInfo errorInfo; _interopMock.Verify( x => x.OpenConnection(It.IsAny <RfcConnectionParameter[]>(), 1, out errorInfo), Times.Once); }
static void Main(string[] args) { try { Console.WriteLine("/************************ rfc .net core support *************************"); Console.WriteLine(" Author(s): christ chang"); Console.WriteLine(" Description: rfc .net core support"); Console.WriteLine(" github: https://github.com/Nightstars/rfc_demo"); Console.WriteLine(" thanks: huysentruitw and his work "); Console.WriteLine("************************************************************************/"); //define connect string string connectionString = "AppServerHost=192.168.95.20; SystemNumber=00; User=ZBT_RFC; Password=Zbt_rfc123; Client=310; Language=ZH; PoolSize=5; Trace=8;"; //structure rfc connection using var connection = new SapConnection(connectionString); //open rfc connection connection.Connect(); //structure call function by rfc target fun using var someFunction = connection.CreateFunction("ZMDG_MDATA_INFO"); //call remote rfc functon with input parameter constructor and get fun result rfc_demo.FunctionResult result = someFunction.Invoke <FunctionResult>(new FunctionParameters { Ibukrs = "1010", Iztype = "2", Izdata = "20200801", Iztime = "00:00:00" }); //print result in console foreach (ZMDGS003 item in result.result) { Console.WriteLine(item.Mdata); Console.WriteLine(item.Meinst); Console.WriteLine(item.Groes); Console.WriteLine(item.Zspm); Console.WriteLine(item.Maktx); Console.WriteLine(item.Bukrs); Console.WriteLine(); } Console.ReadKey(); }catch (Exception e) { Console.WriteLine("Oh no: " + e.Message); Console.ReadKey(); } }
public ClassRfcReadTable SapReadTable(string query_table, string delimiter, string no_data, string fields, string filter) { SapLibrary.EnsureLibraryPresent(); ClassRfcReadTable data = null; // System.Console.WriteLine("Starting..."); var connectionString = ConfigurationManager.AppSettings["ConnectionString"]; using var conn = new SapConnection(connectionString); conn.Connect(); // Console.WriteLine("SAP Connction was opened..."); ClassRfcReadTableInput fc = new ClassRfcReadTableInput(); fc.QueryTable = query_table; fc.Delimiter = delimiter; fc.NoData = no_data; string[] af = fields.Split(','); fc.Fields = new RFC_DB_FLD[af.Length]; for (int i = 0; i < af.Length; i++) { fc.Fields[i] = new RFC_DB_FLD(); fc.Fields[i].FieldName = af[i]; } string[] ao = filter.Split(','); if (ao != null && ao.Length > 0) { fc.Options = new RFC_DB_OPT[ao.Length]; } for (int i = 0; i < ao.Length; i++) { fc.Options[i] = new RFC_DB_OPT(); if (!string.IsNullOrEmpty(ao[i])) { if (ao[i].Length > 72) { throw new Exception("Error by rfc_read_table:; an option string is longer as 72 -> " + ao[i]); } fc.Options[i].Text = ao[i]; } } using var func = conn.CreateFunction("RFC_READ_TABLE"); data = func.Invoke <ClassRfcReadTable>(fc); return(data); }
public void Ping_Connected_PingTimeout_ShouldReturnFalse() { // Arrange RfcErrorInfo errorInfo; _interopMock .Setup(x => x.OpenConnection(It.IsAny <RfcConnectionParameter[]>(), It.IsAny <uint>(), out errorInfo)) .Returns(RfcConnectionHandle); _interopMock .Setup(x => x.Ping(RfcConnectionHandle, out errorInfo)) .Returns(RfcResultCode.RFC_TIMEOUT); var connection = new SapConnection(_interopMock.Object, new SapConnectionParameters()); connection.Connect(); // Act var pingResult = connection.Ping(); // Assert pingResult.Should().BeFalse(); }
public void Dispose_DisconnectionFailed_ShouldNotThrow() { // 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.CloseConnection(It.IsAny <IntPtr>(), out errorInfo)) .Returns(RfcResultCode.RFC_CANCELED); connection.Connect(); // Act Action action = () => connection.Dispose(); // Assert action.Should().NotThrow(); }
public void IsValid_ConnectionHandleInvalid_ShouldReturnFalse() { // Arrange var connection = new SapConnection(_interopMock.Object, new SapConnectionParameters()); int isValidValue = 0; RfcErrorInfo errorInfo; _interopMock .Setup(x => x.OpenConnection(It.IsAny <RfcConnectionParameter[]>(), It.IsAny <uint>(), out errorInfo)) .Returns(RfcConnectionHandle); _interopMock .Setup(x => x.IsConnectionHandleValid(RfcConnectionHandle, out isValidValue, out errorInfo)) .Returns(RfcResultCode.RFC_OK); connection.Connect(); // Arrange var isValid = connection.IsValid; // Assert isValid.Should().BeFalse(); }
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); }
public void IsConnected_ConnectedButLibraryReturnsError_ShouldReturnFalse() { // 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); int isValid = 1; _interopMock .Setup(x => x.IsConnectionHandleValid(RfcConnectionHandle, out isValid, out errorInfo)) .Returns(RfcResultCode.RFC_CLOSED); connection.Connect(); // Act bool isConnected = connection.IsValid; // Assert isConnected.Should().BeFalse(); }