public void CanCreateAndSave() { var name = $"test name: {nameof(CanCreateAndSave)} {DateTimeOffset.UtcNow.Ticks}"; var scan = ModelBuilders.CreateScan(name); using (var db = new NPoco.Database(connection, DatabaseType.SQLite)) { db.Insert(scan); var result = db.SingleById <Scan>(scan.Id); Assert.Equal(name, result.Name); } }
public void CanCreateMultiplesAndSave() { var scanName = $"test scanName: {nameof(CanCreateMultiplesAndSave)} {DateTimeOffset.UtcNow.Ticks}"; var scan = ModelBuilders.CreateScan(scanName); string lastFolderName = null; long lastFileId = 0; string lastFileName = null; using (var db = new NPoco.Database(connection, DatabaseType.SQLite)) { db.Insert(scan); for (var i = 0; i <= 9; i++) { var folder = ModelBuilders.CreateFolderScan($"Folder-{i}-{Guid.NewGuid()}", string.Empty); folder.ScanId = scan.Id; db.Insert(folder); lastFolderName = folder.Name; for (var j = 0; j <= 9; j++) { var file = ModelBuilders.CreateFileScan($"File-{i}-{j}-{Guid.NewGuid()}", string.Empty); file.ScanId = scan.Id; file.ParentFolderId = folder.Id; db.Insert(file); lastFileId = file.Id; lastFileName = file.Name; } } var fileResult = db.SingleById <FileScan>(lastFileId); Assert.Equal(lastFileName, fileResult.Name); var folderResult = db.SingleById <FolderScan>(fileResult.ParentFolderId); Assert.Equal(lastFolderName, folderResult.Name); } }
public void CanGetBackKindUtcFromDatabase() { // Microsoft.Data.Sqlite (as of 2.2.2) has problems storing/retrieving DateTime values as kind UTC // https://system.data.sqlite.org/ -- works fine and returns UTC timestamp // Update: NPoco/System.Data.SQLite seems to have trouble round-tripping UTC time to the database // The fix for this is adding "datetimekind=Utc" to the connetion string // "data source=\"file:mem-073d7ec1-528a-4482-8264-caf718d4fc06?mode=memory&cache=shared\";datetimekind=Utc" var name = $"test message: {nameof(CanGetBackKindUtcFromDatabase)} {DateTimeOffset.UtcNow.Ticks}"; var scan = ModelBuilders.CreateScan(name); scan.ScanFinished = new DateTime(2018, 12, 13, 22, 55, 43, DateTimeKind.Utc); using (var db = new NPoco.Database(connection, DatabaseType.SQLite)) { db.Insert(scan); var result = db.SingleById <Scan>(scan.Id); Assert.Equal(DateTimeKind.Utc, result.ScanFinished?.Kind); Assert.Equal(scan.ScanFinished, result.ScanFinished); } }
public void CanCreateAndSave() { var scanName = $"test scanName: {nameof(CanCreateAndSave)} {DateTimeOffset.UtcNow.Ticks}"; var folderName = $"test folderName: {nameof(CanCreateAndSave)} {DateTimeOffset.UtcNow.Ticks}"; var folderUri = $"test folderUri: {nameof(CanCreateAndSave)} {DateTimeOffset.UtcNow.Ticks}"; var fileName = $"test fileName: {nameof(CanCreateAndSave)} {DateTimeOffset.UtcNow.Ticks}"; var fileUri = $"test fileUri: {nameof(CanCreateAndSave)} {DateTimeOffset.UtcNow.Ticks}"; var scan = ModelBuilders.CreateScan(scanName); var folder = ModelBuilders.CreateFolderScan(folderName, folderUri); var file = ModelBuilders.CreateFileScan(fileName, fileUri); using (var db = new NPoco.Database(connection, DatabaseType.SQLite)) { db.Insert(scan); folder.ScanId = scan.Id; db.Insert(folder); file.ScanId = scan.Id; file.ParentFolderId = folder.Id; db.Insert(file); var result = db.SingleById <FileScan>(file.Id); Assert.Equal(fileName, result.Name); } }