Ejemplo n.º 1
0
        public void CanCreateAndSave()
        {
            var scanName = $"test scanName: {nameof(CanCreateAndSave)} {DateTimeOffset.UtcNow.Ticks}";
            var name     = $"test name: {nameof(CanCreateAndSave)} {DateTimeOffset.UtcNow.Ticks}";
            var uri      = $"test URI: {nameof(CanCreateAndSave)} {DateTimeOffset.UtcNow.Ticks}";

            var scan = ModelBuilders.CreateScan(scanName);
            var item = ModelBuilders.CreateFolderScan(name, uri);

            using (var db = new NPoco.Database(connection, DatabaseType.SQLite))
            {
                db.Insert(scan);
                item.ScanId = scan.Id;
                db.Insert(item);
                var result = db.SingleById <FolderScan>(item.Id);
                Assert.Equal(name, result.Name);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }