public async Task ShouldGenerateCorrectContent() { string fileName = @"C:\MockFileName.ps1"; IList <string> commands = new List <string>() { @"Start-Process 'C:\windows\system32\notepad.exe'", @"Start-Process .", }; IOptions options = new Options(); IPowershellTranslator translator = new PowershellTranslator(); UTF8Encoding uTF8Encoding = new UTF8Encoding(); string strContent = string.Empty; LiteralScript literalScript = new LiteralScript( commands, translator, fileName, (path, content, token) => { strContent = uTF8Encoding.GetString(content); return(Task.CompletedTask); }); await literalScript.Process(options); string expected = @"Start-Process 'C:\windows\system32\notepad.exe' Start-Process ."; string actual = strContent; Assert.Equal(expected, actual, ignoreLineEndingDifferences: true); }
public void ShouldInitializeWithoutArguments() { PowershellTranslator translator = new PowershellTranslator(); // This is checking that the class is initialized properly and does not throw exception. Assert.True(true); }
public async Task ShouldCopyFromCorrectSource() { string fileName = @"C:\MockFileName.ps1"; IList <string> commands = new List <string>() { @"Start-Process 'C:\windows\system32\notepad.exe'", @"Start-Process .", }; IOptions options = new Options(); IPowershellTranslator translator = new PowershellTranslator(); string sourceFilePath = string.Empty; LiteralScript literalScript = new LiteralScript( commands, translator, fileName, (path, content, token) => { sourceFilePath = path; return(Task.CompletedTask); }); await literalScript.Process(options); string expected = fileName; string actual = sourceFilePath; Assert.Equal(expected, actual); }
public void ShouldThrowArgumentNullExceptionWithoutCommands() { IPowershellTranslator translator = new PowershellTranslator(); string scriptFileName = "MockFileName"; Func <string, byte[], CancellationToken, Task> writeAllBytesAsync = (path, content, token) => { return(Task.CompletedTask); }; Assert.Throws <ArgumentNullException>(() => new LiteralScript(null, translator, scriptFileName, writeAllBytesAsync)); }
public void ShouldThrowExceptionWithoutOptions() { string fileName = @"C:\mockFile.ps1"; MockFileSystemInfo mockFileInfo = new MockFileSystemInfo(fileName); PowershellTranslator translator = new PowershellTranslator(); Assert.Throws <ArgumentNullException>(() => translator.Translate(mockFileInfo, null)); }
public void ShouldThrowArgumentNullExceptionWithoutScriptFileName() { IList <string> commands = new List <string>() { @"Start-Process 'C:\windows\system32\notepad.exe'", @"Start-Process .", }; IPowershellTranslator translator = new PowershellTranslator(); Func <string, byte[], CancellationToken, Task> writeAllBytesAsync = (path, content, token) => { return(Task.CompletedTask); }; Assert.Throws <ArgumentNullException>(() => new LiteralScript(commands, translator, null, writeAllBytesAsync)); }
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); }
public void ShouldTranslatePowershellScriptToCorrectPowershellCommandWithArguments() { string fileName = @"C:\mockFile.ps1"; IOptions options = new Options(); MockFileSystemInfo mockFileInfo = new MockFileSystemInfo(fileName); PowershellTranslator powershellTranslator = new PowershellTranslator(new string[] { "test" }, () => 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"" test"; Assert.Equal(expected, actual); }
public void ShouldInitializeTranslator() { IEnumerable <string> applications = new List <string>() { "git", "curl", "fiddler" }; IPowershellTranslator powershellTranslator = new PowershellTranslator(); IPackageManagerScript scoopPackageManager = new ScoopPackageManagerScript(applications, powershellTranslator); var expected = powershellTranslator; var actual = scoopPackageManager.Translator; Assert.Equal(expected, actual); }
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); }
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); }
public void IsOptionsAssignableToIOptions() { PowershellTranslator powershellTranslator = new PowershellTranslator(); Assert.IsAssignableFrom <IPowershellTranslator>(powershellTranslator); }
public void ShouldThrowExceptionWithoutFile() { PowershellTranslator translator = new PowershellTranslator(); Assert.Throws <ArgumentNullException>(() => translator.Translate(null, new Options())); }