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); }
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); }
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); }
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); } }
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); } }
public void DeleteNonExistingFile() { IFileRepository repository = new FileRepository(new Logger(), "AA", null); Assert.ThrowsException <FileNotFoundException>(() => repository.DeleteFile(1)); }
public void DeleteFileThrowsOnInvalidFileName() { var repository = new FileRepository(); Assert.Throws <ArgumentNullException>(() => repository.DeleteFile(null)); }
public async Task TryToBreakOutDeleteFile() { var repo = new FileRepository("TestFiles", new FileVerifier()); await Assert.ThrowsAsync <InvalidOperationException>(async() => await repo.DeleteFile("../file.txt")); }
public ActionResult DeleteConfirmed(int id) { repo.DeleteFile(id); return(RedirectToAction("Index")); }
public async Task DeleteFile(string filename) { await _repository.DeleteFile(filename); }