Ejemplo n.º 1
0
        public void Extract_TimeSpan_ShouldMapFromTime()
        {
            // Arrange
            const string VALUE = "123456";
            RfcErrorInfo errorInfo;

            _interopMock
            .Setup(x => x.GetTime(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <char[]>(), out errorInfo))
            .Callback(new GetTimeCallback((IntPtr dataHandle, string name, char[] buffer, out RfcErrorInfo ei) =>
            {
                Array.Copy(VALUE.ToCharArray(), buffer, VALUE.Length);
                ei = default;
            }));

            // Act
            TimeSpanModel result = OutputMapper.Extract <TimeSpanModel>(_interopMock.Object, DataHandle);

            // Assert
            _interopMock.Verify(
                x => x.GetTime(DataHandle, "TIMESPANVALUE", It.IsAny <char[]>(), out errorInfo),
                Times.Once);
            _interopMock.Verify(
                x => x.GetTime(DataHandle, "NULLABLETIMESPANVALUE", It.IsAny <char[]>(), out errorInfo),
                Times.Once);
            result.Should().NotBeNull();
            result.TimeSpanValue.Should().Be(new TimeSpan(12, 34, 56));
            result.NullableTimeSpanValue.Should().Be(new TimeSpan(12, 34, 56));
        }
Ejemplo n.º 2
0
        public void Extract_DateTime_ShouldMapFromDate()
        {
            // Arrange
            const string VALUE = "20200405";
            RfcErrorInfo errorInfo;

            _interopMock
            .Setup(x => x.GetDate(It.IsAny <IntPtr>(), It.IsAny <string>(), It.IsAny <char[]>(), out errorInfo))
            .Callback(new GetDateCallback((IntPtr dataHandle, string name, char[] buffer, out RfcErrorInfo ei) =>
            {
                Array.Copy(VALUE.ToCharArray(), buffer, VALUE.Length);
                ei = default;
            }));

            // Act
            DateTimeModel result = OutputMapper.Extract <DateTimeModel>(_interopMock.Object, DataHandle);

            // Assert
            _interopMock.Verify(
                x => x.GetDate(DataHandle, "DATETIMEVALUE", It.IsAny <char[]>(), out errorInfo),
                Times.Once);
            _interopMock.Verify(
                x => x.GetDate(DataHandle, "NULLABLEDATETIMEVALUE", It.IsAny <char[]>(), out errorInfo),
                Times.Once);
            result.Should().NotBeNull();
            result.DateTimeValue.Should().Be(new DateTime(2020, 04, 05));
            result.NullableDateTimeValue.Should().Be(new DateTime(2020, 04, 05));
        }