The main problem here is that SQLiteDataReader has an internal constructor, which would make trying to mock it rather difficult. That leaves trying to perform an integration test with an actual connection, command and reader, which is not very isolated.
If however the extension method was refactored to depend on the abstraction like DbDataReader
public static DateTime GetDateTime(this DbDataReader reader, int columnNumber, string format) {
string date = reader.GetString(columnNumber);
DateTime dateTime = DateTime.ParseExact(date, format, null);
return dateTime;
}
It would allow for the extension method to be more easily tested using a mock reader
[TestMethod]
public void Should_GetDateTime_Given_Format() {
//Arrange - using Moq
string expected = "2020-02-22";
string format = "yyyy-MM-dd";
int columnNumber = 0;
var target = Mock.Of<DbDataReader>(_ => _.GetString(columnNumber) == expected);
//Act
var actual = target.GetDateTime(columnNumber, format);
//Assert - using FluentAssertions
actual.ToString(format).Should().Be(expected);
}
And also means that the extension method is reusable on other derived DbDataReader and not just SQLiteDataReader