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

Commit

Permalink
Merge pull request #92 from StrangeRanger/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
StrangeRanger authored Mar 1, 2024
2 parents 1109041 + 0a403a1 commit d6ab09b
Show file tree
Hide file tree
Showing 45 changed files with 2,152 additions and 1,139 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build-test-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Built Test
name: Build Test

on:
push:
Expand All @@ -9,12 +9,11 @@ jobs:
strategy:
matrix:
targetplatform: [x64]
#targetplatform: [x86, x64]

runs-on: windows-latest

env:
Project_File: FAFB-PowerShell-Tool\FAFB-PowerShell-Tool.csproj
Project_File: ActiveDirectoryQuerier\ActiveDirectoryQuerier.csproj

steps:
- name: Checkout
Expand All @@ -31,7 +30,8 @@ jobs:
Import-Module ActiveDirectory
- name: Dotnet Restore & Build
run: dotnet build $env:Project_File -c Debug -f net6.0-windows -r win-${{ matrix.targetplatform }}
run: dotnet build $env:Project_File -c Debug -f net8.0-windows -r win-${{ matrix.targetplatform }}

- name: Dotnet Test
run: dotnet test
- name: Dotnet Test with Coverage
run: |
dotnet test $env:Project_File --no-build
10 changes: 5 additions & 5 deletions .github/workflows/release-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: windows-latest

env:
Project_File: FAFB-PowerShell-Tool\FAFB-PowerShell-Tool.csproj
Project_File: ActiveDirectoryQuerier\ActiveDirectoryQuerier.csproj

steps:
- name: Checkout
Expand All @@ -29,16 +29,16 @@ jobs:

- name: Dotnet Build & Publish
run: |
dotnet build $env:Project_File -c Release -f net6.0-windows -r win-${{ matrix.targetplatform }}
dotnet publish $env:Project_File -c Release -f net6.0-windows -r win-${{ matrix.targetplatform }} -o ./publish/FAFB_PowerShell_Tool_${{ matrix.targetplatform }}
dotnet build $env:Project_File -c Release -f net8.0-windows -r win-${{ matrix.targetplatform }}
dotnet publish $env:Project_File -c Release -f net8.0-windows -r win-${{ matrix.targetplatform }} -o ./publish/ActiveDirectoryQuerier_${{ matrix.targetplatform }}
- name: Zip Release Files
run: Compress-Archive -Path .\publish\FAFB_PowerShell_Tool_${{ matrix.targetplatform }} -DestinationPath .\FAFB_PowerShell_Tool_${{ matrix.targetplatform }}.zip
run: Compress-Archive -Path .\publish\ActiveDirectoryQuerier_${{ matrix.targetplatform }} -DestinationPath .\ActiveDirectoryQuerier_${{ matrix.targetplatform }}.zip

- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
files: FAFB_PowerShell_Tool_${{ matrix.targetplatform }}.zip
files: ActiveDirectoryQuerier_${{ matrix.targetplatform }}.zip
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
16 changes: 8 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -476,14 +476,14 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk

.vscode/launch.json

.vscode/tasks.json
# Rider files
.idea

.idea/.idea.FAFB-PowerShell-Tool/.idea/indexLayout.xml

.idea/.idea.FAFB-PowerShell-Tool/.idea/workspace.xml

FAFB-PowerShell-Tool/FAFB-PowerShell-Tool-Output.txt
# VSCode files
.vscode/launch.json
.vscode/tasks.json

.idea/.idea.FAFB-PowerShell-Tool/.idea/
# Text and CSV files
*.txt
*.csv
31 changes: 31 additions & 0 deletions ActiveDirectoryQuerier.Tests/ActiveDirectoryCommandsTests.cs
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);
}
}
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>
46 changes: 46 additions & 0 deletions ActiveDirectoryQuerier.Tests/CommandParametersTests.cs
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);
}
}
105 changes: 105 additions & 0 deletions ActiveDirectoryQuerier.Tests/PowerShellExecutorTests.cs
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);
}
}
83 changes: 83 additions & 0 deletions ActiveDirectoryQuerier.Tests/RelayCommandTests.cs
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 -= (_, _) =>
{};
}
}
Loading

0 comments on commit d6ab09b

Please sign in to comment.