public static Dictionary <string, bool> TestExecutionProxyDownloaders() { Dictionary <string, bool> results = new Dictionary <string, bool>(); string serverHost = "10.141.41.1"; Tonsil.Files.HttpFilePath httpFilePath = new Tonsil.Files.HttpFilePath() { Host = serverHost, Port = 80, Directory = "/somedir/", Filename = "somefile.vbs" }; Tonsil.Files.SmbFilePath smbFilePath = new Tonsil.Files.SmbFilePath() { Host = serverHost, Port = 445, ShareName = "someshare", Directory = @"\somedir\", Filename = "somefile.vbs" }; Tonsil.Files.LocalFilePath localFilePath = new Tonsil.Files.LocalFilePath() { Directory = @"c:\", Filename = "somefile.vbs" }; List <Tonsil.Files.FilePath> filePaths = new List <Tonsil.Files.FilePath>() { httpFilePath, smbFilePath }; Tonsil.Files.File destinationFile = new Tonsil.Files.File() { FileType = Tonsil.Files.FileType.VBScript, FilePath = localFilePath }; Type downloaderParentType = typeof(Tonsil.Processes.Downloaders.Downloader); Assembly assembly = downloaderParentType.Assembly; Type[] types = assembly.GetTypes(); IEnumerable <Type> downloaderSubclasses = types.Where(t => t.IsSubclassOf(downloaderParentType)); Type executionProxyParentType = typeof(Tonsil.Processes.ExecutionProxys.ExecutionProxy); IEnumerable <Type> executionProxySubclasses = types.Where(t => t.IsSubclassOf(executionProxyParentType)); foreach (Type executionProxyType in executionProxySubclasses) { foreach (Type downloaderType in downloaderSubclasses) { foreach (var filePath in filePaths) { Tonsil.Files.File sourceFile = new Tonsil.Files.File() { FilePath = filePath }; Tonsil.Processes.Downloaders.Downloader downloadProcessUnderTest = (Tonsil.Processes.Downloaders.Downloader)Activator.CreateInstance(downloaderType); if (downloadProcessUnderTest.IsValidSource(sourceFile) && downloadProcessUnderTest.IsValidDestination(sourceFile, destinationFile)) { downloadProcessUnderTest.AddDownload(sourceFile, destinationFile); Tonsil.Processes.Process targetProcess = downloadProcessUnderTest; Tonsil.Processes.ExecutionProxys.ExecutionProxy processUnderTest = (Tonsil.Processes.ExecutionProxys.ExecutionProxy)Activator.CreateInstance(executionProxyType); processUnderTest.AddCmdlineExecution(targetProcess); bool result = TestDownloader(processUnderTest, sourceFile, destinationFile); Console.WriteLine(string.Format("{1}: \t{0}", processUnderTest.CmdLine.ToString(), result ? "Pass" : "Fail")); results.Add(processUnderTest.CmdLine.ToString(), result); } } } } return(results); }
public static Dictionary <string, bool> TestExecuters() { Dictionary <string, bool> results = new Dictionary <string, bool>(); string serverHost = "10.141.41.1"; System.IO.File.WriteAllText(@"c:\somefile.vbs", @"CreateObject(""WScript.Shell"").Run(""Notepad.exe"")"); Tonsil.Files.HttpFilePath httpFilePath = new Tonsil.Files.HttpFilePath() { Host = serverHost, Port = 80, Directory = "/somedir/", Filename = "somefile.vbs" }; Tonsil.Files.SmbFilePath smbFilePath = new Tonsil.Files.SmbFilePath() { Host = serverHost, Port = 445, ShareName = "someshare", Directory = @"\somedir\", Filename = "somefile.vbs" }; Tonsil.Files.LocalFilePath localFilePath = new Tonsil.Files.LocalFilePath() { Directory = @"c:\", Filename = "somefile.vbs" }; List <Tonsil.Files.FilePath> filePaths = new List <Tonsil.Files.FilePath>() { httpFilePath, smbFilePath, localFilePath }; Type parentType = typeof(Tonsil.Processes.Executers.Executer); Assembly assembly = parentType.Assembly; Type[] types = assembly.GetTypes(); IEnumerable <Type> subclasses = types.Where(t => t.IsSubclassOf(parentType)); foreach (Type type in subclasses) { foreach (var filePath in filePaths) { Tonsil.Files.File sourceFile = new Tonsil.Files.File() { FilePath = filePath }; var processUnderTest = (Tonsil.Processes.Executers.Executer)Activator.CreateInstance(type); if (processUnderTest.IsValidSource(sourceFile)) { Tonsil.Processes.Process targetProcess = new Notepad(); // The process that sourceFile should spawn processUnderTest.AddFileExecution(sourceFile); bool result = TestExecutionProxy(processUnderTest, targetProcess); Console.WriteLine(string.Format("{1}: \t{0}", processUnderTest.CmdLine.ToString(), result ? "Pass" : "Fail")); results.Add(processUnderTest.CmdLine.ToString(), result); } } } return(results); }