public void RefuseExtension() { CleanTestFilesOutput(); Race race = new Race(ArgsBat); race.ParseUpload(); Assert.AreEqual(".bat", race.CurrentRaceData.FileExtension, "FileExtension"); Assert.AreEqual("file_bat.bat", race.CurrentRaceData.FileName, "FileName"); Assert.AreEqual("Zip", race.CurrentRaceData.DirectoryName, "DirectoryName"); race.Process(); Assert.IsFalse(race.IsValid); }
public void ZipRace() { CleanTestFilesOutput(); Race race = new Race(ArgsCorrectZipFile1); race.ParseUpload(); race.Process(); Assert.IsTrue(race.IsValid); FileInfo fileInfo = new FileInfo(Misc.PathCombine(race.CurrentRaceData.DirectoryPath, Config.FileNameRace)); const int fileSize = 24683; using (FileStream stream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.None)) { using (BinaryReader reader = new BinaryReader(stream)) { stream.Seek(0, SeekOrigin.Begin); Assert.AreEqual(5, reader.ReadInt32(), "Total files count"); stream.Seek(256 * 5, SeekOrigin.Begin); Assert.AreEqual("file-000.zip", reader.ReadString(), "FileName"); Assert.AreEqual("00000000", reader.ReadString(), "CRC32"); Assert.AreEqual(true, reader.ReadBoolean(), "File was uploaded"); Assert.AreEqual((UInt64)fileSize, reader.ReadUInt64(), "FileSize"); } } Assert.AreEqual((UInt64)fileSize, race.TotalBytesUploaded, "TotalBytesUploaded"); Assert.AreEqual(5, race.TotalFilesExpected, "TotalFilesExpected"); Assert.AreEqual(1, race.TotalFilesUploaded, "TotalFilesUploaded"); race = new Race(ArgsCorrectZipFile2); race.ParseUpload(); race.Process(); fileInfo = new FileInfo(Misc.PathCombine(race.CurrentRaceData.DirectoryPath, Config.FileNameRace)); using (FileStream stream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.None)) { using (BinaryReader reader = new BinaryReader(stream)) { stream.Seek(0, SeekOrigin.Begin); Assert.AreEqual(5, reader.ReadInt32(), "Total files count"); stream.Seek(256 * 4, SeekOrigin.Begin); Assert.AreEqual("file-001.zip", reader.ReadString(), "FileName"); Assert.AreEqual("00000000", reader.ReadString(), "CRC32"); Assert.AreEqual(true, reader.ReadBoolean(), "File was uploaded"); Assert.AreEqual((UInt64)fileSize, reader.ReadUInt64(), "FileSize"); } } Assert.AreEqual((UInt64)fileSize * 2, race.TotalBytesUploaded, "TotalBytesUploaded"); Assert.AreEqual(5, race.TotalFilesExpected, "TotalFilesExpected"); Assert.AreEqual(2, race.TotalFilesUploaded, "TotalFilesUploaded"); race = new Race(ArgsCorrectZipFile3); race.ParseUpload(); race.Process(); fileInfo = new FileInfo(Misc.PathCombine(race.CurrentRaceData.DirectoryPath, Config.FileNameRace)); using (FileStream stream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.None)) { using (BinaryReader reader = new BinaryReader(stream)) { stream.Seek(0, SeekOrigin.Begin); Assert.AreEqual(5, reader.ReadInt32(), "Total files count"); stream.Seek(256 * 3, SeekOrigin.Begin); Assert.AreEqual("file-002.zip", reader.ReadString(), "FileName"); Assert.AreEqual("00000000", reader.ReadString(), "CRC32"); Assert.AreEqual(true, reader.ReadBoolean(), "File was uploaded"); Assert.AreEqual((UInt64)fileSize, reader.ReadUInt64(), "FileSize"); } } Assert.AreEqual((UInt64)fileSize * 3, race.TotalBytesUploaded, "TotalBytesUploaded"); Assert.AreEqual(5, race.TotalFilesExpected, "TotalFilesExpected"); Assert.AreEqual(3, race.TotalFilesUploaded, "TotalFilesUploaded"); race = new Race(ArgsCorrectZipFile4); race.ParseUpload(); race.Process(); fileInfo = new FileInfo(Misc.PathCombine(race.CurrentRaceData.DirectoryPath, Config.FileNameRace)); using (FileStream stream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.None)) { using (BinaryReader reader = new BinaryReader(stream)) { stream.Seek(0, SeekOrigin.Begin); Assert.AreEqual(5, reader.ReadInt32(), "Total files count"); stream.Seek(256 * 2, SeekOrigin.Begin); Assert.AreEqual("file-003.zip", reader.ReadString(), "FileName"); Assert.AreEqual("00000000", reader.ReadString(), "CRC32"); Assert.AreEqual(true, reader.ReadBoolean(), "File was uploaded"); Assert.AreEqual((UInt64)fileSize, reader.ReadUInt64(), "FileSize"); } } Assert.AreEqual((UInt64)fileSize * 4, race.TotalBytesUploaded, "TotalBytesUploaded"); Assert.AreEqual(5, race.TotalFilesExpected, "TotalFilesExpected"); Assert.AreEqual(4, race.TotalFilesUploaded, "TotalFilesUploaded"); race = new Race(ArgsCorrectZipFile5); race.ParseUpload(); race.Process(); fileInfo = new FileInfo(Misc.PathCombine(race.CurrentRaceData.DirectoryPath, Config.FileNameRace)); using (FileStream stream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.None)) { using (BinaryReader reader = new BinaryReader(stream)) { stream.Seek(0, SeekOrigin.Begin); Assert.AreEqual(5, reader.ReadInt32(), "Total files count"); stream.Seek(256 * 1, SeekOrigin.Begin); Assert.AreEqual("file-004.zip", reader.ReadString(), "FileName"); Assert.AreEqual("00000000", reader.ReadString(), "CRC32"); Assert.AreEqual(true, reader.ReadBoolean(), "File was uploaded"); Assert.AreEqual((UInt64)fileSize, reader.ReadUInt64(), "FileSize"); } } Assert.AreEqual((UInt64)fileSize * 5, race.TotalBytesUploaded, "TotalBytesUploaded"); Assert.AreEqual(5, race.TotalFilesExpected, "TotalFilesExpected"); Assert.AreEqual(5, race.TotalFilesUploaded, "TotalFilesUploaded"); }
public void RaceRar() { CleanTestFilesOutput (); UploadSfvFile (); Race race = new Race (ArgsRarPart1); race.ParseUpload (); race.Process (); FileInfo fileInfo = new FileInfo(Misc.PathCombine(race.CurrentRaceData.DirectoryPath, Config.FileNameRace)); using (FileStream stream = new FileStream (fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.None)) { using (BinaryReader reader = new BinaryReader (stream)) { stream.Seek (0, SeekOrigin.Begin); Assert.AreEqual (4, reader.ReadInt32 (), "Total files count"); stream.Seek (256 * 1, SeekOrigin.Begin); Assert.AreEqual ("infected.part1.rar", reader.ReadString (), "FileName"); Assert.AreEqual ("2e04944c", reader.ReadString (), "CRC32"); Assert.AreEqual (true, reader.ReadBoolean (), "File was uploaded"); Assert.AreEqual ((UInt64) 5000, reader.ReadUInt64 (), "FileSize"); } } Assert.AreEqual((UInt64)5000, race.TotalBytesUploaded, "TotalBytesUploaded"); Assert.AreEqual(4, race.TotalFilesExpected, "TotalFilesExpected"); Assert.AreEqual(1, race.TotalFilesUploaded, "TotalFilesUploaded"); race = new Race(ArgsRarPart2); race.ParseUpload(); race.Process(); fileInfo = new FileInfo(Misc.PathCombine(race.CurrentRaceData.DirectoryPath, Config.FileNameRace)); using (FileStream stream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.None)) { using (BinaryReader reader = new BinaryReader(stream)) { stream.Seek(0, SeekOrigin.Begin); Assert.AreEqual(4, reader.ReadInt32(), "Total files count"); stream.Seek(256 * 2, SeekOrigin.Begin); Assert.AreEqual("infected.part2.rar", reader.ReadString(), "FileName"); Assert.AreEqual("1c7c24a5", reader.ReadString(), "CRC32"); Assert.AreEqual(true, reader.ReadBoolean(), "File was uploaded"); Assert.AreEqual((UInt64)5000, reader.ReadUInt64(), "FileSize"); } } Assert.AreEqual((UInt64)5000 * 2, race.TotalBytesUploaded, "TotalBytesUploaded"); Assert.AreEqual(4, race.TotalFilesExpected, "TotalFilesExpected"); Assert.AreEqual(2, race.TotalFilesUploaded, "TotalFilesUploaded"); race = new Race(ArgsRarPart3); race.ParseUpload(); race.Process(); fileInfo = new FileInfo(Misc.PathCombine(race.CurrentRaceData.DirectoryPath, Config.FileNameRace)); using (FileStream stream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.None)) { using (BinaryReader reader = new BinaryReader(stream)) { stream.Seek(0, SeekOrigin.Begin); Assert.AreEqual(4, reader.ReadInt32(), "Total files count"); stream.Seek(256 * 3, SeekOrigin.Begin); Assert.AreEqual("infected.part3.rar", reader.ReadString(), "FileName"); Assert.AreEqual("d5d617e3", reader.ReadString(), "CRC32"); Assert.AreEqual(true, reader.ReadBoolean(), "File was uploaded"); Assert.AreEqual((UInt64)5000, reader.ReadUInt64(), "FileSize"); } } Assert.AreEqual((UInt64)5000 * 3, race.TotalBytesUploaded, "TotalBytesUploaded"); Assert.AreEqual(4, race.TotalFilesExpected, "TotalFilesExpected"); Assert.AreEqual(3, race.TotalFilesUploaded, "TotalFilesUploaded"); race = new Race(ArgsRarPart4); race.ParseUpload(); race.Process(); fileInfo = new FileInfo(Misc.PathCombine(race.CurrentRaceData.DirectoryPath, Config.FileNameRace)); using (FileStream stream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.None)) { using (BinaryReader reader = new BinaryReader(stream)) { stream.Seek(0, SeekOrigin.Begin); Assert.AreEqual(4, reader.ReadInt32(), "Total files count"); stream.Seek(256 * 4, SeekOrigin.Begin); Assert.AreEqual("infected.part4.rar", reader.ReadString(), "FileName"); Assert.AreEqual("0edb20ea", reader.ReadString(), "CRC32"); Assert.AreEqual(true, reader.ReadBoolean(), "File was uploaded"); Assert.AreEqual((UInt64)2916, reader.ReadUInt64(), "FileSize"); } } Assert.AreEqual((UInt64)5000 * 3 + 2916, race.TotalBytesUploaded, "TotalBytesUploaded"); Assert.AreEqual(4, race.TotalFilesExpected, "TotalFilesExpected"); Assert.AreEqual(4, race.TotalFilesUploaded, "TotalFilesUploaded"); }
public void ZipRaceNoDiz() { CleanTestFilesOutput(); Race race = new Race(ArgsZipFile1); race.ParseUpload(); race.Process(); Assert.IsFalse(race.IsValid); }
public void Race() { CleanTestFilesOutput(); UploadSfvFileMp3(); Race race = new Race(ArgsMp3File1); race.ParseUpload(); race.Process(); Output output = new Output(race); FileInfo fileInfo = new FileInfo(Misc.PathCombine(race.CurrentRaceData.DirectoryPath, Config.FileNameRace)); using (FileStream stream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.None)) { using (BinaryReader reader = new BinaryReader(stream)) { stream.Seek(0, SeekOrigin.Begin); Assert.AreEqual(4, reader.ReadInt32(), "Total files count"); stream.Seek(256 * 1, SeekOrigin.Begin); Assert.AreEqual("01-jozek.Pepek-2009-asd-Ind.mp3", reader.ReadString(), "FileName"); Assert.AreEqual("2e04944c", reader.ReadString(), "CRC32"); Assert.AreEqual(true, reader.ReadBoolean(), "File was uploaded"); Assert.AreEqual((UInt64) 5000, reader.ReadUInt64(), "FileSize"); } } Assert.AreEqual((UInt64) 5000, race.TotalBytesUploaded, "TotalBytesUploaded"); Assert.AreEqual(4, race.TotalFilesExpected, "TotalFilesExpected"); Assert.AreEqual(1, race.TotalFilesUploaded, "TotalFilesUploaded"); Assert.IsFalse( File.Exists(@"..\..\TestFiles\Mp3\01-jozek.Pepek-2009-asd-Ind.mp3" + Config.FileExtensionMissing), "01-jozek.Pepek-2009-asd-Ind.mp3" + Config.FileExtensionMissing); Assert.IsTrue( Directory.Exists(Misc.PathCombine(race.CurrentRaceData.DirectoryParent, output.Format(Config.TagIncompleteLink))), "Symlink does not exist!"); race = new Race(ArgsMp3File2); race.ParseUpload(); race.Process(); output = new Output(race); Assert.IsFalse( File.Exists(@"..\..\TestFiles\Mp3\02-jozek.Pepek-2009-asd-Ind.mp3" + Config.FileExtensionMissing), "02-jozek.Pepek-2009-asd-Ind.mp3" + Config.FileExtensionMissing); Assert.IsTrue( Directory.Exists(Misc.PathCombine(race.CurrentRaceData.DirectoryParent, output.Format(Config.TagIncompleteLink))), "Symlink does not exist!"); race = new Race(ArgsMp3File3); race.ParseUpload(); race.Process(); output = new Output(race); Assert.IsFalse( File.Exists(@"..\..\TestFiles\Mp3\03-jozek.Pepek-2009-asd-Ind(2).mp3" + Config.FileExtensionMissing), "03-jozek.Pepek-2009-asd-Ind(2).mp3" + Config.FileExtensionMissing); Assert.IsTrue( Directory.Exists(Misc.PathCombine(race.CurrentRaceData.DirectoryParent, output.Format(Config.TagIncompleteLink))), "Symlink does not exist!"); race = new Race(ArgsMp3File4); race.ParseUpload(); race.Process(); output = new Output(race); Assert.AreEqual(4, race.TotalFilesExpected, "TotalFilesExpected"); Assert.AreEqual(4, race.TotalFilesUploaded, "TotalFilesUploaded"); Assert.IsFalse( File.Exists(@"..\..\TestFiles\Mp3\04-jozek.Pepek-2009-asd-Ind(3).mp3" + Config.FileExtensionMissing), "04-jozek.Pepek-2009-asd-Ind(3).mp3" + Config.FileExtensionMissing); Assert.IsFalse( Directory.Exists(Misc.PathCombine(race.CurrentRaceData.DirectoryParent, output.Format(Config.TagIncompleteLink))), "Symlink not deleted!"); }
protected Race UploadSfvFileMp3() { Race race = new Race(ArgsSfvMp3); race.ParseUpload(); Assert.AreEqual(".sfv", race.CurrentRaceData.FileExtension, "FileExtension"); Assert.AreEqual("jozek.Pepek-2009-asd-Ind.sfv", race.CurrentRaceData.FileName, "FileName"); //Assert.AreEqual(554, race.CurrentRaceData.FileSize, "FileSize"); Assert.AreEqual("Mp3", race.CurrentRaceData.DirectoryName, "DirectoryName"); race.Process(); return race; }
protected Race UploadSfvFile() { Race race = new Race(ArgsSfv); race.ParseUpload(); Assert.AreEqual(".sfv", race.CurrentRaceData.FileExtension, "FileExtension"); Assert.AreEqual("infected.sfv", race.CurrentRaceData.FileName, "FileName"); Assert.AreEqual(432, race.CurrentRaceData.FileSize, "FileSize"); Assert.AreEqual("Rar", race.CurrentRaceData.DirectoryName, "DirectoryName"); race.Process(); return race; }
protected Race UploadNfoFile02() { Race race = new Race(ArgsNfo02); race.ParseUpload(); Assert.AreEqual(".nfo", race.CurrentRaceData.FileExtension, "FileExtension"); Assert.AreEqual("Movie02.nfo", race.CurrentRaceData.FileName, "FileName"); Assert.AreEqual("Nfo", race.CurrentRaceData.DirectoryName, "DirectoryName"); race.Process(); return race; }
protected Race UploadDizFile() { Race race = new Race(ArgsDiz); race.ParseUpload(); Assert.AreEqual(".diz", race.CurrentRaceData.FileExtension, "FileExtension"); Assert.AreEqual("file_id.diz", race.CurrentRaceData.FileName, "FileName"); Assert.AreEqual(350, race.CurrentRaceData.FileSize, "FileSize"); Assert.AreEqual("Zip", race.CurrentRaceData.DirectoryName, "DirectoryName"); race.Process(); return race; }