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)); }
public void Extract_NonNullableDateTime_ZeroOrEmptyOrInvalidDate_ShouldMapToMinimumDateTime(string value) { // Arrange 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); result.Should().NotBeNull(); result.DateTimeValue.Should().Be(DateTime.MinValue); }