This repository has been archived by the owner on Dec 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from StrangeRanger/dev
- Loading branch information
Showing
34 changed files
with
1,472 additions
and
1,382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Management.Automation.Runspaces; | ||
using ActiveDirectoryQuerier.ActiveDirectory; | ||
using ActiveDirectoryQuerier.PowerShell; | ||
|
||
namespace ActiveDirectoryQuerier.Tests; | ||
|
||
// ReSharper disable once InconsistentNaming | ||
public class ADCommandParametersTests | ||
{ | ||
[Fact] | ||
public void AvailableParameters_AvailableParametersNotPopulated_NoValidCommandProvided() | ||
{ | ||
// Arrange | ||
ADCommandParameters adCommandParameters = new(); | ||
|
||
// Assert | ||
Assert.Contains("No valid command provided", adCommandParameters.AvailableParameters); | ||
} | ||
|
||
[Fact] | ||
public async Task LoadAvailableParametersAsync_PopulatesAvailableParameters_IsNotEmpty() | ||
{ | ||
// Arrange | ||
ADCommandParameters adCommandParameters = new(); | ||
Command command = new("Get-Process"); | ||
|
||
// Act | ||
await adCommandParameters.LoadAvailableParametersAsync(command); | ||
|
||
// Assert | ||
Assert.NotEmpty(adCommandParameters.AvailableParameters); | ||
} | ||
|
||
[Fact] | ||
public async Task LoadAvailableParametersAsync_CheckAvailableParameters_ContainsNameAndId() | ||
{ | ||
// Arrange | ||
ADCommandParameters adCommandParameters = new(); | ||
Command command = new("Get-Process"); | ||
|
||
// Act | ||
await adCommandParameters.LoadAvailableParametersAsync(command); | ||
|
||
// Assert | ||
Assert.Contains("-Name", adCommandParameters.AvailableParameters); | ||
Assert.Contains("-Id", adCommandParameters.AvailableParameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Collections.ObjectModel; | ||
using System.Management.Automation.Runspaces; | ||
using ActiveDirectoryQuerier.ActiveDirectory; | ||
using ActiveDirectoryQuerier.PowerShell; | ||
|
||
namespace ActiveDirectoryQuerier.Tests; | ||
|
||
// ReSharper disable once InconsistentNaming | ||
public class ADCommandsFetcherTests | ||
{ | ||
[Fact] | ||
public async Task GetADCommands_ReturnsCommandList_IsNotEmpty() | ||
{ | ||
// Act | ||
ObservableCollection<Command> adCommands = await ADCommandsFetcher.GetADCommands(); | ||
|
||
// Assert | ||
Assert.NotEmpty(adCommands); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Get-ADUser")] | ||
[InlineData("Get-ADGroup")] | ||
[InlineData("Get-ADComputer")] | ||
public async Task GetADCommands_ReturnsCommandList_ContainsCommand(string commandName) | ||
{ | ||
// Act | ||
ObservableCollection<Command> adCommands = await ADCommandsFetcher.GetADCommands(); | ||
|
||
// Assert | ||
Assert.Contains(adCommands, command => command.CommandText == commandName); | ||
} | ||
} |
31 changes: 0 additions & 31 deletions
31
ActiveDirectoryQuerier.Tests/ActiveDirectoryCommandsTests.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System.Management.Automation.Runspaces; | ||
using ActiveDirectoryQuerier.PowerShell; | ||
|
||
namespace ActiveDirectoryQuerier.Tests; | ||
|
||
public class AppConsoleTests : IDisposable | ||
{ | ||
// TODO: Make sure this is how I should perform cleanups... | ||
public void Dispose() | ||
{ | ||
if (File.Exists("output.txt")) | ||
{ | ||
File.Delete("output.txt"); | ||
} | ||
|
||
if (File.Exists("output.csv")) | ||
{ | ||
File.Delete("output.csv"); | ||
} | ||
|
||
GC.SuppressFinalize(this); | ||
} | ||
|
||
private static async Task<(AppConsole, PSOutput)> ExecuteCommandAsync(Command command) | ||
{ | ||
PSExecutor psExecutor = new(); | ||
AppConsole appConsole = new(); | ||
PSOutput result = await psExecutor.ExecuteAsync(command); | ||
|
||
appConsole.Append(result.HadErrors ? result.StdErr : result.StdOut); | ||
|
||
return (appConsole, result); | ||
} | ||
|
||
[Fact] | ||
public async Task ClearConsole_ClearsConsole_SuccessfullyCleared() | ||
{ | ||
// Arrange | ||
Command command = new("Get-Process"); | ||
command.Parameters.Add("Name", "explorer"); | ||
var (appConsole, _) = await ExecuteCommandAsync(command); | ||
|
||
// Act | ||
appConsole.Clear(); | ||
|
||
// Assert | ||
Assert.Empty(appConsole.ConsoleOutput); | ||
} | ||
|
||
[Fact] | ||
public void Append_AppendsStringToConsole_SuccessfullyAppended() | ||
{ | ||
// Arrange | ||
AppConsole appConsole = new(); | ||
const string output = "Output"; | ||
|
||
// Act | ||
appConsole.Append(output); | ||
|
||
// Assert | ||
Assert.Equal(output, appConsole.ConsoleOutput); | ||
} | ||
|
||
[Fact] | ||
public async Task ExportToText_ExportToText_SuccessfullyExported() | ||
{ | ||
// Arrange | ||
Command command = new("Get-Process"); | ||
command.Parameters.Add("Name", "explorer"); | ||
var (appConsole, returnValues) = await ExecuteCommandAsync(command); | ||
|
||
// Act | ||
appConsole.ExportToText(); | ||
string fileContents = await File.ReadAllTextAsync("output.txt"); | ||
|
||
// Assert | ||
Assert.True(File.Exists("output.txt")); | ||
|
||
Assert.Equal(returnValues.HadErrors ? string.Join(Environment.NewLine, returnValues.StdErr) | ||
: string.Join(Environment.NewLine, returnValues.StdOut), | ||
fileContents); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
ActiveDirectoryQuerier.Tests/ComboBoxParameterViewModelTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System.Collections.ObjectModel; | ||
using System.Management.Automation.Runspaces; | ||
using ActiveDirectoryQuerier.ActiveDirectory; | ||
using ActiveDirectoryQuerier.PowerShell; | ||
using ActiveDirectoryQuerier.ViewModels; | ||
|
||
namespace ActiveDirectoryQuerier.Tests; | ||
|
||
public class ComboBoxParameterViewModelTests | ||
{ | ||
[Fact] | ||
public async Task ComboBoxParameterViewModel_WhenConstructed_PossibleParametersIsNotNullOrEmpty() | ||
{ | ||
// Arrange | ||
Command command = new("Get-ADUser"); | ||
ADCommandParameters adCommandParameters = new(); | ||
ComboBoxParameterViewModel comboBoxParameterViewModel; | ||
|
||
// Act | ||
await adCommandParameters.LoadAvailableParametersAsync(command); | ||
comboBoxParameterViewModel = new(adCommandParameters.AvailableParameters); | ||
|
||
// Assert | ||
Assert.NotNull(comboBoxParameterViewModel.AvailableParameters); | ||
Assert.NotEmpty(comboBoxParameterViewModel.AvailableParameters); | ||
} | ||
|
||
[Fact] | ||
public async Task ComboBoxParameterViewModel_WhenConstructed_PossibleParametersContainsExpectedParameters() | ||
{ | ||
// Arrange | ||
Command command = new("Get-ADUser"); | ||
ADCommandParameters adCommandParameters = new(); | ||
ComboBoxParameterViewModel comboBoxParameterViewModel; | ||
|
||
// Act | ||
await adCommandParameters.LoadAvailableParametersAsync(command); | ||
comboBoxParameterViewModel = new(adCommandParameters.AvailableParameters); | ||
|
||
// Assert | ||
Assert.Contains(comboBoxParameterViewModel.AvailableParameters, param => param == "-Filter"); | ||
Assert.Contains(comboBoxParameterViewModel.AvailableParameters, param => param == "-Identity"); | ||
Assert.Contains(comboBoxParameterViewModel.AvailableParameters, param => param == "-LDAPFilter"); | ||
Assert.Contains(comboBoxParameterViewModel.AvailableParameters, param => param == "-SearchBase"); | ||
Assert.Contains(comboBoxParameterViewModel.AvailableParameters, param => param == "-SearchScope"); | ||
} | ||
|
||
[Fact] | ||
public async Task ComboBoxParameterViewModel_WhenSelectedParameterChosen_SelectedParameterIsSet() | ||
{ | ||
// Arrange | ||
string selectedParameter; | ||
Command command = new("Get-ADUser"); | ||
ADCommandParameters adCommandParameters = new(); | ||
ComboBoxParameterViewModel comboBoxParameterViewModel; | ||
|
||
// Act | ||
await adCommandParameters.LoadAvailableParametersAsync(command); | ||
comboBoxParameterViewModel = new(adCommandParameters.AvailableParameters); | ||
selectedParameter = comboBoxParameterViewModel.AvailableParameters[0]; | ||
comboBoxParameterViewModel.SelectedParameter = selectedParameter; | ||
|
||
// Assert | ||
Assert.Equal(selectedParameter, comboBoxParameterViewModel.SelectedParameter); | ||
} | ||
|
||
[Fact] | ||
public void ComboBoxParameterViewModel_WhenConstructedWithNullPossibleParameters_ThrowsArgumentNullException() | ||
{ | ||
// Arrange | ||
ObservableCollection<string> possibleParameters = null!; | ||
|
||
// Assert | ||
Assert.Throws<ArgumentNullException>(() => new ComboBoxParameterViewModel(possibleParameters)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.