예제 #1
0
        public void WatchProcessNotepadTest()
        {
            IWatcher watcher = new ProcessWatcher()
            {
                Id             = PluginUtilities.GetUniqueId(),
                LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(nameof(ProcessWatcher)),
                ProcessName    = "notepad"
            };

            var watcherResult = watcher.Watch();

            Assert.IsNotNull(watcherResult);
            Assert.IsFalse(watcherResult.Result);

            var process = System.Diagnostics.Process.Start("notepad");

            Assert.IsNotNull(process);
            Thread.Sleep(1000);

            watcherResult = watcher.Watch();
            Assert.IsNotNull(watcherResult);
            Assert.IsTrue(watcherResult.Result);
            Assert.IsTrue(watcherResult.WatchingArguments.HasArgument(ProcessWatcherResultArgs.ProcessName));
            Assert.IsTrue(watcherResult.WatchingArguments.HasArgument(ProcessWatcherResultArgs.ProcessId));
            Assert.AreEqual(process.ProcessName, watcherResult.WatchingArguments.GetValue <string>(ProcessWatcherResultArgs.ProcessName));
            Assert.AreEqual(process.Id, watcherResult.WatchingArguments.GetValue <int>(ProcessWatcherResultArgs.ProcessId));

            process.Kill();
        }
예제 #2
0
        public void WatchForFilesByPatternTest()
        {
            string     remoteWorkingDir = "/test";
            FtpWatcher watcher          = new FtpWatcher
            {
                Id               = PluginUtilities.GetUniqueId(),
                LoggingService   = ServicesContainer.ServicesProvider.GetLoggingService(nameof(FtpWatcher)),
                Host             = FtpTestCredentials.Host,
                Username         = FtpTestCredentials.User,
                Password         = FtpTestCredentials.Password,
                Port             = FtpTestCredentials.Port,
                RemoteWorkingDir = remoteWorkingDir,
                SelectFiles      = true
            };

            watcher.SearchPattern = "prefix*.pat";

            var localWriteDir     = Path.Combine(Environment.ExpandEnvironmentVariables(LocalWorkingDir), remoteWorkingDir.Trim('/'));
            var fileNamePath      = CreateTestFile(localWriteDir, "prefix", "pat");
            var otherFileNamePath = CreateTestFile(localWriteDir);
            var watcherResult     = watcher.Watch();

            Assert.IsNotNull(watcherResult);
            Assert.AreEqual(true, watcherResult.Result);
            Assert.IsNotNull(watcherResult.WatchingArguments);
            Assert.IsTrue(watcherResult.WatchingArguments.HasArgument(FtpWatcherResultArgs.RemoteFilesCollection));
            Assert.IsTrue(watcherResult.WatchingArguments.GetValue <List <string> >(FtpWatcherResultArgs.RemoteFilesCollection).Any());
            Assert.AreEqual(1, watcherResult.WatchingArguments.GetValue <List <string> >(FtpWatcherResultArgs.RemoteFilesCollection).Count);

            var watchedFile = watcherResult.WatchingArguments.GetValue <List <string> >(FtpWatcherResultArgs
                                                                                        .RemoteFilesCollection).Single();

            Assert.AreEqual(UriHelper.BuildPath("/", remoteWorkingDir, Path.GetFileName(fileNamePath)), watchedFile);
        }
예제 #3
0
        public void DeleteFilesTest()
        {
            var             localWriteDir   = Path.GetDirectoryName(Environment.ExpandEnvironmentVariables(LocalWorkingDir));
            FtpDeleteAction ftpDeleteAction = new FtpDeleteAction()
            {
                Id             = PluginUtilities.GetUniqueId(),
                LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(nameof(FtpDownloadAction))
            };

            ftpDeleteAction.Host             = FtpTestCredentials.Host;
            ftpDeleteAction.Username         = FtpTestCredentials.User;
            ftpDeleteAction.Password         = FtpTestCredentials.Password;
            ftpDeleteAction.Port             = FtpTestCredentials.Port;
            ftpDeleteAction.RemoteWorkingDir = "/";

            var fileNamePath = CreateTestFile(localWriteDir);

            var actionResult = ftpDeleteAction.Execute(ArgumentCollection.New()
                                                       .WithArgument(FtpDownloadActionExecutionArgs.RemoteFilesCollection, new List <string>()
            {
                Path.GetFileName(fileNamePath)
            })
                                                       );

            Assert.IsNotNull(actionResult);
            Assert.IsTrue(actionResult.Result);
        }
예제 #4
0
        public void KillProcessByNameFromExecutionArgsTest()
        {
            var processId = StartNotepad();
            Assert.AreNotEqual(0, processId);
            Console.WriteLine($"Created Process with ID {processId}");
            Thread.Sleep(1000);
            KillProcessByNameAction action = new KillProcessByNameAction()
            {
                Id = PluginUtilities.GetUniqueId(),
                LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(nameof(KillProcessByNameAction)),
            };

            var actionResult = action.Execute(ArgumentCollection.New()
                .WithArgument(KillProcessByNameActionExecutionArgs.ProcessName, "notepad")
            );
            Assert.IsNotNull(actionResult);
            Assert.IsTrue(actionResult.Result);
            Assert.IsTrue(
                actionResult.AdditionalInformation.HasArgument(KillProcessActionResultArgs
                    .ProcessesKilledSuccessfully));
            Assert.AreEqual(1,
                actionResult.AdditionalInformation
                    .GetValue<List<int>>(KillProcessActionResultArgs.ProcessesKilledSuccessfully).Count);
            Assert.AreEqual(processId,
                actionResult.AdditionalInformation
                    .GetValue<List<int>>(KillProcessActionResultArgs.ProcessesKilledSuccessfully).Single());
            Thread.Sleep(2000);
            actionResult = action.Execute(ArgumentCollection.New()
                .WithArgument(KillProcessByNameActionExecutionArgs.ProcessName, "notepad")
            );
            Assert.IsNotNull(actionResult);
            Assert.IsFalse(actionResult.Result);
        }
예제 #5
0
        public void DownloadFileFromWorkingDirAndRenameTest()
        {
            var localWriteDir = Environment.ExpandEnvironmentVariables(LocalWorkingDir);
            FtpDownloadAction ftpDownloadAction = new FtpDownloadAction
            {
                Id               = PluginUtilities.GetUniqueId(),
                LoggingService   = ServicesContainer.ServicesProvider.GetLoggingService(nameof(FtpDownloadAction)),
                Host             = FtpTestCredentials.Host,
                Username         = FtpTestCredentials.User,
                Password         = FtpTestCredentials.Password,
                Port             = FtpTestCredentials.Port,
                DirectoryPath    = LocalDownloadDir,
                RemoteWorkingDir = "test"
            };

            ftpDownloadAction.RenameDownloaded        = true;
            ftpDownloadAction.RenameDownloadedNewName = "ROUTINDO_";
            var fileNamePath = CreateTestFile(localWriteDir);

            var actionResult = ftpDownloadAction.Execute(ArgumentCollection.New()
                                                         .WithArgument(FtpDownloadActionExecutionArgs.RemoteFilesCollection, new List <string>()
            {
                Path.GetFileName(fileNamePath)
            })
                                                         );

            Assert.IsNotNull(actionResult);
            Assert.IsTrue(actionResult.Result);
        }
예제 #6
0
        public void MoveFileFailsWhenUsedByAnotherProcess()
        {
            var destinationPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            var moveFileAction  = new MoveFileAction()
            {
                Id = PluginUtilities.GetUniqueId(),
                DestinationDirectory = destinationPath
            };
            var sourcePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());


            var createdFileStream = File.Create(sourcePath);

            Assert.IsTrue(File.Exists(sourcePath));
            var args   = new ArgumentCollection((MoveFileActionExecutionArgs.SourceFilePaths, sourcePath));
            var result = moveFileAction.Execute(args);

            Assert.IsNotNull(result);
            Assert.IsFalse(result.Result);

            Assert.IsTrue(File.Exists(sourcePath));
            createdFileStream.Close();

            // Cleanup
            File.Delete(sourcePath);
            Assert.IsFalse(File.Exists(sourcePath));
        }
예제 #7
0
        public void SendSampleFileTest()
        {
            FtpUploadAction action = new FtpUploadAction()
            {
                Id                          = PluginUtilities.GetUniqueId(),
                LoggingService              = ServicesContainer.ServicesProvider.GetLoggingService(nameof(FtpUploadAction)),
                Host                        = FtpTestCredentials.Host,
                Username                    = FtpTestCredentials.User,
                Password                    = FtpTestCredentials.Password,
                Port                        = FtpTestCredentials.Port,
                DestinationFolderPath       = "Data",
                DestinationFileName         = "renamed.txt",
                UseRemoteTemporaryExtension = true,
                RemoteTemporaryExtension    = "remote",
                UseLocalTemporaryExtension  = true,
                LocalTemporaryExtension     = "local",
                Overwrite                   = true,
                CreateRemoteDirectory       = true
            };

            string sourceFileName = Path.Combine(Path.GetTempPath(), "test.txt");

            File.WriteAllText(sourceFileName, "Hello world! This is a remote message!");

            var result = action.Execute(ArgumentCollection.New()
                                        .WithArgument(FtpUploadActionExecutionArgs.SourceFilesCollection, new List <string> {
                sourceFileName
            }));

            Console.WriteLine(result.AttachedException);
            Assert.IsTrue(result.Result);
            File.Delete(sourceFileName);
        }
예제 #8
0
        public void MoveFileTestSuccess()
        {
            var destinationPath = Path.Combine(Path.GetTempPath());
            var moveFileAction  = new MoveFileAction()
            {
                Id = PluginUtilities.GetUniqueId(),
                DestinationDirectory = destinationPath,
                DestinationPrefix    = "RENAMED"
            };
            var sourcePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            using (var file = File.Create(sourcePath))
            {
            }

            Assert.IsTrue(File.Exists(sourcePath));
            Assert.IsFalse(File.Exists(destinationPath));
            var args = new ArgumentCollection((MoveFileActionExecutionArgs.SourceFilePaths, new List <string>()
            {
                sourcePath
            }));

            var result = moveFileAction.Execute(args);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Result);
            Assert.IsFalse(File.Exists(sourcePath));
            destinationPath = Path.Combine(destinationPath, $"RENAMED{Path.GetFileName(sourcePath)}");
            Assert.IsTrue(File.Exists(destinationPath));

            // CleanUp
            File.Delete(destinationPath);
        }
예제 #9
0
        public void MoveFileFailsWhenDestinationFileAlreadyExist()
        {
            var destinationPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            var moveFileAction  = new MoveFileAction()
            {
                Id = PluginUtilities.GetUniqueId(),
                DestinationDirectory = destinationPath
            };
            var filePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            using (var sourceFile = File.Create(filePath))
            {
            }

            using (var destinationFile = File.Create(destinationPath))
            {
            }

            var args = new ArgumentCollection((MoveFileActionExecutionArgs.SourceFilePaths, filePath)
                                              );

            var result = moveFileAction.Execute(args);

            Assert.IsNotNull(result);
            Assert.IsFalse(result.Result);

            // Clean up
            File.Delete(filePath);
            File.Delete(destinationPath);
        }
예제 #10
0
        public void CreateZipOnSameExistingOptionTest()
        {
            var     outputDirectory = Path.GetTempPath();
            IAction action          = new ZipDirectoryAction()
            {
                EraseOutputIfExists = true,
                UseLocationAsOutput = true,
                Id             = PluginUtilities.GetUniqueId(),
                LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(null)
            };

            var testDir = Path.Combine(Path.GetTempPath(), "TEMPO_TEST");

            if (!Directory.Exists(testDir))
            {
                Directory.CreateDirectory(testDir);
            }

            File.WriteAllText(Path.Combine(outputDirectory, "TEMPO_TEST.zip"), "");

            var actionResult = action.Execute(ArgumentCollection.New()
                                              .WithArgument(ZipDirectoryActionExecutionArgs.Directory, testDir));

            Assert.IsNotNull(actionResult);
            Assert.IsTrue(actionResult.Result);
        }
예제 #11
0
        public void WatchForFilesTest()
        {
            string     remoteWorkingDir = "/";
            FtpWatcher watcher          = new FtpWatcher
            {
                Id             = PluginUtilities.GetUniqueId(),
                LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(nameof(FtpWatcher)),
                Host           = FtpTestCredentials.Host,
                Username       = FtpTestCredentials.User,
                Password       = FtpTestCredentials.Password,
                SelectFiles    = true
            };


            var localWriteDir = Environment.ExpandEnvironmentVariables(LocalWorkingDir);
            var fileNamePath  = CreateTestFile(localWriteDir);
            var watcherResult = watcher.Watch();

            Assert.IsNotNull(watcherResult);
            Assert.AreEqual(true, watcherResult.Result);
            Assert.IsNotNull(watcherResult.WatchingArguments);
            Assert.IsTrue(watcherResult.WatchingArguments.HasArgument(FtpWatcherResultArgs.RemoteFilesCollection));
            Assert.IsTrue(watcherResult.WatchingArguments.GetValue <List <string> >(FtpWatcherResultArgs.RemoteFilesCollection).Any());
            Assert.AreEqual(1, watcherResult.WatchingArguments.GetValue <List <string> >(FtpWatcherResultArgs.RemoteFilesCollection).Count);

            var watchedFile = watcherResult.WatchingArguments.GetValue <List <string> >(FtpWatcherResultArgs
                                                                                        .RemoteFilesCollection).Single();

            Assert.AreEqual(remoteWorkingDir + Path.GetFileName(fileNamePath), watchedFile);
        }
예제 #12
0
        public void GetUniqueIdTest()
        {
            var uniqueId          = PluginUtilities.GetUniqueId();
            var upperCaseUniqueId = uniqueId.ToUpper();

            Assert.IsFalse(string.IsNullOrWhiteSpace(uniqueId));
            // Assert unique Id is generated in upper cases
            Assert.AreEqual(uniqueId, upperCaseUniqueId);
        }
예제 #13
0
        public void MoveFileFailsWhenArgumentsNull()
        {
            var moveFileAction = new MoveFileAction()
            {
                Id = PluginUtilities.GetUniqueId()
            };
            var result = moveFileAction.Execute(null);

            Assert.IsNotNull(result);
            Assert.IsFalse(result.Result);
        }
예제 #14
0
        public void MoveFileFailsWhenMissingArgumentDestinationPath()
        {
            var moveFileAction = new MoveFileAction()
            {
                Id = PluginUtilities.GetUniqueId()
            };
            var args   = new ArgumentCollection((MoveFileActionExecutionArgs.SourceFilePaths, ""));
            var result = moveFileAction.Execute(args);

            Assert.IsNotNull(result);
            Assert.IsFalse(result.Result);
        }
예제 #15
0
        public void MoveFileFailsWhenMissingArgumentSourcePath()
        {
            var moveFileAction = new MoveFileAction()
            {
                Id = PluginUtilities.GetUniqueId(),
                DestinationDirectory = null
            };
            var result = moveFileAction.Execute(null);

            Assert.IsNotNull(result);
            Assert.IsFalse(result.Result);
        }
예제 #16
0
        public void CreateArgumentMapperInfoTest()
        {
            var    id                = PluginUtilities.GetUniqueId();
            string name              = "ComponentName";
            string description       = "This is Component description";
            var    componentInstance = RoutindoArgumentsMapperInfo.Create <ArgumentMapperMock>(id, name, description);

            Assert.IsNotNull(componentInstance);
            Assert.AreEqual(id, componentInstance.Id);
            Assert.AreEqual(name, componentInstance.Name);
            Assert.AreEqual(description, componentInstance.Description);
            Assert.AreEqual(typeof(ArgumentMapperMock), componentInstance.ComponentType);
        }
예제 #17
0
        public void CreateWatcherInfoTest()
        {
            var    id              = PluginUtilities.GetUniqueId();
            string name            = "watcherName";
            string description     = "This is watcher description";
            var    watcherInstance = RoutindoWatcherInfo.Create <WatcherMock>(id, name, description);

            Assert.IsNotNull(watcherInstance);
            Assert.AreEqual(id, watcherInstance.Id);
            Assert.AreEqual(name, watcherInstance.Name);
            Assert.AreEqual(description, watcherInstance.Description);
            Assert.AreEqual(typeof(WatcherMock), watcherInstance.ComponentType);
        }
예제 #18
0
        public void CreateActionInfoTest()
        {
            var    id             = PluginUtilities.GetUniqueId();
            string name           = "actionName";
            string description    = "This is action description";
            var    actionInstance = RoutindoActionInfo.Create <ActionMock>(id, name, description);

            Assert.IsNotNull(actionInstance);
            Assert.AreEqual(id, actionInstance.Id);
            Assert.AreEqual(name, actionInstance.Name);
            Assert.AreEqual(description, actionInstance.Description);
            Assert.AreEqual(typeof(ActionMock), actionInstance.ComponentType);
        }
예제 #19
0
        public void DownloadFileWithAppendTest()
        {
            var localWriteDir = Path.GetDirectoryName(Environment.ExpandEnvironmentVariables(LocalWorkingDir));
            FtpDownloadAction ftpDownloadAction = new FtpDownloadAction()
            {
                Id             = PluginUtilities.GetUniqueId(),
                LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(nameof(FtpDownloadAction))
            };

            ftpDownloadAction.Host          = FtpTestCredentials.Host;
            ftpDownloadAction.Username      = FtpTestCredentials.User;
            ftpDownloadAction.Password      = FtpTestCredentials.Password;
            ftpDownloadAction.Port          = FtpTestCredentials.Port;
            ftpDownloadAction.DirectoryPath = LocalDownloadDir;
            ftpDownloadAction.Append        = true;

            var fileNamePath = CreateTestFile(localWriteDir);

            var actionResult = ftpDownloadAction.Execute(ArgumentCollection.New()
                                                         .WithArgument(FtpDownloadActionExecutionArgs.RemoteFilesCollection, new List <string>()
            {
                Path.GetFileName(fileNamePath)
            })
                                                         );

            Assert.IsNotNull(actionResult);
            Assert.IsTrue(actionResult.Result);

            File.AppendAllLines(Path.Combine(Environment.ExpandEnvironmentVariables(localWriteDir), fileNamePath), new List <string>()
            {
                // Environment.NewLine,
                $"{Environment.NewLine}Hello world!"
            });

            actionResult = ftpDownloadAction.Execute(ArgumentCollection.New()
                                                     .WithArgument(FtpDownloadActionExecutionArgs.RemoteFilesCollection, new List <string>()
            {
                Path.GetFileName(fileNamePath)
            })
                                                     );

            Assert.IsNotNull(actionResult);
            Assert.IsTrue(actionResult.Result);

            var fileLines = File.ReadAllLines(Path.Combine(
                                                  Environment.ExpandEnvironmentVariables(ftpDownloadAction.DirectoryPath),
                                                  Path.GetFileName(fileNamePath)));

            Assert.AreEqual(2, fileLines.Count());
        }
예제 #20
0
        public void WatchProcessFailsOnNoNameTest()
        {
            IWatcher watcher = new ProcessWatcher()
            {
                Id             = PluginUtilities.GetUniqueId(),
                LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(nameof(ProcessWatcher)),
            };

            var watcherResult = watcher.Watch();

            Assert.IsNotNull(watcherResult);
            Assert.IsFalse(watcherResult.Result);
            Assert.IsNotNull(watcherResult.AttachedException);
            Assert.AreEqual(typeof(MissingArgumentException), watcherResult.AttachedException.GetType());
        }
예제 #21
0
        public void CreateZipFromDirectoryTest()
        {
            var     outputDirectory = Path.Combine(Path.GetTempPath(), "TEST_OUTPUT");
            IAction action          = new ZipDirectoryAction()
            {
                OutputDirectory       = outputDirectory,
                CreateOutputDirectory = true,
                EraseOutputIfExists   = true,
                Id = PluginUtilities.GetUniqueId(), LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(null)
            };

            var testDir = Path.Combine(Path.GetTempPath(), "TEMPO_TEST");

            if (!Directory.Exists(testDir))
            {
                Directory.CreateDirectory(testDir);
            }

            var createdDir = new DirectoryInfo(testDir);

            Assert.IsTrue(Directory.Exists(createdDir.FullName));
            var file1 = Path.Combine(createdDir.FullName, "file1.txt");

            if (!File.Exists(file1))
            {
                File.WriteAllText(file1, "Hello world");
            }
            Assert.IsTrue(File.Exists(file1));
            var file2 = Path.Combine(createdDir.FullName, "file2.txt");

            if (!File.Exists(file2))
            {
                File.WriteAllText(file2, "Hello world");
            }
            Assert.IsTrue(File.Exists(file2));

            var actionResult = action.Execute(ArgumentCollection.New()
                                              .WithArgument(ZipDirectoryActionExecutionArgs.Directory, createdDir.FullName));

            Assert.IsNotNull(actionResult);
            Assert.IsTrue(actionResult.Result);

            Assert.IsTrue(File.Exists(Path.Combine(outputDirectory, "TEMPO_TEST.zip")));

            Directory.Delete(createdDir.FullName, true);

            File.Delete(Path.Combine(Path.GetTempPath(), "TEMPO_TEST.zip"));
        }
예제 #22
0
        public void CreateZipFailsOnSourceDirectoryNotFoundTest()
        {
            var     outputDirectory = Path.Combine(Path.GetTempPath(), "TEST_OUTPUT");
            IAction action          = new ZipDirectoryAction()
            {
                OutputDirectory = outputDirectory,
                Id             = PluginUtilities.GetUniqueId(),
                LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(null)
            };
            var testDir      = Path.Combine(Path.GetTempPath(), "TEMPO_TEST");
            var actionResult = action.Execute(ArgumentCollection.New()
                                              .WithArgument(ZipDirectoryActionExecutionArgs.Directory, testDir));

            Assert.IsNotNull(actionResult);
            Assert.IsFalse(actionResult.Result);
        }
예제 #23
0
 private IWatcher GetPingWatcher(bool anyStatus, string targetHost, bool targetStatus = true)
 {
     return(anyStatus
         ? new PingStatusWatcher()
     {
         Id = PluginUtilities.GetUniqueId(),
         AnyStatus = anyStatus,
         Host = targetHost
     }
         : new PingStatusWatcher()
     {
         Id = PluginUtilities.GetUniqueId(),
         AnyStatus = anyStatus,
         Host = targetHost,
         Reachable = targetStatus
     });
 }
예제 #24
0
        public void StartProcessNotepadTest()
        {
            string             processPath        = @"notepad";
            StartProcessAction startProcessAction = new StartProcessAction()
            {
                Id             = PluginUtilities.GetUniqueId(),
                LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(nameof(StartProcessAction)),
                ProcessPath    = processPath,
            };

            var actionResult = startProcessAction.Execute(ArgumentCollection.New());

            Assert.IsNotNull(actionResult);
            Assert.IsTrue(actionResult.Result);

            System.Diagnostics.Process.GetProcessesByName(processPath).FirstOrDefault()?.Kill();
        }
예제 #25
0
        public void KillProcessByIdNotExistTest()
        {
            var processId = int.MaxValue;
            Assert.AreNotEqual(0, processId);
            Console.WriteLine($"Created Process with ID {processId}");
            Thread.Sleep(1000);
            KillProcessByIdAction action = new KillProcessByIdAction()
            {
                Id = PluginUtilities.GetUniqueId(),
                LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(nameof(KillProcessByNameAction))
            };

            var actionResult = action.Execute(ArgumentCollection.New()
                .WithArgument(KillProcessByIdActionExecutionArgs.ProcessId, processId)
            );
            Assert.IsNotNull(actionResult);
            Assert.IsFalse(actionResult.Result);
            Assert.IsNotNull(actionResult.AttachedException);
            
        }
예제 #26
0
        public void CheckStatusOfUnavailableUrl()
        {
            var watcher = new UrlStatusWatcher()
            {
                AnyStatus      = true,
                Url            = "http://routindo.com/error404notfound",
                Id             = PluginUtilities.GetUniqueId(),
                LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(nameof(UrlStatusWatcher))
            };

            var watcherResult = watcher.Watch();

            Assert.IsNotNull(watcherResult);
            Assert.IsTrue(watcherResult.Result);
            Assert.IsTrue(watcherResult.WatchingArguments.HasArgument(UrlStatusWatcherResultArgs.StatusCodeName));
            Assert.IsInstanceOfType(watcherResult.WatchingArguments[UrlStatusWatcherResultArgs.StatusCodeName], typeof(string));
            Assert.IsTrue(watcherResult.WatchingArguments.HasArgument(UrlStatusWatcherResultArgs.StatusCodeValue));
            Assert.IsInstanceOfType(watcherResult.WatchingArguments[UrlStatusWatcherResultArgs.StatusCodeValue], typeof(int));
            var statusCodeValue = watcherResult.WatchingArguments.GetValue <int>(UrlStatusWatcherResultArgs.StatusCodeValue);
            var statusCode      = (HttpStatusCode)statusCodeValue;

            Assert.AreEqual(HttpStatusCode.NotFound, statusCode);
        }
예제 #27
0
        public void WatchForDirectoryTest()
        {
            string     remoteWorkingDir = "/";
            FtpWatcher watcher          = new FtpWatcher
            {
                Id                = PluginUtilities.GetUniqueId(),
                LoggingService    = ServicesContainer.ServicesProvider.GetLoggingService(nameof(FtpWatcher)),
                Host              = FtpTestCredentials.Host,
                Username          = FtpTestCredentials.User,
                Password          = FtpTestCredentials.Password,
                SelectDirectories = true
            };


            var watcherResult = watcher.Watch();

            Assert.IsNotNull(watcherResult);
            Assert.AreEqual(true, watcherResult.Result);
            Assert.IsNotNull(watcherResult.WatchingArguments);
            Assert.IsTrue(watcherResult.WatchingArguments.HasArgument(FtpWatcherResultArgs.RemoteFilesCollection));
            Assert.IsTrue(watcherResult.WatchingArguments.GetValue <List <string> >(FtpWatcherResultArgs.RemoteFilesCollection).Any());
            Assert.AreEqual(1, watcherResult.WatchingArguments.GetValue <List <string> >(FtpWatcherResultArgs.RemoteFilesCollection).Count);
        }
예제 #28
0
        public void StartProcessTest()
        {
            string             processPath        = @"%userprofile%\Desktop\processtest\sample.bat";
            StartProcessAction startProcessAction = new StartProcessAction()
            {
                Id                 = PluginUtilities.GetUniqueId(),
                LoggingService     = ServicesContainer.ServicesProvider.GetLoggingService(nameof(StartProcessAction)),
                ProcessPath        = Environment.ExpandEnvironmentVariables(processPath),
                WaitForExit        = true,
                WaitForExitTimeout = 10000
            };

            var actionResult = startProcessAction.Execute(ArgumentCollection.New());

            Assert.IsNotNull(actionResult);
            Assert.IsTrue(actionResult.Result);
            Assert.IsNull(actionResult.AttachedException);
            Assert.IsNotNull(actionResult.AdditionalInformation);
            Assert.IsTrue(actionResult.AdditionalInformation.HasArgument(StartProcessActionResultArgs.ProcessPath));
            Assert.IsTrue(
                actionResult.AdditionalInformation.HasArgument(StartProcessActionResultArgs.ProcessArguments));
            Assert.IsTrue(
                actionResult.AdditionalInformation.HasArgument(StartProcessActionResultArgs.ProcessWorkingDirectory));
            Assert.IsTrue(actionResult.AdditionalInformation.HasArgument(StartProcessActionResultArgs.ProcessExited));
            Assert.IsTrue(actionResult.AdditionalInformation.HasArgument(StartProcessActionResultArgs.ProcessStarted));
            Assert.AreEqual(Environment.ExpandEnvironmentVariables(processPath),
                            actionResult.AdditionalInformation.GetValue <string>(StartProcessActionResultArgs.ProcessPath));
            Assert.AreEqual(Path.GetDirectoryName(Environment.ExpandEnvironmentVariables(processPath)),
                            actionResult.AdditionalInformation.GetValue <string>(
                                StartProcessActionResultArgs.ProcessWorkingDirectory));
            Assert.IsTrue(string.IsNullOrWhiteSpace(
                              actionResult.AdditionalInformation.GetValue <string>(StartProcessActionResultArgs.ProcessArguments)));
            Assert.AreEqual(true,
                            actionResult.AdditionalInformation.GetValue <bool>(StartProcessActionResultArgs.ProcessStarted));
            Assert.AreEqual(true,
                            actionResult.AdditionalInformation.GetValue <bool>(StartProcessActionResultArgs.ProcessExited));
        }