Beispiel #1
0
        public async Task UploadTests()
        {
            var dbName = $"testdb-{GetCurrentMethodName()}-{DateTime.UtcNow.ToString("yyyy-mm-dd_hh-mm-dd-fff")}.db";
            var fsm    = new LiteDbFileStoreManager(dbName);

            var file1 = new FileModel
            {
                Id             = "1",
                Bytes          = File.ReadAllBytes(Path.Combine("Resources", "file.txt")),
                StoredFileName = "file.txt"
            };
            var file2 = new FileModel
            {
                Id             = "2",
                Bytes          = File.ReadAllBytes(Path.Combine("Resources", "file.csv")),
                StoredFileName = "file.csv"
            };

            var files = new[] { file1, file2 };
            var res   = await fsm.Upload(files);

            res.Count().ShouldBe(files.Count());
            for (int i = 0; i < files.Length; i++)
            {
                var c = res.ElementAt(i);
                c.Status.ShouldBe(FileStoreState.Uploaded);
                c.File.ShouldBe(files[i]);
            }
        }
Beispiel #2
0
        public async Task Delete_Tests()
        {
            var dbName = $"testdb-{GetCurrentMethodName()}-{DateTime.UtcNow.ToString("yyyy-mm-dd_hh-mm-dd-fff")}.db";

            var file1 = new FileModel
            {
                Id             = "1",
                Bytes          = File.ReadAllBytes(Path.Combine("Resources", "file.txt")),
                StoredFileName = "file.txt"
            };
            var file2 = new FileModel
            {
                Id             = "2",
                Bytes          = File.ReadAllBytes(Path.Combine("Resources", "file.csv")),
                StoredFileName = "file.csv",
            };
            var files = new[] { file1, file2 };

            using (var db = new LiteDatabase(dbName))
            {
                foreach (var f in files)
                {
                    var stream = new MemoryStream(f.Bytes.ToArray()) as Stream;
                    db.FileStorage.Upload(f.Id, f.StoredFileName, stream);
                }
            }

            var fsm = new LiteDbFileStoreManager(dbName);
            var res = await fsm.Delete(files);

            res.Count().ShouldBe(files.Count());
            for (int i = 0; i < files.Length; i++)
            {
                var c = res.ElementAt(i);
                c.Status.ShouldBe(FileStoreState.Deleted);
                c.File.ShouldBe(files[i]);
            }
        }