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

Commit

Permalink
Format code to closer match with Microsoft standards
Browse files Browse the repository at this point in the history
  • Loading branch information
StrangeRanger committed Nov 13, 2024
1 parent c5d469a commit ad7f37b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 102 deletions.
22 changes: 7 additions & 15 deletions ActiveDirectoryQuerier.Tests/MainWindowViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ public void ClearConsoleOutput_WhenConsoleIsNotEmpty_ShowsWarningMessage()

_viewModel.ClearConsoleOutput(consoleViewModel);

_messageBoxServiceMock.Verify(m => m.Show(It.IsAny<string>(),
"Warning",
MessageBoxButton.YesNo,
MessageBoxImage.Warning,
MessageBoxResult.No),
_messageBoxServiceMock.Verify(m => m.Show(It.IsAny<string>(), "Warning", MessageBoxButton.YesNo,
MessageBoxImage.Warning, MessageBoxResult.No),
Times.Once);
}

Expand All @@ -57,8 +54,7 @@ public void EditQueryFromQueryStackPanel_NullParameter_ShowsMessageBox()

// Assert
_messageBoxServiceMock.Verify(
x => x.Show(It.IsAny<string>(), "Error", MessageBoxButton.OK, MessageBoxImage.Error),
Times.Once);
x => x.Show(It.IsAny<string>(), "Error", MessageBoxButton.OK, MessageBoxImage.Error), Times.Once);
}

[Fact]
Expand All @@ -67,8 +63,7 @@ public void DeleteQueryFromQueryStackPanel_WhenNoQuerySelected_ShowsWarningMessa
_viewModel.DeleteQueryFromQueryStackPanel(null);

_messageBoxServiceMock.Verify(
m => m.Show(It.IsAny<string>(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning),
Times.Once);
m => m.Show(It.IsAny<string>(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning), Times.Once);
}

[Fact]
Expand All @@ -77,8 +72,7 @@ public void RemoveParameterComboBoxInQueryBuilder_WhenNoParametersToRemove_Shows
_viewModel.RemoveParameterComboBoxInQueryBuilder(null);

_messageBoxServiceMock.Verify(
m => m.Show(It.IsAny<string>(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning),
Times.Once);
m => m.Show(It.IsAny<string>(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning), Times.Once);
}

[Fact]
Expand All @@ -87,8 +81,7 @@ public void SaveCurrentQuery_WhenNoCommandSelected_ShowsWarningMessage()
_viewModel.SaveCurrentQuery(null);

_messageBoxServiceMock.Verify(
m => m.Show(It.IsAny<string>(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning),
Times.Once);
m => m.Show(It.IsAny<string>(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning), Times.Once);
}

[Fact]
Expand All @@ -97,8 +90,7 @@ public void AddParameterComboBoxInQueryBuilder_WhenNoCommandSelected_ShowsWarnin
_viewModel.AddParameterComboBoxInQueryBuilder(null);

_messageBoxServiceMock.Verify(
m => m.Show(It.IsAny<string>(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning),
Times.Once);
m => m.Show(It.IsAny<string>(), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning), Times.Once);
}

[Fact]
Expand Down
15 changes: 5 additions & 10 deletions ActiveDirectoryQuerier.Tests/PSExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
102 changes: 33 additions & 69 deletions ActiveDirectoryQuerier/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
}

Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ad7f37b

Please sign in to comment.