public async Task CreateTorrentAsync_TorrentWith2Files_TorrentWith2Files() { var sut = new TorrentFileHelper(); var fileLoc1 = GenerateTempFilePath(); await CreateFile(sut, fileLoc1, 32); var fileLoc2 = GenerateTempFilePath(); await CreateFile(sut, fileLoc2, 64); var innerFiles = new CreateTorrentFileMapping[] { new CreateTorrentFileMapping { FileLocOnDisk = fileLoc1, FileLocInTorrent = "FileA.txt" }, new CreateTorrentFileMapping { FileLocOnDisk = fileLoc2, FileLocInTorrent = "FileB.txt" } }; var torrentName = "TestTorrent2File32kbAnd64kb"; var torrentFileLoc = GenerateTempFilePath(extension: "torent"); var newTorrentFile = CreateNewTorrentFile(innerFiles, torrentName); await CreateTorrentAsyncTestBodyAsync(sut, torrentFileLoc, newTorrentFile); }
private async Task CreateTextFileAsyncTestBodyAsync(int fileSizeInBytes) { var tempFileName = GenerateTempFilePath(); var sut = new TorrentFileHelper(); //Act await sut.CreateTextFileAsync(tempFileName, fileSizeInBytes); //Assert var fi = new FileInfo(tempFileName); fi.Length.Should().Be(fileSizeInBytes); }
private static async Task ReadTorrentAsyncTestBodyAsync(TorrentFileHelper sut, string torrentFileLocation, ExistingTorrentFile expectedTorrent) { //Act var existingTorrent = await sut.ReadTorrentAsync(torrentFileLocation); //Assert existingTorrent.Name.Should().Be(expectedTorrent.Name); existingTorrent.IsPrivate.Should().Be(expectedTorrent.IsPrivate); existingTorrent.TrackerAnnounceUrl.Should().Be(expectedTorrent.TrackerAnnounceUrl); existingTorrent.InnerTorrentFiles.Count().Should().Be(expectedTorrent.InnerTorrentFiles.Count()); foreach (var expectedInnerTorrentFile in expectedTorrent.InnerTorrentFiles) { var existingInnerTorrentFile = existingTorrent.InnerTorrentFiles.Single(f => f.FileLocInTorrent == expectedInnerTorrentFile.FileLocInTorrent); existingInnerTorrentFile.FileSizeInBytes.Should().Be(expectedInnerTorrentFile.FileSizeInBytes); } }
public async Task ReadTorrentAsync_1File_TorrentWith1File() { var sut = new TorrentFileHelper(); var torrentFileLocation = Path.Combine(TestFilesDir, "TorrentWith1File128kb.torent"); var expectedTorrent = new ExistingTorrentFile { IsPrivate = true, Name = "TestTorrent1File128kb", TrackerAnnounceUrl = "http://mytracker.org:2710/announce", InnerTorrentFiles = new InnerTorrentFileInfo[] { new InnerTorrentFileInfo { FileLocInTorrent = "FileA.txt", FileSizeInBytes = 128 * 1024 } } }; await ReadTorrentAsyncTestBodyAsync(sut, torrentFileLocation, expectedTorrent); }
private static async Task CreateTorrentAsyncTestBodyAsync(TorrentFileHelper sut, string torrentFileLoc, NewTorrentFile newTorrentFile) { //Act await sut.CreateTorrentAsync(torrentFileLoc, newTorrentFile); //Assert File.Exists(torrentFileLoc).Should().BeTrue(); var torrentFile = await sut.ReadTorrentAsync(torrentFileLoc); torrentFile.Name.Should().Be(newTorrentFile.Name); torrentFile.IsPrivate.Should().Be(newTorrentFile.IsPrivate); torrentFile.TrackerAnnounceUrl.Should().Be(newTorrentFile.TrackerAnnounceUrls.SingleOrDefault()); torrentFile.InnerTorrentFiles.Count().Should().Be(newTorrentFile.FileMappings.Count()); foreach (var fileMapping in newTorrentFile.FileMappings) { var innerTorrentFile = torrentFile.InnerTorrentFiles.Single(f => f.FileLocInTorrent == fileMapping.FileLocInTorrent); var actualSizeInbytes = new FileInfo(fileMapping.FileLocOnDisk).Length; innerTorrentFile.FileSizeInBytes.Should().Be(actualSizeInbytes); } }
private static async Task CreateFile(TorrentFileHelper sut, string fileLoc, int sizeInBytes) { var fileSize = sizeInBytes * 1024; await sut.CreateTextFileAsync(fileLoc, fileSize); }