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 #105 from StrangeRanger/dev
- Loading branch information
Showing
31 changed files
with
1,094 additions
and
925 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 |
---|---|---|
@@ -1,48 +1,51 @@ | ||
using System.Management.Automation.Runspaces; | ||
using ActiveDirectoryQuerier.ActiveDirectory; | ||
using ActiveDirectoryQuerier.PowerShell; | ||
// ReSharper disable InconsistentNaming | ||
// ReSharper disable ConvertConstructorToMemberInitializers | ||
|
||
namespace ActiveDirectoryQuerier.Tests; | ||
|
||
// ReSharper disable once InconsistentNaming | ||
public class ADCommandParametersTests | ||
{ | ||
[Fact] | ||
public void AvailableParameters_AvailableParametersNotPopulated_NoValidCommandProvided() | ||
private readonly ADCommandParameters _adCommandParameters; | ||
|
||
public ADCommandParametersTests() | ||
{ | ||
// Arrange | ||
ADCommandParameters adCommandParameters = new(); | ||
_adCommandParameters = new ADCommandParameters(); | ||
} | ||
|
||
[Fact] | ||
public void AvailableParameters_AvailableParametersNotPopulated_NoValidCommandProvided() | ||
{ | ||
// Assert | ||
Assert.Contains("No valid command provided", adCommandParameters.AvailableParameters); | ||
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); | ||
await _adCommandParameters.LoadAvailableParametersAsync(command); | ||
|
||
// Assert | ||
Assert.NotEmpty(adCommandParameters.AvailableParameters); | ||
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); | ||
await _adCommandParameters.LoadAvailableParametersAsync(command); | ||
|
||
// Assert | ||
Assert.Contains("-Name", adCommandParameters.AvailableParameters); | ||
Assert.Contains("-Id", adCommandParameters.AvailableParameters); | ||
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
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,90 @@ | ||
using ActiveDirectoryQuerier.PowerShell; | ||
// ReSharper disable ConvertConstructorToMemberInitializers | ||
|
||
namespace ActiveDirectoryQuerier.Tests; | ||
|
||
/// <remarks> | ||
/// Since ActiveDirectoryInfo executes Active Directory commands, and it's not guaranteed that the tests will be | ||
/// executed on an Active Directory domain, the output will vary in location (StdOut or StdErr) and content. Therefore, | ||
/// it's more important to test that something is returned rather than the actual contents of the output. | ||
/// </remarks> | ||
public class ActiveDirectoryInfoTests | ||
{ | ||
private readonly ActiveDirectoryInfo _adInfo = new(); | ||
|
||
[Fact] | ||
public async Task GetADUsers_ReturnsExpectedOutput() | ||
{ | ||
// Act | ||
PSOutput result = await _adInfo.AvailableOptions["Get user on domain"](); | ||
|
||
// Assert | ||
Assert.NotNull(result); | ||
|
||
if (result.HadErrors) | ||
{ | ||
Assert.True(result.StdErr.Count > 0); | ||
} | ||
else | ||
{ | ||
Assert.True(result.StdOut.Count > 0); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task GetADComputers_ReturnsExpectedOutput() | ||
{ | ||
// Act | ||
PSOutput result = await _adInfo.AvailableOptions["Get computers on domain"](); | ||
|
||
// Assert | ||
Assert.NotNull(result); | ||
|
||
if (result.HadErrors) | ||
{ | ||
Assert.True(result.StdErr.Count > 0); | ||
} | ||
else | ||
{ | ||
Assert.True(result.StdOut.Count > 0); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task GetADIPv4Addresses_ReturnsExpectedOutput() | ||
{ | ||
// Act | ||
PSOutput result = await _adInfo.AvailableOptions["Get IPv4 of each system on domain"](); | ||
|
||
// Assert | ||
Assert.NotNull(result); | ||
|
||
if (result.HadErrors) | ||
{ | ||
Assert.True(result.StdErr.Count > 0); | ||
} | ||
else | ||
{ | ||
Assert.True(result.StdOut.Count > 0); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task GetADIPv6Addresses_ReturnsExpectedOutput() | ||
{ | ||
// Act | ||
PSOutput result = await _adInfo.AvailableOptions["Get IPv6 of each system on domain"](); | ||
|
||
// Assert | ||
Assert.NotNull(result); | ||
|
||
if (result.HadErrors) | ||
{ | ||
Assert.True(result.StdErr.Count > 0); | ||
} | ||
else | ||
{ | ||
Assert.True(result.StdOut.Count > 0); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.