Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #51 from StrangeRanger/MVVM-Pattern
Browse files Browse the repository at this point in the history
MVVM Pattern
  • Loading branch information
StrangeRanger authored Jan 21, 2024
2 parents 1e379b2 + 590f059 commit cd0e0e0
Show file tree
Hide file tree
Showing 17 changed files with 386 additions and 435 deletions.
4 changes: 1 addition & 3 deletions FAFB-PowerShell-Tool.Tests/CustomQueriesTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
namespace FAFB_PowerShell_Tool.Tests;

public class CustomQueriesTest
{

}
{ }
2 changes: 1 addition & 1 deletion FAFB-PowerShell-Tool.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
global using Xunit;
global using Xunit;
49 changes: 0 additions & 49 deletions FAFB-PowerShell-Tool.Tests/GuiCommandTest.cs

This file was deleted.

20 changes: 0 additions & 20 deletions FAFB-PowerShell-Tool.Tests/InternalCommandTest.cs

This file was deleted.

21 changes: 10 additions & 11 deletions FAFB-PowerShell-Tool.Tests/PowerShellExecutorTest.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<ArgumentException>(() => powerShell.Execute(new InternalCommand("")));
Assert.Throws<ArgumentException>(() => powerShell.Execute(new InternalCommand(" ")));
Assert.Throws<ArgumentException>(() => powerShell.Execute(new InternalCommand(null!)));
Assert.Throws<ArgumentException>(() => powerShell.Execute(new InternalCommand(string.Empty)));
Assert.Throws<ArgumentException>(() => powerShell.Execute(new Command("")));
Assert.Throws<ArgumentException>(() => powerShell.Execute(new Command(" ")));
Assert.Throws<ArgumentException>(() => powerShell.Execute(new Command(null!)));
Assert.Throws<ArgumentException>(() => powerShell.Execute(new Command(string.Empty)));
}

}
28 changes: 14 additions & 14 deletions FAFB-PowerShell-Tool.Tests/SaveOptionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
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;

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();
PowerShellExecutor executor = new PowerShellExecutor();
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");
}




}
}*/
}
71 changes: 45 additions & 26 deletions FAFB-PowerShell-Tool/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
xmlns:local="clr-namespace:FAFB_PowerShell_Tool"
mc:Ignorable="d"
Title="MainWindow" Height="500" Width="800">
<Window.DataContext>
<local:MainWindowViewModel />
</Window.DataContext>

<Grid>
<!-- Define Rows -->
<Grid.RowDefinitions>
Expand Down Expand Up @@ -44,9 +48,14 @@
</Grid.Background>

<!-- Stacked Queries are placed here. -->
<StackPanel x:Name="ButtonStackPanel" >

</StackPanel>
<StackPanel x:Name="ButtonStackPanel"></StackPanel>
<!--<ItemsControl ItemsSource="{Binding SavedQueries}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding}" Height="48" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>-->
</Grid>

<!-- Grid Splitter for resizing -->
Expand All @@ -58,9 +67,7 @@
<TabControl>
<!-- Tab Items -->
<TabItem Header="Query Information">
<!--<Grid Background="White">
<Button x:Name="ExecutionButton" Content="Execute" Click="MExecutionButton" HorizontalAlignment="Left" Margin="206,88,0,0" VerticalAlignment="Top" Height="49" Width="140" Grid.Column="2"/>
</Grid>-->
<Grid Background="White"></Grid>
</TabItem>
<!-- Tab Items -->
<TabItem Header="Query Builder">
Expand All @@ -75,16 +82,22 @@
</Grid.RowDefinitions>

<Grid Grid.Row="0">
<!-- Existing Controls -->
<ComboBox x:Name="ComboBoxCommandList" SelectionChanged="MComboBoxSelectionChanged" HorizontalAlignment="Left" Margin="26,48,0,0" VerticalAlignment="Top" Width="216" BorderBrush="#FFD41818" Background="Black" IsEditable="True" Grid.Row="0"/>
<ComboBox x:Name="ComboBoxCommandParameterList" HorizontalAlignment="Left" Margin="283,48,0,0" VerticalAlignment="Top" Width="212" IsEditable="True">
<ComboBox.Background>
<LinearGradientBrush EndPoint="0,1">
<GradientStop Color="#FFF0F0F0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</ComboBox.Background>
</ComboBox>
<ComboBox x:Name="ComboBoxCommandList"
ItemsSource="{Binding ActiveDirectoryCommandList}"
SelectedItem="{Binding SelectedCommand}"
DisplayMemberPath="CommandText"
HorizontalAlignment="Left"
Margin="26,48,0,0"
VerticalAlignment="Top"
Width="216"
IsEditable="True"/>
<ComboBox x:Name="ComboBoxCommandParameterList"
ItemsSource="{Binding PossibleParameterList}"
HorizontalAlignment="Left"
Margin="283,48,0,0"
VerticalAlignment="Top"
Width="212"
IsEditable="True" />
<!-- This will be used for picking how you would like to output the query **not implemented yet** -->
<ComboBox x:Name="ComboBoxOutputOptions" HorizontalAlignment="Left" Margin="26,100,0,0" VerticalAlignment="Top" Width="216" IsEditable="True">
<ComboBox.Background>
Expand All @@ -97,7 +110,21 @@
</Grid>

<Grid Grid.Row="1" Margin="12,16">
<Button x:Name="SaveQueryButton" Click="MSaveQueryButton" Content="Save Query" HorizontalAlignment="Right" VerticalAlignment="Top" Height="29" Width="83"/>
<Grid.ColumnDefinitions>
<!-- Define two columns with equal width -->
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<!-- TODO: Joseph - Update to ensure binding and everything works correctly. -->
<Button x:Name="SaveQueryButton"
Content="Save Query"
Command="{Binding SavedQueries}"
CommandParameter="{Binding SelectedItem.Content, ElementName=ComboBoxCommandList}"
Grid.Column="0" />
<Button Content="Execute"
Command="{Binding ExecuteCommand}"
Grid.Column="1" />
</Grid>

<!-- GridSplitter for resizing console area in the second row -->
Expand All @@ -106,17 +133,9 @@
<!-- TODO: Figure out why I can't get the console to be resizable to the min height... -->
<Grid Grid.Row="3">
<!-- TextBox as Console Output -->
<TextBox x:Name="ConsoleOutputTextBox" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10" IsReadOnly="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"/>
<TextBox Text="{Binding PowerShellOutput}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10" IsReadOnly="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"/>
</Grid>
</Grid>

</TabItem>
<!-- Tab Items -->
<TabItem Header="Script Editor" HorizontalAlignment="Center" >
<Grid Background="#FFE5E5E5" Height="406">
<TextBox x:Name="ScriptEditorTextBox" HorizontalAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Top" Width="568" Height="295" KeyboardNavigation.AcceptsReturn="True" Margin="0,10,0,0" Text=""/>
<Button Content="Execute" HorizontalAlignment="Left" Margin="508,345,0,0" VerticalAlignment="Top" Height="25" Width="70"/>
</Grid>
</TabItem>
</TabControl>
</Border>
Expand Down
Loading

0 comments on commit cd0e0e0

Please sign in to comment.