diff --git a/ActiveDirectoryQuerier.Tests/MainWindowViewModelTests.cs b/ActiveDirectoryQuerier.Tests/MainWindowViewModelTests.cs index 002455f..10446bf 100644 --- a/ActiveDirectoryQuerier.Tests/MainWindowViewModelTests.cs +++ b/ActiveDirectoryQuerier.Tests/MainWindowViewModelTests.cs @@ -35,11 +35,8 @@ public void ClearConsoleOutput_WhenConsoleIsNotEmpty_ShowsWarningMessage() _viewModel.ClearConsoleOutput(consoleViewModel); - _messageBoxServiceMock.Verify(m => m.Show(It.IsAny(), - "Warning", - MessageBoxButton.YesNo, - MessageBoxImage.Warning, - MessageBoxResult.No), + _messageBoxServiceMock.Verify(m => m.Show(It.IsAny(), "Warning", MessageBoxButton.YesNo, + MessageBoxImage.Warning, MessageBoxResult.No), Times.Once); } @@ -57,8 +54,7 @@ public void EditQueryFromQueryStackPanel_NullParameter_ShowsMessageBox() // Assert _messageBoxServiceMock.Verify( - x => x.Show(It.IsAny(), "Error", MessageBoxButton.OK, MessageBoxImage.Error), - Times.Once); + x => x.Show(It.IsAny(), "Error", MessageBoxButton.OK, MessageBoxImage.Error), Times.Once); } [Fact] @@ -67,8 +63,7 @@ public void DeleteQueryFromQueryStackPanel_WhenNoQuerySelected_ShowsWarningMessa _viewModel.DeleteQueryFromQueryStackPanel(null); _messageBoxServiceMock.Verify( - m => m.Show(It.IsAny(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning), - Times.Once); + m => m.Show(It.IsAny(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning), Times.Once); } [Fact] @@ -77,8 +72,7 @@ public void RemoveParameterComboBoxInQueryBuilder_WhenNoParametersToRemove_Shows _viewModel.RemoveParameterComboBoxInQueryBuilder(null); _messageBoxServiceMock.Verify( - m => m.Show(It.IsAny(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning), - Times.Once); + m => m.Show(It.IsAny(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning), Times.Once); } [Fact] @@ -87,8 +81,7 @@ public void SaveCurrentQuery_WhenNoCommandSelected_ShowsWarningMessage() _viewModel.SaveCurrentQuery(null); _messageBoxServiceMock.Verify( - m => m.Show(It.IsAny(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning), - Times.Once); + m => m.Show(It.IsAny(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning), Times.Once); } [Fact] @@ -97,8 +90,7 @@ public void AddParameterComboBoxInQueryBuilder_WhenNoCommandSelected_ShowsWarnin _viewModel.AddParameterComboBoxInQueryBuilder(null); _messageBoxServiceMock.Verify( - m => m.Show(It.IsAny(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning), - Times.Once); + m => m.Show(It.IsAny(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning), Times.Once); } [Fact] diff --git a/ActiveDirectoryQuerier.Tests/PSExecutorTests.cs b/ActiveDirectoryQuerier.Tests/PSExecutorTests.cs index f3fb15f..bf3649c 100644 --- a/ActiveDirectoryQuerier.Tests/PSExecutorTests.cs +++ b/ActiveDirectoryQuerier.Tests/PSExecutorTests.cs @@ -18,8 +18,7 @@ public PSExecutorTests() [Theory] [InlineData("Get-Command", "Module", "ActiveDirectory")] [InlineData("Get-Process", "Name", "explorer")] - public void Execute_WhenGivenValidCommand_ReturnsExpectedOutput(string command, - string parameter, + public void Execute_WhenGivenValidCommand_ReturnsExpectedOutput(string command, string parameter, string parameterValue) { // Arrange @@ -55,8 +54,7 @@ public void Execute_CheckIfOutputChanged_ReturnsDifferentOutput() [Theory] [InlineData("Get-Command", "Module", "ActiveDirectory")] [InlineData("Get-Process", "Name", "explorer")] - public async Task ExecuteAsync_WhenGivenValidCommand_ReturnsExpectedOutput(string command, - string parameter, + public async Task ExecuteAsync_WhenGivenValidCommand_ReturnsExpectedOutput(string command, string parameter, string parameterValue) { // Arrange @@ -75,8 +73,7 @@ public async Task ExecuteAsync_WhenGivenValidCommand_ReturnsExpectedOutput(strin [Theory] [InlineData("Get-ADUser", "InvalidParameter", "*")] [InlineData("InvalidCommand", "Filter", "*")] - public void Execute_WhenGivenInvalidCommand_ReturnsExpectedOutput(string command, - string parameter, + public void Execute_WhenGivenInvalidCommand_ReturnsExpectedOutput(string command, string parameter, string parameterValue) { // Arrange @@ -95,8 +92,7 @@ public void Execute_WhenGivenInvalidCommand_ReturnsExpectedOutput(string command [Theory] [InlineData("Get-ADUser", "InvalidParameter", "*")] [InlineData("InvalidCommand", "Filter", "*")] - public async Task ExecuteAsync_WhenGivenInvalidCommand_ReturnsExpectedOutput(string command, - string parameter, + public async Task ExecuteAsync_WhenGivenInvalidCommand_ReturnsExpectedOutput(string command, string parameter, string parameterValue) { // Arrange @@ -115,8 +111,7 @@ public async Task ExecuteAsync_WhenGivenInvalidCommand_ReturnsExpectedOutput(str [Theory] [InlineData("Get-Command", "Module", "ActiveDirectory")] [InlineData("Get-Process", "Name", "explorer")] - public async Task ExecuteAsync_ExecuteToCsv_ReturnsExpectedOutput(string command, - string parameter, + public async Task ExecuteAsync_ExecuteToCsv_ReturnsExpectedOutput(string command, string parameter, string parameterValue) { // Arrange diff --git a/ActiveDirectoryQuerier/MainWindowViewModel.cs b/ActiveDirectoryQuerier/MainWindowViewModel.cs index db92f39..2598606 100644 --- a/ActiveDirectoryQuerier/MainWindowViewModel.cs +++ b/ActiveDirectoryQuerier/MainWindowViewModel.cs @@ -231,18 +231,14 @@ internal void ClearConsoleOutput(ConsoleViewModel consoleOutput) { if (consoleOutput.GetConsoleOutput.Length == 0) { - MessageBoxService.Show("The console is already clear.", - "Information", - MessageBoxButton.OK, + MessageBoxService.Show("The console is already clear.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } - MessageBoxResult result = MessageBoxService.Show("Are you sure you want to clear the console output?", - "Warning", - MessageBoxButton.YesNo, - MessageBoxImage.Warning, - MessageBoxResult.No); + MessageBoxResult result = + MessageBoxService.Show("Are you sure you want to clear the console output?", "Warning", + MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); if (result == MessageBoxResult.Yes) { @@ -255,9 +251,7 @@ private async void ExecuteSelectedQueryInADInfo(object? _) if (SelectedQueryInActiveDirectoryInfo is null) { Trace.WriteLine("No command selected."); - MessageBoxService.Show("You must first select an option to execute.", - "Warning", - MessageBoxButton.OK, + MessageBoxService.Show("You must first select an option to execute.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } @@ -282,10 +276,8 @@ internal void EditQueryFromQueryStackPanel(object? queryButton) if (queryButton is not Button button) { Trace.WriteLine("No button selected."); - MessageBoxService.Show($"An internal error occurred while trying to edit the query: {queryButton}", - "Error", - MessageBoxButton.OK, - MessageBoxImage.Error); + MessageBoxService.Show($"An internal error occurred while trying to edit the query: {queryButton}", "Error", + MessageBoxButton.OK, MessageBoxImage.Error); return; } @@ -332,18 +324,14 @@ internal void DeleteQueryFromQueryStackPanel(object? queryButton) if (queryButton is not Button currentButton) { Trace.WriteLine("No button selected."); - MessageBoxService.Show("To delete a query, you must first select a query.", - "Warning", - MessageBoxButton.OK, + MessageBoxService.Show("To delete a query, you must first select a query.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } - MessageBoxResult result = MessageBoxService.Show("Are you sure you want to delete the query?", - "Warning", - MessageBoxButton.YesNo, - MessageBoxImage.Warning, - MessageBoxResult.No); + MessageBoxResult result = + MessageBoxService.Show("Are you sure you want to delete the query?", "Warning", MessageBoxButton.YesNo, + MessageBoxImage.Warning, MessageBoxResult.No); if (result == MessageBoxResult.Yes) { @@ -466,10 +454,8 @@ internal void AddParameterComboBoxInQueryBuilder(object? _) if (AvailableADCommandParameters is null) { Trace.WriteLine("AvailableADCommandParameters has not been populated yet."); - MessageBoxService.Show("To add a parameter, you must first select a command.", - "Warning", - MessageBoxButton.OK, - MessageBoxImage.Warning); + MessageBoxService.Show("To add a parameter, you must first select a command.", "Warning", + MessageBoxButton.OK, MessageBoxImage.Warning); return; } @@ -489,9 +475,7 @@ private void UpdateCommandWithSelectedParameters() if (SelectedCommandInQueryBuilder is null) { Trace.WriteLine("No command selected."); - MessageBoxService.Show("To save a query, you must first select a command.", - "Warning", - MessageBoxButton.OK, + MessageBoxService.Show("To save a query, you must first select a command.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } @@ -547,9 +531,7 @@ internal void RemoveParameterComboBoxInQueryBuilder(object? _) } else { - MessageBoxService.Show("There are no parameters to remove.", - "Warning", - MessageBoxButton.OK, + MessageBoxService.Show("There are no parameters to remove.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } } @@ -559,9 +541,7 @@ internal void SaveCurrentQuery(object? commandParameter) if (SelectedCommandInQueryBuilder is null) { Trace.WriteLine("No command selected."); - MessageBoxService.Show("To save a query, you must first select a command.", - "Warning", - MessageBoxButton.OK, + MessageBoxService.Show("To save a query, you must first select a command.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } @@ -602,19 +582,15 @@ internal void ClearQueryBuilder(object? _) { if (SelectedCommandInQueryBuilder is null && DynamicallyAvailableADCommandParameterComboBoxes.Count == 0) { - MessageBoxService.Show("The query builder is already clear.", - "Information", - MessageBoxButton.OK, + MessageBoxService.Show("The query builder is already clear.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } // Display a gui box confirming if the user wants to confirm the clear - MessageBoxResult result = MessageBoxService.Show("Are you sure you want to clear the query builder?", - "Warning", - MessageBoxButton.YesNo, - MessageBoxImage.Warning, - MessageBoxResult.No); + MessageBoxResult result = + MessageBoxService.Show("Are you sure you want to clear the query builder?", "Warning", + MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); // If the user selects yes, clear the consoleOutput if (result == MessageBoxResult.Yes) @@ -639,10 +615,8 @@ private async Task ExecuteQueryAsync(ConsoleViewModel consoleOutput, Command? co if (SelectedCommandInQueryBuilder is null && command is null) { Trace.WriteLine("No command selected."); - MessageBoxService.Show("To execute a command, you must first select a command.", - "Warning", - MessageBoxButton.OK, - MessageBoxImage.Warning); + MessageBoxService.Show("To execute a command, you must first select a command.", "Warning", + MessageBoxButton.OK, MessageBoxImage.Warning); return; } @@ -683,9 +657,7 @@ private async void ExecuteQueryFromQueryStackPanelAsync(object? queryButton) if (queryButton is not Button currentButton) { Trace.WriteLine("No button selected."); - MessageBoxService.Show("To execute a query, you must first select a query.", - "Warning", - MessageBoxButton.OK, + MessageBoxService.Show("To execute a query, you must first select a query.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } @@ -698,9 +670,7 @@ private void ExportConsoleOutputToFile(object? _) { if (ConsoleOutputInQueryBuilder.GetConsoleOutput.Length == 0) { - MessageBoxService.Show("The console is empty.", - "Information", - MessageBoxButton.OK, + MessageBoxService.Show("The console is empty.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } @@ -764,10 +734,8 @@ private Button CreateQueryButtonInStackPanel(Query? query = null) if (SelectedCommandInQueryBuilder is null) { Trace.WriteLine("No command selected."); - MessageBoxService.Show("To save a query, you must first select a command.", - "Warning", - MessageBoxButton.OK, - MessageBoxImage.Warning); + MessageBoxService.Show("To save a query, you must first select a command.", "Warning", + MessageBoxButton.OK, MessageBoxImage.Warning); return new Button(); } @@ -783,15 +751,13 @@ private Button CreateQueryButtonInStackPanel(Query? query = null) MenuItem menuItem1 = new() { Header = "Execute", Command = ExecuteQueryFromQueryStackPanelRelay, CommandParameter = newButton }; - MenuItem outputToCsv = new() { Header = "Output to CSV", - Command = OutputExecutionResultsToCsvFileRelay, + MenuItem outputToCsv = new() { Header = "Output to CSV", Command = OutputExecutionResultsToCsvFileRelay, CommandParameter = newButton }; - MenuItem outputToText = new() { Header = "Output to Text", - Command = OutputExecutionResultsToTextFileRelay, + MenuItem outputToText = new() { Header = "Output to Text", Command = OutputExecutionResultsToTextFileRelay, CommandParameter = newButton }; - MenuItem outputToConsole = new() { Header = "Execute to Console", - Command = ExecuteQueryFromQueryStackPanelRelay, - CommandParameter = newButton }; + MenuItem outputToConsole = + new() { Header = "Execute to Console", Command = ExecuteQueryFromQueryStackPanelRelay, + CommandParameter = newButton }; menuItem1.Items.Add(outputToCsv); menuItem1.Items.Add(outputToText); @@ -826,10 +792,8 @@ private void CheckBoxChecked(object? _) if (IsQueryEditingEnabled) { MessageBoxService.Show( - "To edit a query, right click on a query button and select 'Edit' from the context menu.", - "Warning", - MessageBoxButton.OK, - MessageBoxImage.Warning); + "To edit a query, right click on a query button and select 'Edit' from the context menu.", "Warning", + MessageBoxButton.OK, MessageBoxImage.Warning); IsQueryEditingEnabled = false; } } diff --git a/ActiveDirectoryQuerier/MessageBoxService/IMessageBoxService.cs b/ActiveDirectoryQuerier/MessageBoxService/IMessageBoxService.cs index 5e74855..2723eb7 100644 --- a/ActiveDirectoryQuerier/MessageBoxService/IMessageBoxService.cs +++ b/ActiveDirectoryQuerier/MessageBoxService/IMessageBoxService.cs @@ -6,9 +6,6 @@ public interface IMessageBoxService { void Show(string message, string caption, MessageBoxButton button, MessageBoxImage icon); - public MessageBoxResult Show(string message, - string caption, - MessageBoxButton button, - MessageBoxImage icon, + public MessageBoxResult Show(string message, string caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult result); } diff --git a/ActiveDirectoryQuerier/MessageBoxService/MessageBoxService.cs b/ActiveDirectoryQuerier/MessageBoxService/MessageBoxService.cs index e09dc1f..dd8369d 100644 --- a/ActiveDirectoryQuerier/MessageBoxService/MessageBoxService.cs +++ b/ActiveDirectoryQuerier/MessageBoxService/MessageBoxService.cs @@ -9,10 +9,7 @@ public void Show(string message, string caption, MessageBoxButton button, Messag MessageBox.Show(message, caption, button, icon); } - public MessageBoxResult Show(string message, - string caption, - MessageBoxButton button, - MessageBoxImage icon, + public MessageBoxResult Show(string message, string caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult result) { return MessageBox.Show(message, caption, button, icon, result);