예제 #1
0
        public void WriteAndUpdateFileTest()
        {
            IFileRepository repository = new FileRepository(new Logger(), "AA", null);
            var             result     = repository.WriteToFile(1, "abc");

            Assert.IsTrue(result.Success);
            result = repository.UpdateFile(1, "def");
            Assert.IsTrue(result.Success);
            var content = repository.ReadFromFile(1);

            Assert.AreEqual("def", content);
            //cleanup
            repository.DeleteFile(1);
        }
예제 #2
0
        public async Task OpenWriteNoValidate()
        {
            var writeRepoDir = "TestOpenWriteNoValidate";

            Directory.CreateDirectory(writeRepoDir);
            var repo     = new FileRepository(writeRepoDir, new FileVerifier());
            var fileName = "OpenWriteNoValidate.txt";

            using (var stream = await repo.OpenWriteNoValidate(fileName))
            {
                Assert.True(stream.Length == 0, "Opened stream is not empty.");
            }
            Assert.True(await repo.FileExists(fileName));
            await repo.DeleteFile(fileName);

            Directory.Delete(writeRepoDir);
        }
예제 #3
0
        public async Task SaveStream()
        {
            var writeRepoDir = "TestSaveStream";
            var repo         = new FileRepository("TestFiles", new FileVerifier().AddDoc());

            Directory.CreateDirectory(writeRepoDir);
            var writeRepo = new FileRepository(writeRepoDir, new FileVerifier().AddDoc());

            using (var stream = await repo.OpenRead("Doc.doc"))
            {
                var fileName = "TestDoc.doc";
                await writeRepo.WriteFile(fileName, FileVerifierFactory.DocMimeType, stream);

                Assert.True(await writeRepo.FileExists(fileName));
                await writeRepo.DeleteFile(fileName);
            }
            Directory.Delete(writeRepoDir);
        }
예제 #4
0
            public async Task ShouldReturnFalseWhenRequestFailedException()
            {
                var blobClient = new Mock <BlobContainerClient>();

                blobClient.Setup(c => c.DeleteBlobIfExistsAsync(It.IsAny <string>(),
                                                                It.IsAny <DeleteSnapshotsOption>(),
                                                                It.IsAny <BlobRequestConditions>(),
                                                                It.IsAny <CancellationToken>()))
                .ThrowsAsync(new RequestFailedException("failed"));
                var subject = new FileRepository(blobClient.Object);

                using (var token = new CancellationTokenSource())
                {
                    var response = await subject.DeleteFile("test", token.Token);

                    response.Should().Be(false);
                }
            }
예제 #5
0
            public async Task ShouldIndicateResultOfStorageAction(bool fileDeleted)
            {
                var azResponse = new Mock <Response <bool> >();

                azResponse.SetupGet(c => c.Value).Returns(fileDeleted);
                var blobClient = new Mock <BlobContainerClient>();

                blobClient.Setup(c => c.DeleteBlobIfExistsAsync(It.IsAny <string>(),
                                                                It.IsAny <DeleteSnapshotsOption>(),
                                                                It.IsAny <BlobRequestConditions>(),
                                                                It.IsAny <CancellationToken>())).ReturnsAsync(azResponse.Object);
                var subject = new FileRepository(blobClient.Object);

                using (var token = new CancellationTokenSource())
                {
                    var response = await subject.DeleteFile("test", token.Token);

                    response.Should().Be(fileDeleted);
                }
            }
예제 #6
0
        public void DeleteNonExistingFile()
        {
            IFileRepository repository = new FileRepository(new Logger(), "AA", null);

            Assert.ThrowsException <FileNotFoundException>(() => repository.DeleteFile(1));
        }
예제 #7
0
        public void DeleteFileThrowsOnInvalidFileName()
        {
            var repository = new FileRepository();

            Assert.Throws <ArgumentNullException>(() => repository.DeleteFile(null));
        }
예제 #8
0
 public async Task TryToBreakOutDeleteFile()
 {
     var repo = new FileRepository("TestFiles", new FileVerifier());
     await Assert.ThrowsAsync <InvalidOperationException>(async() => await repo.DeleteFile("../file.txt"));
 }
예제 #9
0
        public ActionResult DeleteConfirmed(int id)
        {
            repo.DeleteFile(id);

            return(RedirectToAction("Index"));
        }
예제 #10
0
 public async Task DeleteFile(string filename)
 {
     await _repository.DeleteFile(filename);
 }