コード例 #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));
        }
コード例 #2
0
        public void Extract_NonNullableTimeSpan_ZeroOrEmptyOrInvalidTime_ShouldMapToZeroTimeSpan(string value)
        {
            // Arrange
            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);
            result.Should().NotBeNull();
            result.TimeSpanValue.Should().Be(TimeSpan.Zero);
        }