diff --git a/FAFB-PowerShell-Tool.Tests/CustomQueriesTest.cs b/FAFB-PowerShell-Tool.Tests/CustomQueriesTest.cs index b66f7a6..e6dcd5c 100644 --- a/FAFB-PowerShell-Tool.Tests/CustomQueriesTest.cs +++ b/FAFB-PowerShell-Tool.Tests/CustomQueriesTest.cs @@ -1,6 +1,4 @@ namespace FAFB_PowerShell_Tool.Tests; public class CustomQueriesTest -{ - -} \ No newline at end of file +{ } diff --git a/FAFB-PowerShell-Tool.Tests/GlobalUsings.cs b/FAFB-PowerShell-Tool.Tests/GlobalUsings.cs index 8c927eb..c802f44 100644 --- a/FAFB-PowerShell-Tool.Tests/GlobalUsings.cs +++ b/FAFB-PowerShell-Tool.Tests/GlobalUsings.cs @@ -1 +1 @@ -global using Xunit; \ No newline at end of file +global using Xunit; diff --git a/FAFB-PowerShell-Tool.Tests/GuiCommandTest.cs b/FAFB-PowerShell-Tool.Tests/GuiCommandTest.cs deleted file mode 100644 index cd0a5c2..0000000 --- a/FAFB-PowerShell-Tool.Tests/GuiCommandTest.cs +++ /dev/null @@ -1,49 +0,0 @@ -using FAFB_PowerShell_Tool.PowerShell.Commands; - -namespace FAFB_PowerShell_Tool.Tests; - -public class GuiCommandTest -{ - [Fact] - public void CommandNameIsCorrect() - { - GuiCommand command = new("Get-ADUser"); - Assert.Equal("Get-ADUser", command.CommandName); - } - - [Fact] - public void CommandStringGetIsCorrectWhenParametersAreSet() - { - GuiCommand command = new("Get-ADUser", new[] {"-Identity", "Test"}); - Assert.Equal("Get-ADUser -Identity Test", command.CommandString); - Assert.Equal("-Identity", command.Parameters![0]); - Assert.Equal("Test", command.Parameters![1]); - } - - [Fact] - public void PossibleParametersThrowsInvalidOperationExceptionWhenEmpty() - { - GuiCommand command = new("Get-ADUser"); - Assert.Throws(() => command.PossibleParameters); - } - - [Fact] - public async Task PossibleParametersReturnsCorrectly() - { - GuiCommand command = new("Get-ADUser"); - await command.LoadCommandParametersAsync(); - Assert.Contains("-Identity", command.PossibleParameters); - Assert.True(command.PossibleParameters.Count > 0); - } - - [Fact] - public async Task PossibleParametersReturnsCorrectlyWhenCalledTwice() - { - GuiCommand command = new("Get-ADUser"); - await command.LoadCommandParametersAsync(); - await command.LoadCommandParametersAsync(); - Assert.Contains("-Identity", command.PossibleParameters); - Assert.True(command.PossibleParameters.Count > 0); - Assert.Equal(command.PossibleParameters.Count, command.PossibleParameters.Distinct().Count()); - } -} diff --git a/FAFB-PowerShell-Tool.Tests/InternalCommandTest.cs b/FAFB-PowerShell-Tool.Tests/InternalCommandTest.cs deleted file mode 100644 index 9dcd584..0000000 --- a/FAFB-PowerShell-Tool.Tests/InternalCommandTest.cs +++ /dev/null @@ -1,20 +0,0 @@ -using FAFB_PowerShell_Tool.PowerShell.Commands; - -namespace FAFB_PowerShell_Tool.Tests; - -public class InternalCommandTest -{ - [Fact] - public void CommandNameIsCorrect() - { - InternalCommand command = new("Get-ADUser"); - Assert.Equal("Get-ADUser", command.CommandName); - } - - [Fact] - public void CommandStringGetIsCorrectWhenParametersAreSet() - { - InternalCommand command = new("Get-ADUser", new[] {"-Identity", "Test"}); - Assert.Equal("Get-ADUser -Identity Test", command.CommandString); - } -} \ No newline at end of file diff --git a/FAFB-PowerShell-Tool.Tests/PowerShellExecutorTest.cs b/FAFB-PowerShell-Tool.Tests/PowerShellExecutorTest.cs index 24d0b69..4fed025 100644 --- a/FAFB-PowerShell-Tool.Tests/PowerShellExecutorTest.cs +++ b/FAFB-PowerShell-Tool.Tests/PowerShellExecutorTest.cs @@ -1,5 +1,5 @@ -using FAFB_PowerShell_Tool.PowerShell; -using FAFB_PowerShell_Tool.PowerShell.Commands; +using System.Management.Automation.Runspaces; +using FAFB_PowerShell_Tool.PowerShell; using ArgumentException = System.ArgumentException; namespace FAFB_PowerShell_Tool.Tests; @@ -10,30 +10,29 @@ public class PowerShellExecutorTest public void ExecuteCommandReturnsAreCorrect() { PowerShellExecutor powerShell = new(); - ReturnValues values = powerShell.Execute(new InternalCommand("Get-Process")); + ReturnValues values = powerShell.Execute(new Command("Get-Process")); Assert.False(values.HadErrors); Assert.NotEmpty(values.StdOut); Assert.Empty(values.StdErr); } - + [Fact] public void ExecuteBadCommandReturnsAreCorrect() { PowerShellExecutor powerShell = new(); - ReturnValues values = powerShell.Execute(new InternalCommand("BadCommand")); + ReturnValues values = powerShell.Execute(new Command("BadCommand")); Assert.True(values.HadErrors); Assert.Empty(values.StdOut); Assert.NotEmpty(values.StdErr); } - + [Fact] public void ExecuteBadInternalCommandThrowsInvalidOperationException() { PowerShellExecutor powerShell = new(); - Assert.Throws(() => powerShell.Execute(new InternalCommand(""))); - Assert.Throws(() => powerShell.Execute(new InternalCommand(" "))); - Assert.Throws(() => powerShell.Execute(new InternalCommand(null!))); - Assert.Throws(() => powerShell.Execute(new InternalCommand(string.Empty))); + Assert.Throws(() => powerShell.Execute(new Command(""))); + Assert.Throws(() => powerShell.Execute(new Command(" "))); + Assert.Throws(() => powerShell.Execute(new Command(null!))); + Assert.Throws(() => powerShell.Execute(new Command(string.Empty))); } - } diff --git a/FAFB-PowerShell-Tool.Tests/SaveOptionsTest.cs b/FAFB-PowerShell-Tool.Tests/SaveOptionsTest.cs index 4f6729a..3b75e06 100644 --- a/FAFB-PowerShell-Tool.Tests/SaveOptionsTest.cs +++ b/FAFB-PowerShell-Tool.Tests/SaveOptionsTest.cs @@ -1,4 +1,5 @@ -using FAFB_PowerShell_Tool.PowerShell.Commands; +using System.Management.Automation.Internal; +using System.Management.Automation.Runspaces; using FAFB_PowerShell_Tool; using FAFB_PowerShell_Tool.PowerShell; @@ -6,18 +7,21 @@ namespace FAFB_PowerShell_Tool.Tests; public class SaveOptionsTest { - [Fact] + /*[Fact] public void SaveToCSVAppendsParameter() { var saveOptions = new PSSaveOptions(); - InternalCommand command = new("Get-ADUser", new[] { "-Identity", "Test" }); + Command commandString = new("Get-ADUser"); + commandString.Parameters.Add("Identity", "Test"); - InternalCommand returnedCommand = saveOptions.OutputToCSV(command); + InternalCommand returnedCommand = saveOptions.OutputToCSV(commandString); - Assert.Equal("Get-ADUser -Identity Test | Export-CSV ..\\..\\..\\SavedOutput\\output.csv", returnedCommand.CommandString); - } - [Fact] + Assert.Equal("Get-ADUser -Identity Test | Export-CSV ..\\..\\..\\SavedOutput\\output.csv", + returnedCommand.CommandString); + }*/ + + /*[Fact] public void ExecuteOutputToCSV() { PSSaveOptions pssave = new PSSaveOptions(); @@ -25,12 +29,8 @@ public void ExecuteOutputToCSV() InternalCommand test_command = new("get-process"); ReturnValues temprv = executor.Execute(pssave.OutputToCSV(test_command)); - //Check if a csv was made + //Check if a csv was made Assert.True(File.Exists("..\\..\\..\\SavedOutput\\output.csv")); //File.Delete("..\\..\\..\\FAFB-PowerShell-Tool\\SavedOutput\\output.csv"); - } - - - - -} \ No newline at end of file + }*/ +} diff --git a/FAFB-PowerShell-Tool/MainWindow.xaml b/FAFB-PowerShell-Tool/MainWindow.xaml index 579235b..35d0156 100644 --- a/FAFB-PowerShell-Tool/MainWindow.xaml +++ b/FAFB-PowerShell-Tool/MainWindow.xaml @@ -6,6 +6,10 @@ xmlns:local="clr-namespace:FAFB_PowerShell_Tool" mc:Ignorable="d" Title="MainWindow" Height="500" Width="800"> + + + + @@ -44,9 +48,14 @@ - - - + + @@ -58,9 +67,7 @@ - + @@ -75,16 +82,22 @@ - - - - - - - - - - + + @@ -97,7 +110,21 @@ -