Example #1
0
        public void ShouldThrowExceptionWithoutOptions()
        {
            string             fileName     = @"C:\mockFile.bat";
            MockFileSystemInfo mockFileInfo = new MockFileSystemInfo(fileName);

            BatTranslator translator = new BatTranslator();

            Assert.Throws <ArgumentNullException>(() => translator.Translate(mockFileInfo, null));
        }
Example #2
0
        public void ShouldInitializeScriptFile()
        {
            string         fileName       = "MockFileName";
            FileSystemInfo fileSystemInfo = new MockFileSystemInfo(fileName);

            ExternalScript externalScript = new ExternalScript(fileSystemInfo, new PowershellTranslator());

            FileSystemInfo expected = fileSystemInfo;
            FileSystemInfo actual   = externalScript.ScriptFile;

            Assert.Equal(expected, actual);
        }
Example #3
0
        public void ShouldInitializeTranslator()
        {
            string                fileName       = "MockFileName";
            FileSystemInfo        fileSystemInfo = new MockFileSystemInfo(fileName);
            IPowershellTranslator translator     = new PowershellTranslator();

            ExternalScript externalScript = new ExternalScript(fileSystemInfo, translator);

            IPowershellTranslator expected = translator;
            IPowershellTranslator actual   = externalScript.Translator;

            Assert.Equal(expected, actual);
        }
Example #4
0
        public void ShouldTranslatePowershellScriptToCorrectPowershellCommandWithArguments()
        {
            string             fileName     = @"C:\mockFile.bat";
            IOptions           options      = new Options();
            MockFileSystemInfo mockFileInfo = new MockFileSystemInfo(fileName);

            BatTranslator translator = new BatTranslator(new string[] { "test" }, () => 1000);
            string        result     = translator.Translate(mockFileInfo, options);

            string actual   = result;
            string expected = @"powershell.exe ""C:\Users\WDAGUtilityAccount\Desktop\Sandbox\mockFile.bat"" 3>&1 2>&1 > ""C:\Users\WDAGUtilityAccount\Desktop\Log_1000.txt"" test";

            Assert.Equal(expected, actual);
        }
Example #5
0
        public void ShouldTranslatePowershellScriptToCorrectPowershellCommandWithoutArguments()
        {
            string             fileName     = @"C:\mockFile.ps1";
            IOptions           options      = new Options();
            MockFileSystemInfo mockFileInfo = new MockFileSystemInfo(fileName);

            PowershellTranslator powershellTranslator = new PowershellTranslator(null, () => 1000);
            string result = powershellTranslator.Translate(mockFileInfo, options);

            string actual   = result;
            string expected = @"powershell.exe -ExecutionPolicy Bypass -File C:\Users\WDAGUtilityAccount\Desktop\Sandbox\mockFile.ps1 3>&1 2>&1 > ""C:\Users\WDAGUtilityAccount\Desktop\Log_1000.txt""";

            Assert.Equal(expected, actual);
        }
Example #6
0
        public async Task ShouldCopyFromCorrectSource()
        {
            string                fileName   = @"C:\MockFileName.ps1";
            IOptions              options    = new Options();
            MockFileSystemInfo    fileInfo   = new MockFileSystemInfo(fileName);
            IPowershellTranslator translator = new PowershellTranslator();

            string sourcePath = string.Empty;

            ExternalScript externalScript = new ExternalScript(fileInfo, translator, (source, destination, token) =>
            {
                sourcePath = source;
                return(Task.CompletedTask);
            });

            await externalScript.Process(options);

            string expected = fileName;
            string actual   = sourcePath;

            Assert.Equal(expected, actual);
        }
Example #7
0
        public async Task ShouldCopyToCorrectDestination()
        {
            string                fileName   = @"C:\MockFileName.ps1";
            IOptions              options    = new Options();
            MockFileSystemInfo    fileInfo   = new MockFileSystemInfo(fileName);
            IPowershellTranslator translator = new PowershellTranslator();

            string destinationPath = string.Empty;

            ExternalScript externalScript = new ExternalScript(fileInfo, translator, (source, destination, token) =>
            {
                destinationPath = destination;

                return(Task.CompletedTask);
            });

            await externalScript.Process(options);

            string expected = Path.Combine(options.RootFilesDirectoryLocation, Path.GetFileName(externalScript.ScriptFile.Name));
            string actual   = destinationPath;

            Assert.Equal(expected, actual);
        }