public async Task ReadsIntFromCorrectColumn() { await using var target = new TxtDatabase("Data"); var result = target.Execute("sample", async reader => new { Id = await reader.Get <int>(0).ConfigureAwait(false) }); await foreach (var item in result) { Assert.AreEqual(42, item.Id); } }
public async Task ReadsCorrectFileWithParameters() { await using var target = new TxtDatabase("Data"); var result = target.Execute("sample", async reader => new { Date = await reader.Get <DateTime>(1).ConfigureAwait(false) }, null, new KeyValuePair <string, object>("test", "value")); await foreach (var item in result) { var expected = new DateTime(2019, 12, 23, 22, 44, 33); Assert.AreEqual(expected, item.Date); } }
public async Task ReadsDateTimeFromCorrectColumn() { await using var target = new TxtDatabase("Data"); var result = target.Execute("sample", async reader => new { Date = await reader.Get <DateTime>(1).ConfigureAwait(false) }); await foreach (var item in result) { var expected = new DateTime(2020, 12, 23, 22, 44, 33); Assert.AreEqual(expected, item.Date); } }
public async Task MapsSampleType() { await using var target = new TxtDatabase("Data"); var result = target.Execute("sample", FileSystemTests.Map.To <Sample>); await foreach (var item in result) { Assert.AreEqual(42, item.Id); var expected = new DateTime(2020, 12, 23, 22, 44, 33); Assert.AreEqual(expected, item.Date); } }
public async Task ReadsSecondResult() { await using var target = new TxtDatabase("Data"); var result = target.Execute( "sample", async reader => { await reader.NextResult().ConfigureAwait(false); return(new { Date = await reader.Get <DateTime>(1).ConfigureAwait(false) }); }); await foreach (var item in result) { var expected = new DateTime(2018, 12, 23, 22, 44, 33); Assert.AreEqual(expected, item.Date); } }
public async Task LogsCorrectly() { var logEntries = new List <string>(); void LogMethod(LogCategories categories, LogLevel level, LogScope scope, string message) => logEntries.Add(message); var target = new TxtDatabase("Data"); await using var log = LogScope.Create("db", LogMethod); logEntries.Clear(); var result = target.Execute("sample", async reader => new { Date = await reader.Get <DateTime>(1).ConfigureAwait(false) }, log); await foreach (var item in result) { var expected = new DateTime(2019, 12, 23, 22, 44, 33); Assert.AreEqual("Method Execute - scope value: - Data: {\"sproc\":\"sample\",\"parameters\":[]}", logEntries[1]); } }