コード例 #1
0
        public void ExportBinaryParameterAsByteArrayTest()
        {
            using (SapRfcConnection conn = this.GetConnection())
            {
                var result = conn.ExecuteFunction("Z_SSRT_GET_BMP_IMAGE", new
                {
                    i_object = "GRAPHICS",
                    i_name   = "IDES_LOGO",
                    i_id     = "BMAP",
                    i_btype  = "BMON"
                });

                var bytes = result.GetOutput <byte[]>("e_image");
                using (Bitmap local = (Bitmap)Bitmap.FromFile(@"Assets\IDES_LOGO.bmp"))
                {
                    using (MemoryStream ms = new MemoryStream(bytes))
                    {
                        using (Bitmap remote = (Bitmap)Bitmap.FromStream(ms))
                        {
                            ImageAssert.AreEqual(local, remote);
                        }
                    }
                }
            }
        }
コード例 #2
0
 public void ObjectFunctionWithSingleReturnValueTest()
 {
     using (SapRfcConnection conn = GetConnection())
     {
         int value = conn.ExecuteFunction(new SumOfTwoNumbersFunction(2, 8));
         Assert.Equal(10, value);
     }
 }
コード例 #3
0
 public void NullDateOutTest()
 {
     using (SapRfcConnection conn = this.GetConnection())
     {
         var result = conn.ExecuteFunction("Z_SSRT_EMPTY_DATE");
         Assert.Equal(null, result.GetOutput <DateTime?>("E_DATUM"));
     }
 }
コード例 #4
0
 public void ObjectFunctionWithTableReturnValueTest()
 {
     using (SapRfcConnection conn = GetConnection())
     {
         var customers = conn.ExecuteFunction(new GetAllCustomersFunction());
         Assert.Equal(2, customers.Count());
     }
 }
コード例 #5
0
 public void ObjectFunctionTest()
 {
     using (SapRfcConnection conn = GetConnection())
     {
         var result = conn.ExecuteFunction(new DivideTwoNumbersFunction(9, 2));
         Assert.Equal(4.5m, result.Quotient);
         Assert.Equal(1, result.Remainder);
     }
 }
コード例 #6
0
 public void ShouldNotThrowTimeoutException()
 {
     using (SapRfcConnection conn = this.GetConnection())
     {
         var result = conn.ExecuteFunction("Z_SSRT_LONG_PROCESS", new
         {
             i_seconds = 1
         });
     }
 }
コード例 #7
0
        public void MaxDateInOutTest()
        {
            using (SapRfcConnection conn = this.GetConnection())
            {
                var result = conn.ExecuteFunction("Z_SSRT_IN_OUT", new
                {
                    I_DATUM = DateTime.MaxValue
                });

                Assert.Equal(DateTime.MaxValue.Date, result.GetOutput <DateTime>("E_DATUM"));
            }
        }
コード例 #8
0
        public void NullDateInOutTest_NonNullableStruct()
        {
            using (SapRfcConnection conn = this.GetConnection())
            {
                var result = conn.ExecuteFunction("Z_SSRT_IN_OUT", new
                {
                    I_DATUM = (DateTime?)null
                });

                Assert.Equal(DateTime.MinValue, result.GetOutput <DateTime>("E_DATUM"));
            }
        }
コード例 #9
0
 public void ShouldNotExecuteFunctionBecauseItIsNotAllowed()
 {
     using (SapRfcConnection conn = this.GetConnection())
     {
         Assert.Throws <SharpRfcCallException>(() => {
             var result = conn.ExecuteFunction("Z_SSRT_SUM",
                                               new RfcParameter("i_num1", 2),
                                               new RfcParameter("i_num2", 4)
                                               );
         });
     }
 }
コード例 #10
0
        public void ExportSingleParameterTest()
        {
            using (SapRfcConnection conn = this.GetConnection())
            {
                var result = conn.ExecuteFunction("Z_SSRT_SUM",
                                                  new RfcParameter("i_num1", 2),
                                                  new RfcParameter("i_num2", 4)
                                                  );

                var total = result.GetOutput <int>("e_result");
                Assert.Equal(6, total);
            }
        }
コード例 #11
0
        public void ChangingSingleParameterTest()
        {
            using (SapRfcConnection conn = this.GetConnection())
            {
                var result = conn.ExecuteFunction("Z_SSRT_ADD",
                                                  new RfcParameter("i_add", 4),
                                                  new RfcParameter("c_num", 4)
                                                  );

                var total = result.GetOutput <int>("c_num");
                Assert.Equal(8, total);
            }
        }
コード例 #12
0
 public void TenTimesTest()
 {
     Parallel.For(1, 10, (int idx) =>
     {
         using (SapRfcConnection conn = this.GetConnection())
         {
             var result = conn.ExecuteFunction("Z_SSRT_SUM",
                                               new RfcParameter("i_num1", 2),
                                               new RfcParameter("i_num2", 4)
                                               );
         }
     });
     Task.WaitAll();
 }
コード例 #13
0
 public void ExceptionTest()
 {
     using (SapRfcConnection conn = this.GetConnection())
     {
         SharpRfcCallException ex = Assert.Throws <SharpRfcCallException>(() =>
         {
             var result = conn.ExecuteFunction("Z_SSRT_DIVIDE",
                                               new RfcParameter("i_num1", 5),
                                               new RfcParameter("i_num2", 0)
                                               );
         });
         Assert.Equal("DIVIDE_BY_ZERO", ex.Message);
     }
 }
コード例 #14
0
        public void ExportSingleParameterTest_WithAnonymousType()
        {
            using (SapRfcConnection conn = this.GetConnection())
            {
                var result = conn.ExecuteFunction("Z_SSRT_SUM", new
                {
                    i_num1 = 2,
                    i_num2 = 7
                });

                var total = result.GetOutput <int>("e_result");
                Assert.Equal(9, total);
            }
        }
コード例 #15
0
        public void ExportStructureTest()
        {
            using (SapRfcConnection conn = this.GetConnection())
            {
                var result = conn.ExecuteFunction("Z_SSRT_GET_CUSTOMER",
                                                  new RfcParameter("i_id", 2)
                                                  );

                var customer = result.GetOutput <ZCustomer>("e_customer");
                Assert.Equal(2, customer.Id);
                Assert.Equal("Walmart", customer.Name);
                Assert.Equal(false, customer.IsActive);
            }
        }
コード例 #16
0
        public void ImportStructureTest()
        {
            using (SapRfcConnection conn = this.GetConnection())
            {
                var customer = new ZCustomer {
                    Id = 3, Name = "Microsoft", IsActive = true
                };
                var result = conn.ExecuteFunction("Z_SSRT_ADD_CUSTOMER",
                                                  new RfcParameter("i_customer", customer)
                                                  );

                string message = result.GetOutput <string>("e_success");
                Assert.Equal("Created:    3 - Microsoft - X", message);
            }
        }
コード例 #17
0
        public void ExportMultipleParametersTest()
        {
            using (SapRfcConnection conn = this.GetConnection())
            {
                var result = conn.ExecuteFunction("Z_SSRT_DIVIDE",
                                                  new RfcParameter("i_num1", 5),
                                                  new RfcParameter("i_num2", 2)
                                                  );

                var quotient  = result.GetOutput <decimal>("e_quotient");
                var remainder = result.GetOutput <int>("e_remainder");
                Assert.Equal(2.5m, quotient);
                Assert.Equal(1, remainder);
            }
        }
コード例 #18
0
        public void ShouldThrowTimeoutException()
        {
            using (SapRfcConnection conn = this.GetConnection())
            {
                Exception ex = Assert.Throws <SharpRfcCallException>(() =>
                {
                    var result = conn.ExecuteFunction("Z_SSRT_LONG_PROCESS", new
                    {
                        i_seconds = 10
                    });
                });

                Assert.IsType <TimeoutException>(ex.InnerException);
            }
        }
コード例 #19
0
 public void CustomExceptionOnInvalidParameter()
 {
     using (SapRfcConnection conn = this.GetConnection())
     {
         Exception ex = Assert.Throws <UnknownRfcParameterException>(() =>
         {
             var result = conn.ExecuteFunction("Z_SSRT_SUM",
                                               new RfcParameter("i_num1", 2),
                                               new RfcParameter("i_num2", 4),
                                               new RfcParameter("i_num3", 4)
                                               );
         });
         Assert.Equal("Parameter I_NUM3 was not found on function Z_SSRT_SUM.", ex.Message);
     }
 }
コード例 #20
0
        public void ExceptionToStringShouldReturnRequestBodyTest()
        {
            using (SapRfcConnection conn = this.GetConnection())
            {
                SharpRfcCallException ex = Assert.Throws <SharpRfcCallException>(() =>
                {
                    var result = conn.ExecuteFunction("Z_SSRT_DIVIDE", new
                    {
                        i_num1 = 2,
                        i_num2 = 0
                    });
                });

                Assert.Contains(this.GetExpectedRequestBody(), ex.ToString());
            }
        }
コード例 #21
0
        public void ExportTableTest()
        {
            using (SapRfcConnection conn = this.GetConnection())
            {
                var result = conn.ExecuteFunction("Z_SSRT_GET_ALL_CUSTOMERS");

                var customers = result.GetTable <ZCustomer>("t_customers");
                Assert.Equal(2, customers.Count());

                Assert.Equal(1, customers.ElementAt(0).Id);
                Assert.Equal("Apple Store", customers.ElementAt(0).Name);
                Assert.Equal(0, customers.ElementAt(0).Age);
                Assert.Equal(true, customers.ElementAt(0).IsActive);

                Assert.Equal(2, customers.ElementAt(1).Id);
                Assert.Equal("Walmart", customers.ElementAt(1).Name);
                Assert.Equal(0, customers.ElementAt(1).Age);
                Assert.Equal(false, customers.ElementAt(1).IsActive);
            }
        }
コード例 #22
0
        public void AllTypesInOutTest()
        {
            using (SapRfcConnection conn = this.GetConnection())
            {
                var result = conn.ExecuteFunction("Z_SSRT_IN_OUT", new
                {
                    I_NAME          = "",
                    I_ID            = 2,
                    I_INT1          = 200,
                    I_FLOAT         = 20.12f,
                    I_DEC_3_2       = 4.52,
                    I_DEC_23_4      = 999999999.999,
                    I_DEC_30_7      = 999999999.9999,
                    I_DATUM         = new DateTime(2014, 4, 6),
                    I_UZEIT         = new DateTime(1, 1, 1, 12, 10, 53),
                    i_active        = true,
                    i_multiple_id   = new int[] { 10, 20, 30 },
                    i_multiple_name = new string[] { "A", "B", "C", "D" },
                    i_mara          = new ZMaraSingleDateTime {
                        Id = 4, DateTime = new DateTime(2014, 4, 6, 12, 10, 53)
                    }
                });

                Assert.Equal("", result.GetOutput <string>("E_NAME"));
                Assert.Equal(2, result.GetOutput <int>("E_ID"));
                Assert.Equal(200, result.GetOutput <byte>("E_INT1"));
                Assert.Equal(4.52m, result.GetOutput <decimal>("E_DEC_3_2"));
                Assert.Equal(999999999.999m, result.GetOutput <decimal>("E_DEC_23_4"));
                Assert.Equal(999999999.9999m, result.GetOutput <decimal>("E_DEC_30_7"));
                Assert.Equal(20.12f, result.GetOutput <double>("E_FLOAT"), 1);
                Assert.Equal(new DateTime(2014, 4, 6), result.GetOutput <DateTime>("E_DATUM"));
                Assert.Equal(new DateTime(1, 1, 1, 12, 10, 53), result.GetOutput <DateTime>("E_UZEIT"));
                Assert.Equal(true, result.GetOutput <bool>("e_active"));

                Assert.Equal(4, result.GetOutput <int>("e_mara_id"));
                Assert.Equal(new int[] { 10, 20, 30 }, result.GetTable <int>("e_multiple_id"));
                Assert.Equal(new string[] { "A", "B", "C", "D" }, result.GetTable <string>("e_multiple_name"));
                Assert.Equal(new DateTime(2014, 4, 6), result.GetOutput <DateTime>("e_mara_datum"));
                Assert.Equal(new DateTime(1, 1, 1, 12, 10, 53), result.GetOutput <DateTime>("e_mara_UZEIT"));
            }
        }
コード例 #23
0
        public void ChangingSingleStructureAsTableTest()
        {
            using (SapRfcConnection conn = this.GetConnection())
            {
                ZCustomer customer = new ZCustomer()
                {
                    Id = 1
                };

                var result = conn.ExecuteFunction("Z_SSRT_QUERY_CUSTOMERS",
                                                  new RfcParameter("c_customers", customer)
                                                  );

                var customers = result.GetTable <ZCustomer>("c_customers");
                Assert.Equal(1, customers.Count());

                Assert.Equal(1, customers.ElementAt(0).Id);
                Assert.Equal("Apple Store", customers.ElementAt(0).Name);
                Assert.Equal(0, customers.ElementAt(0).Age);
                Assert.Equal(true, customers.ElementAt(0).IsActive);
            }
        }