public async Task MoveFile_SamePath() { using var tmp = TempDir.Create(); var file = TorrentFileInfo.Create(Constants.BlockSize, ("file.txt", 123456, Path.Combine(tmp.Path, "orig.txt"))).Single(); File.OpenWrite(file.FullPath).Close(); using var writer = new TestPieceWriter(); using var manager = new DiskManager(new EngineSettings(), Factories.Default, writer); await manager.MoveFileAsync(file, file.FullPath); Assert.IsTrue(File.Exists(file.FullPath)); }
public async Task MoveFile_ConvertsToFullPath() { using var writer = new TestPieceWriter(); using var manager = new DiskManager(new EngineSettings(), Factories.Default, writer); var file = TorrentFileInfo.Create(Constants.BlockSize, 123456).Single(); Assert.IsFalse(File.Exists(file.FullPath)); await manager.MoveFileAsync(file, "NewPath"); Assert.AreEqual(Path.GetFullPath("NewPath"), file.FullPath); Assert.IsFalse(File.Exists(file.FullPath)); }
public async Task MoveFile_TargetDirectoryDoesNotExist() { using var tmp = TempDir.Create(); var file = TorrentFileInfo.Create(Constants.BlockSize, ("file.txt", 123456, Path.Combine(tmp.Path, "orig.txt"))).Single(); File.OpenWrite(file.FullPath).Close(); using var writer = new TestPieceWriter(); using var manager = new DiskManager(new EngineSettings(), Factories.Default, writer); var fullPath = Path.Combine(tmp.Path, "New", "Path", "file.txt"); await manager.MoveFileAsync(file, fullPath); Assert.AreEqual(fullPath, file.FullPath); }
public async Task MoveFiles_Overwrite_SameDir() { using var tmp = TempDir.Create(); var file = TorrentFileInfo.Create(Constants.BlockSize, (Path.Combine("sub_dir", "orig.txt"), 123456, Path.Combine(tmp.Path, "sub_dir", "orig.txt"))).Single(); Directory.CreateDirectory(Path.GetDirectoryName(file.FullPath)); File.OpenWrite(file.FullPath).Close(); using var writer = new TestPieceWriter(); using var manager = new DiskManager(new EngineSettings(), Factories.Default, writer); await manager.MoveFilesAsync(new[] { file }, tmp.Path, true); Assert.AreEqual(Path.Combine(tmp.Path, file.Path), file.FullPath); Assert.IsTrue(File.Exists(file.FullPath)); }