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 #92 from StrangeRanger/dev
- Loading branch information
Showing
45 changed files
with
2,152 additions
and
1,139 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
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
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
31 changes: 31 additions & 0 deletions
31
ActiveDirectoryQuerier.Tests/ActiveDirectoryCommandsTests.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,31 @@ | ||
using System.Collections.ObjectModel; | ||
using System.Management.Automation.Runspaces; | ||
using ActiveDirectoryQuerier.PowerShell; | ||
|
||
namespace ActiveDirectoryQuerier.Tests; | ||
|
||
public class ActiveDirectoryCommandsTests | ||
{ | ||
[Fact] | ||
public async Task GetActiveDirectoryCommands_ReturnsCommandList_IsNotEmpty() | ||
{ | ||
// Act | ||
ObservableCollection<Command> commandList = await ActiveDirectoryCommands.GetActiveDirectoryCommands(); | ||
|
||
// Assert | ||
Assert.NotEmpty(commandList); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Get-ADUser")] | ||
[InlineData("Get-ADGroup")] | ||
[InlineData("Get-ADComputer")] | ||
public async Task GetActiveDirectoryCommands_ReturnsCommandList_ContainsCommand(string commandName) | ||
{ | ||
// Act | ||
ObservableCollection<Command> commandList = await ActiveDirectoryCommands.GetActiveDirectoryCommands(); | ||
|
||
// Assert | ||
Assert.Contains(commandList, cmd => cmd.CommandText == commandName); | ||
} | ||
} |
17 changes: 7 additions & 10 deletions
17
...l.Tests/FAFB-PowerShell-Tool.Tests.csproj → ...Tests/ActiveDirectoryQuerier.Tests.csproj
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 |
---|---|---|
@@ -1,28 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0-windows</TargetFramework> | ||
<RootNamespace>FAFB_PowerShell_Tool.Tests</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<AssemblyName>ActiveDirectoryQuerier.Tests</AssemblyName> | ||
<RootNamespace>ActiveDirectoryQuerier.Tests</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0"/> | ||
<PackageReference Include="xunit" Version="2.4.1"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" /> | ||
<PackageReference Include="xunit" Version="2.7.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<PackageReference Include="coverlet.collector" Version="6.0.1"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\FAFB-PowerShell-Tool\FAFB-PowerShell-Tool.csproj" /> | ||
<ProjectReference Include="..\ActiveDirectoryQuerier\ActiveDirectoryQuerier.csproj" /> | ||
</ItemGroup> | ||
</Project> |
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,46 @@ | ||
using System.Management.Automation.Runspaces; | ||
using ActiveDirectoryQuerier.PowerShell; | ||
|
||
namespace ActiveDirectoryQuerier.Tests; | ||
|
||
public class CommandParametersTests | ||
{ | ||
[Fact] | ||
public void PossibleParameters_LoadCommandParametersAsyncNotPopulated_ThrowInvalidOperationException() | ||
{ | ||
// Arrange | ||
CommandParameters commandParameters = new(); | ||
|
||
// Assert | ||
Assert.Throws<InvalidOperationException>(() => commandParameters.PossibleParameters); | ||
} | ||
|
||
[Fact] | ||
public async Task LoadCommandParametersAsync_PopulatesPossibleParameters_IsNotEmpty() | ||
{ | ||
// Arrange | ||
CommandParameters commandParameters = new(); | ||
Command command = new("Get-Process"); | ||
|
||
// Act | ||
await commandParameters.LoadCommandParametersAsync(command); | ||
|
||
// Assert | ||
Assert.NotEmpty(commandParameters.PossibleParameters); | ||
} | ||
|
||
[Fact] | ||
public async Task LoadCommandParametersAsync_CheckPossibleParameter_ContentIsCorrect() | ||
{ | ||
// Arrange | ||
CommandParameters commandParameters = new(); | ||
Command command = new("Get-Process"); | ||
|
||
// Act | ||
await commandParameters.LoadCommandParametersAsync(command); | ||
|
||
// Assert | ||
Assert.Contains("-Name", commandParameters.PossibleParameters); | ||
Assert.Contains("-Id", commandParameters.PossibleParameters); | ||
} | ||
} |
File renamed without changes.
105 changes: 105 additions & 0 deletions
105
ActiveDirectoryQuerier.Tests/PowerShellExecutorTests.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,105 @@ | ||
using System.Management.Automation.Runspaces; | ||
using ActiveDirectoryQuerier.PowerShell; | ||
|
||
namespace ActiveDirectoryQuerier.Tests; | ||
|
||
public class PowerShellExecutorTests | ||
{ | ||
[Theory] | ||
[InlineData("Get-Command", "Module", "ActiveDirectory")] | ||
[InlineData("Get-Process", "Name", "explorer")] | ||
public void Execute_WhenGivenValidCommand_ReturnsExpectedOutput(string cmd, string paramName, string paramValue) | ||
{ | ||
// Arrange | ||
Command command = new(cmd); | ||
command.Parameters.Add(paramName, paramValue); | ||
PowerShellExecutor powerShellExecutor = new(); | ||
|
||
// Act | ||
ReturnValues result = powerShellExecutor.Execute(command); | ||
|
||
// Assert | ||
Assert.False(result.HadErrors); | ||
Assert.Empty(result.StdErr); | ||
Assert.NotEmpty(result.StdOut); | ||
} | ||
|
||
[Fact] | ||
public void Execute_CheckIfOutputChanged_ReturnsDifferentOutput() | ||
{ | ||
// Arrange | ||
Command command = new("Get-Command"); | ||
command.Parameters.Add("Module", "ActiveDirectory"); | ||
Command command2 = new("Get-Process"); | ||
command.Parameters.Add("Name", "explorer"); | ||
PowerShellExecutor powerShellExecutor = new(); | ||
|
||
// Act | ||
ReturnValues result = powerShellExecutor.Execute(command); | ||
ReturnValues result2 = powerShellExecutor.Execute(command2); | ||
|
||
// Assert | ||
Assert.NotEqual(result, result2); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Get-Command", "Module", "ActiveDirectory")] | ||
[InlineData("Get-Process", "Name", "explorer")] | ||
public async Task ExecuteAsync_WhenGivenValidCommand_ReturnsExpectedOutput(string cmd, | ||
string paramName, | ||
string paramValue) | ||
{ | ||
// Arrange | ||
Command command = new(cmd); | ||
command.Parameters.Add(paramName, paramValue); | ||
PowerShellExecutor powerShellExecutor = new(); | ||
|
||
// Act | ||
ReturnValues result = await powerShellExecutor.ExecuteAsync(command); | ||
|
||
// Assert | ||
Assert.False(result.HadErrors); | ||
Assert.Empty(result.StdErr); | ||
Assert.NotEmpty(result.StdOut); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Get-ADUser", "InvalidParameter", "*")] | ||
[InlineData("InvalidCommand", "Filter", "*")] | ||
public void Execute_WhenGivenInvalidCommand_ReturnsExpectedOutput(string cmd, string paramName, string paramValue) | ||
{ | ||
// Arrange | ||
Command command = new(cmd); | ||
command.Parameters.Add(paramName, paramValue); | ||
PowerShellExecutor powerShellExecutor = new(); | ||
|
||
// Act | ||
ReturnValues result = powerShellExecutor.Execute(command); | ||
|
||
// Assert | ||
Assert.True(result.HadErrors); | ||
Assert.NotEmpty(result.StdErr); | ||
Assert.Empty(result.StdOut); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Get-ADUser", "InvalidParameter", "*")] | ||
[InlineData("InvalidCommand", "Filter", "*")] | ||
public async Task ExecuteAsync_WhenGivenInvalidCommand_ReturnsExpectedOutput(string cmd, | ||
string paramName, | ||
string paramValue) | ||
{ | ||
// Arrange | ||
Command command = new(cmd); | ||
command.Parameters.Add(paramName, paramValue); | ||
PowerShellExecutor powerShellExecutor = new(); | ||
|
||
// Act | ||
ReturnValues result = await powerShellExecutor.ExecuteAsync(command); | ||
|
||
// Assert | ||
Assert.True(result.HadErrors); | ||
Assert.NotEmpty(result.StdErr); | ||
Assert.Empty(result.StdOut); | ||
} | ||
} |
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 @@ | ||
namespace ActiveDirectoryQuerier.Tests; | ||
|
||
public class RelayCommandTests | ||
{ | ||
[Fact] | ||
public void CanExecute_WithNullPredicate_ReturnsTrue() | ||
{ | ||
RelayCommand command = new( | ||
_ => | ||
{}); | ||
Assert.True(command.CanExecute(null)); | ||
} | ||
|
||
[Fact] | ||
public void CanExecute_WithNonNullPredicate_ReturnsTrue() | ||
{ | ||
RelayCommand command = new( | ||
_ => | ||
{}, | ||
_ => true); | ||
Assert.True(command.CanExecute(null)); | ||
} | ||
|
||
[Fact] | ||
public void CanExecute_WithNonNullPredicate_ReturnsFalse() | ||
{ | ||
RelayCommand command = new( | ||
_ => | ||
{}, | ||
_ => false); | ||
Assert.False(command.CanExecute(null)); | ||
} | ||
|
||
[Fact] | ||
public void Execute_WithNullParameter_Executes() | ||
{ | ||
bool executed = false; | ||
RelayCommand command = new( | ||
_ => executed = true); | ||
command.Execute(null); | ||
Assert.True(executed); | ||
} | ||
|
||
[Fact] | ||
public void Execute_WithNonNullParameter_Executes() | ||
{ | ||
bool executed = false; | ||
RelayCommand command = new( | ||
_ => executed = true); | ||
command.Execute("test"); | ||
Assert.True(executed); | ||
} | ||
|
||
[Fact] | ||
public void RaiseCanExecuteChanged_WithNullParameter_DoesNotThrow() | ||
{ | ||
RelayCommand command = new( | ||
_ => | ||
{}); | ||
command.RaiseCanExecuteChanged(); | ||
} | ||
|
||
[Fact] | ||
public void CanExecuteChanged_WithNullParameter_DoesNotThrow() | ||
{ | ||
RelayCommand command = new( | ||
_ => | ||
{}); | ||
command.CanExecuteChanged += (_, _) => | ||
{}; | ||
} | ||
|
||
[Fact] | ||
public void CanExecuteChanged_WithNullParameter_DoesNotThrow2() | ||
{ | ||
RelayCommand command = new( | ||
_ => | ||
{}); | ||
// ReSharper disable once EventUnsubscriptionViaAnonymousDelegate | ||
command.CanExecuteChanged -= (_, _) => | ||
{}; | ||
} | ||
} |
Oops, something went wrong.