Exemple #1
0
        public void Apply_Array_ShouldMapRowsAndValues()
        {
            // Arrange
            const int    numberOfRows = 5;
            var          tableHandle  = (IntPtr)1235;
            var          lineHandle   = (IntPtr)2245;
            RfcErrorInfo errorInfo;

            _interopMock.Setup(x => x.GetTable(DataHandle, "SOMEARRAY", out tableHandle, out errorInfo));
            _interopMock.Setup(x => x.AppendNewRow(It.IsAny <IntPtr>(), out errorInfo)).Returns(lineHandle);
            var model = new { SomeArray = Fixture.CreateMany <ArrayElement>(numberOfRows).ToArray() };

            // Act
            InputMapper.Apply(_interopMock.Object, DataHandle, model);

            // Assert
            _interopMock.Verify(x => x.AppendNewRow(tableHandle, out errorInfo), Times.Exactly(numberOfRows));
            foreach (ArrayElement element in model.SomeArray)
            {
                var length = (uint)element.Value.Length;
                _interopMock.Verify(
                    x => x.SetString(lineHandle, "VALUE", element.Value, length, out errorInfo),
                    Times.Once);
            }
        }
Exemple #2
0
        public void Apply_UnknownTypeThatCannotBeConstructed_ShouldThrowException()
        {
            Action action = () => InputMapper.Apply(_interopMock.Object, DataHandle, new { UnknownType = 1.0f });

            action.Should().Throw <InvalidOperationException>()
            .WithMessage("No matching field constructor found");
        }
Exemple #3
0
        public void Apply_Decimal_ShouldMapAsFormattedString()
        {
            RfcErrorInfo errorInfo;

            InputMapper.Apply(_interopMock.Object, DataHandle, new { SomeDecimal = 123.4M });

            _interopMock.Verify(x => x.SetString(DataHandle, "SOMEDECIMAL", "123.4", 5, out errorInfo), Times.Once);
        }
Exemple #4
0
        public void Apply_String_ShouldMapAsString()
        {
            RfcErrorInfo errorInfo;

            InputMapper.Apply(_interopMock.Object, DataHandle, new { SomeString = (string)"Hello" });

            _interopMock.Verify(x => x.SetString(DataHandle, "SOMESTRING", "Hello", 5, out errorInfo));
        }
Exemple #5
0
        public void Apply_NullInput_ShouldNotThrow()
        {
            // Act
            Action action = () => InputMapper.Apply(_interopMock.Object, DataHandle, null);

            // Assert
            action.Should().NotThrow();
        }
Exemple #6
0
        public void Apply_Double_ShouldMapAsFloat()
        {
            RfcErrorInfo errorInfo;

            InputMapper.Apply(_interopMock.Object, DataHandle, new { SomeDouble = 1234.5d });

            _interopMock.Verify(x => x.SetFloat(DataHandle, "SOMEDOUBLE", 1234.5d, out errorInfo), Times.Once);
        }
Exemple #7
0
        public void Apply_Long_ShouldMapAsInt8()
        {
            RfcErrorInfo errorInfo;

            InputMapper.Apply(_interopMock.Object, DataHandle, new { SomeLong = 123L });

            _interopMock.Verify(x => x.SetInt8(DataHandle, "SOMELONG", 123L, out errorInfo), Times.Once);
        }
Exemple #8
0
        public void Apply_Int_ShouldMapAsInt()
        {
            RfcErrorInfo errorInfo;

            InputMapper.Apply(_interopMock.Object, DataHandle, new { SomeInt = 555 });

            _interopMock.Verify(x => x.SetInt(DataHandle, "SOMEINT", 555, out errorInfo), Times.Once);
        }
Exemple #9
0
        public void Apply_NullString_ShouldNotMapString()
        {
            RfcErrorInfo errorInfo;

            InputMapper.Apply(_interopMock.Object, DataHandle, new { SomeString = (string)null });

            _interopMock.Verify(
                x => x.SetString(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <uint>(), out errorInfo),
                Times.Never);
        }
Exemple #10
0
        public void Apply_ModelWithCustomNameAttribute_ShouldUseCustomSapNameInsteadOfPropertyName()
        {
            RfcErrorInfo errorInfo;
            var          model = new CustomNameAttributeModel {
                Value = 123
            };

            InputMapper.Apply(_interopMock.Object, DataHandle, model);

            _interopMock.Verify(x => x.SetInt(DataHandle, "CUSTOM_IN_VAL", 123, out errorInfo), Times.Once);
        }
Exemple #11
0
        public void Apply_CharArray_ShouldMapAsCharArray()
        {
            // Arrange
            RfcErrorInfo errorInfo;

            // Act
            InputMapper.Apply(_interopMock.Object, DataHandle, new { SomeCharArray = new char[] { '0', '1', '2' } });

            // Assert
            _interopMock.Verify(x => x.SetChars(DataHandle, "SOMECHARARRAY", new char[] { '0', '1', '2' }, 3, out errorInfo));
        }
Exemple #12
0
        public void Apply_ByteArray_ShouldMapAsByteArray()
        {
            // Arrange
            RfcErrorInfo errorInfo;

            // Act
            InputMapper.Apply(_interopMock.Object, DataHandle, new { SomeByteArray = new byte[] { 0, 1, 2 } });

            // Assert
            _interopMock.Verify(x => x.SetBytes(DataHandle, "SOMEBYTEARRAY", new byte[] { 0, 1, 2 }, 3, out errorInfo));
        }
Exemple #13
0
        public void Apply_String_ShouldMapAsString()
        {
            // Arrange
            RfcErrorInfo errorInfo;

            // Act
            InputMapper.Apply(_interopMock.Object, DataHandle, new { SomeString = "Hello" });

            // Assert
            _interopMock.Verify(x => x.SetString(DataHandle, "SOMESTRING", "Hello", 5, out errorInfo));
        }
Exemple #14
0
        public void Apply_Array_ShouldMapAsTable()
        {
            RfcErrorInfo errorInfo;
            var          model = new { SomeArray = Fixture.CreateMany <ArrayElement>(2).ToArray() };

            InputMapper.Apply(_interopMock.Object, DataHandle, model);

            IntPtr tableHandle;

            _interopMock.Verify(x => x.GetTable(DataHandle, "SOMEARRAY", out tableHandle, out errorInfo), Times.Once);
        }
Exemple #15
0
        public void Apply_ModelWithSapIgnoreAttribute_ShouldIgnorePropertiesWithIgnoreAttribute()
        {
            RfcErrorInfo errorInfo;
            var          model = new SapIgnoreAttributeModel {
                Value = 123, IgnoredProperty = 234
            };

            InputMapper.Apply(_interopMock.Object, DataHandle, model);

            _interopMock.Verify(x => x.SetInt(DataHandle, "VALUE", 123, out errorInfo), Times.Once);
            _interopMock.Verify(x => x.SetInt(DataHandle, "IGNOREDPROPERTY", 234, out errorInfo), Times.Never);
        }
Exemple #16
0
        public override void Apply(IRfcInterop interop, IntPtr dataHandle)
        {
            RfcResultCodes resultCode = interop.GetStructure(
                dataHandle: dataHandle,
                name: Name,
                structHandle: out IntPtr structHandle,
                out RfcErrorInfo errorInfo);

            resultCode.ThrowOnError(errorInfo);

            InputMapper.Apply(interop, structHandle, Value);
        }
Exemple #17
0
        public void Apply_NullCharArray_ShouldNotMapCharArray()
        {
            // Arrange
            RfcErrorInfo errorInfo;

            // Act
            InputMapper.Apply(_interopMock.Object, DataHandle, new { SomeCharArray = (char[])null });

            // Assert
            _interopMock.Verify(
                x => x.GetChars(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <char[]>(), It.IsAny <uint>(), out errorInfo),
                Times.Never);
        }
Exemple #18
0
        public void Apply_NullableDateTime_HasValue_ShouldMapAsDate()
        {
            RfcErrorInfo errorInfo;
            DateTime?    date = new DateTime(2020, 4, 1);

            InputMapper.Apply(_interopMock.Object, DataHandle, new { SomeDate = date });

            _interopMock.Verify(x => x.SetDate(
                                    DataHandle,
                                    "SOMEDATE",
                                    It.Is <char[]>(y => y.SequenceEqual("20200401")),
                                    out errorInfo));
        }
Exemple #19
0
        public void Apply_NullArray_ShouldNotMapAsTable()
        {
            // Arrange
            RfcErrorInfo errorInfo;
            var          model = new TableModel();

            // Act
            InputMapper.Apply(_interopMock.Object, DataHandle, model);

            // Assert
            IntPtr tableHandle;

            _interopMock.Verify(x => x.GetTable(DataHandle, It.IsAny <string>(), out tableHandle, out errorInfo), Times.Never);
        }
Exemple #20
0
        public void Apply_NullableTimeSpan_NullValue_ShouldMapAsZeroTime()
        {
            RfcErrorInfo errorInfo;

            InputMapper.Apply(_interopMock.Object, DataHandle, new { SomeTime = (TimeSpan?)null });

            _interopMock.Verify(
                x => x.SetTime(
                    DataHandle,
                    "SOMETIME",
                    It.Is <char[]>(y => y.SequenceEqual("000000")),
                    out errorInfo),
                Times.Once);
        }
Exemple #21
0
        public void Apply_ModelWithSapNameAttribute_ShouldUseSapNameInsteadOfPropertyName()
        {
            // Arrange
            RfcErrorInfo errorInfo;
            var          model = new SapNameAttributeModel {
                Value = 123
            };

            // Act
            InputMapper.Apply(_interopMock.Object, DataHandle, model);

            // Assert
            _interopMock.Verify(x => x.SetInt(DataHandle, "IN_VAL", 123, out errorInfo), Times.Once);
        }
Exemple #22
0
        public void Apply_NullableTimeSpan_HasValue_ShouldMapAsTime()
        {
            RfcErrorInfo errorInfo;
            TimeSpan?    time = new TimeSpan(23, 45, 16);

            InputMapper.Apply(_interopMock.Object, DataHandle, new { SomeTime = time });

            _interopMock.Verify(
                x => x.SetTime(
                    DataHandle,
                    "SOMETIME",
                    It.Is <char[]>(y => y.SequenceEqual("234516")),
                    out errorInfo),
                Times.Once);
        }
Exemple #23
0
        public void Apply_DateTime_ShouldMapAsDate()
        {
            // Arrange
            RfcErrorInfo errorInfo;
            var          date = new DateTime(2020, 4, 1);

            // Act
            InputMapper.Apply(_interopMock.Object, DataHandle, new { SomeDate = date });

            // Assert
            _interopMock.Verify(x => x.SetDate(
                                    DataHandle,
                                    "SOMEDATE",
                                    It.Is <char[]>(y => y.SequenceEqual("20200401")),
                                    out errorInfo));
        }
Exemple #24
0
        public void Apply_NullableDateTime_NullValue_ShouldMapAsZeroDate()
        {
            // Arrange
            RfcErrorInfo errorInfo;

            // Act
            InputMapper.Apply(_interopMock.Object, DataHandle, new { SomeDate = (DateTime?)null });

            // Assert
            _interopMock.Verify(
                x => x.SetDate(
                    DataHandle,
                    "SOMEDATE",
                    It.Is <char[]>(y => y.SequenceEqual("00000000")),
                    out errorInfo),
                Times.Once);
        }
Exemple #25
0
        public void Apply_Structure_ShouldMapAsStructure()
        {
            var          structHandle = (IntPtr)44553;
            RfcErrorInfo errorInfo;

            _interopMock.Setup(x => x.GetStructure(It.IsAny <IntPtr>(), It.IsAny <string>(), out structHandle, out errorInfo));
            var model = new StructureModel {
                Structure = new Structure {
                    Value = 224
                }
            };

            InputMapper.Apply(_interopMock.Object, DataHandle, model);

            _interopMock.Verify(x => x.GetStructure(DataHandle, "STRUCTURE", out structHandle, out errorInfo), Times.Once);
            _interopMock.Verify(x => x.SetInt(structHandle, "VALUE", 224, out errorInfo), Times.Once);
        }
Exemple #26
0
        public override void Apply(RfcInterop interop, IntPtr dataHandle)
        {
            RfcResultCode resultCode = interop.GetTable(
                dataHandle: dataHandle,
                name: Name,
                out IntPtr tableHandle,
                out RfcErrorInfo errorInfo);

            resultCode.ThrowOnError(errorInfo);

            foreach (TItem row in Value)
            {
                IntPtr lineHandle = interop.AppendNewRow(tableHandle, out errorInfo);
                errorInfo.ThrowOnError();
                InputMapper.Apply(interop, lineHandle, row);
            }
        }
Exemple #27
0
        public void Apply_TimeSpan_ShouldMapAsTime()
        {
            // Arrange
            RfcErrorInfo errorInfo;
            var          time = new TimeSpan(23, 45, 16);

            // Act
            InputMapper.Apply(_interopMock.Object, DataHandle, new { SomeTime = time });

            // Assert
            _interopMock.Verify(
                x => x.SetTime(
                    DataHandle,
                    "SOMETIME",
                    It.Is <char[]>(y => y.SequenceEqual("234516")),
                    out errorInfo),
                Times.Once);
        }
Exemple #28
0
        /// <inheritdoc cref="ISapFunction"/>
        public void Invoke(object input)
        {
            InputMapper.Apply(_interop, _functionHandle, input);

            Invoke();
        }
Exemple #29
0
 public async Task <bool> InvokeAsync(object input)
 {
     InputMapper.Apply(_interop, _functionHandle, input);
     return(await InvokeAsync());
 }
 /// <inheritdoc cref="ISapServerFunction"/>
 public void SetResult(object input)
 {
     InputMapper.Apply(_interop, _functionHandle, input);
 }