AutomationIoC.PSCmdlets.Tools
2.1.0-alpha2
Suggested Alternatives
This is a prerelease version of AutomationIoC.PSCmdlets.Tools.
dotnet add package AutomationIoC.PSCmdlets.Tools --version 2.1.0-alpha2
NuGet\Install-Package AutomationIoC.PSCmdlets.Tools -Version 2.1.0-alpha2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AutomationIoC.PSCmdlets.Tools" Version="2.1.0-alpha2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AutomationIoC.PSCmdlets.Tools --version 2.1.0-alpha2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AutomationIoC.PSCmdlets.Tools, 2.1.0-alpha2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AutomationIoC.PSCmdlets.Tools as a Cake Addin #addin nuget:?package=AutomationIoC.PSCmdlets.Tools&version=2.1.0-alpha2&prerelease // Install AutomationIoC.PSCmdlets.Tools as a Cake Tool #tool nuget:?package=AutomationIoC.PSCmdlets.Tools&version=2.1.0-alpha2&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
AutomationIoC.PSCmdlets.Tools
Tooling for running/testing C# PowerShell Cmdlets
Requirements
- .NET 7 or .NET 6
- PowerShell 7.3 or greater
Getting Started
Installation
dotnet add package AutomationIoC.PSCmdlets.Tools
Testing AutomationIoC PSCmdlets
Sample AutomationIoC PSCmdlet startup class
public class Startup : IoCStartup
{
// Add any configuration sources or data needed
public override void Configure(IConfigurationBuilder configurationBuilder)
{
// AutomationEnvironment class allows retrieving global PowerShell
// variables during service configuration.
var environment =
AutomationEnvironment.GetVariable<string>("AppEnvironment");
var appSettings = new Dictionary<string, string>()
{
["TestOptionsConfig:TestProperty"] = "This is an example",
["AppEnvironment"] = environment
};
configurationBuilder.AddInMemoryCollection(appSettings);
}
// Configure services/lifetimes
public override void ConfigureServices(IServiceCollection services)
{
services.Configure<TestOptions>(Configuration.GetSection("TestOptionsConfig"));
services.AddTransient<ITestDependencyOne, TestDependencyOne>();
services.AddTransient<ITestDependencyTwo, TestDependencyTwo>();
// ...
// other services, client, etc.
}
}
Sample AutomationIoC PSCmdlet to test
[Cmdlet(VerbsLifecycle.Submit, "Data")]
public class SubmitData : IoCShell<Startup>
{
[Parameter(Mandatory = true)]
public string Id { get; set; }
[AutomationDependency]
protected ITestDependencyOne TestDependencyOne { get; set; }
[AutomationDependency]
protected ITestDependencyTwo testDependencyTwo { get; set; }
[AutomationDependency]
private ILogger<RequestCard> logger { get; set; }
protected override void ProcessRecord()
{
base.ProcessRecord();
TestDependencyOne.PushTestId(Id);
TestData testData = testDependencyTwo.GetTestData(Id);
logger.LogInformation("Auto Generated Data: {Id} - {Name}", Id, testData.Name);
WriteObject(testData);
}
}
Sample Test
using AutomationIoC.PSCmdlets.Tools;
using FluentAssertions;
using Xunit;
public class RequestCardTests
{
[Fact]
public void ShouldSubmitData()
{
var testDependencyOneMock = new Mock<ITestDependencyOne>();
var testDependencyTwoMock = new Mock<ITestDependencyTwo>();
var testId = "ThisIsATestId";
var expectedTestData = new TestData { Id = testId, Name = "ThisIsTestName" };
testDependencyTwoMock.Setup(dependency =>
dependency.GetTestDataAsync(testId))
.Returns(expectedTestData);
// Creates inline context of the command under test
using var submitDataCommand =
AutomationSandbox.CreateContext<SubmitData, Startup>(services =>
{
services.AddTransient(_ => testDependencyOneMock.Object);
services.AddTransient(_ => testDependencyTwoMock.Object);
});
submitDataCommand.AddParameter(command =>
command.AddParameter("id", testId));
var actualTestData = submitDataCommand.RunCommand<TestData>().First();
actualTestData.Should().BeEquivalentTo(expectedTestData);
}
}
Other Resources
Related Packages
Package | Description |
---|---|
AutomationIoC.PSCmdlets | Dependency Injection Framework for C# PowerShell Cmdlets |
AutomationIoC | Framework Runtime for AutomationIoC Console Applications and PowerShell Cmdlets |
AutomationIoC.Consoles | Dependency Injection Framework for C# Console Applications |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- AutomationIoC.PSCmdlets (>= 2.1.0-alpha2)
- Microsoft.PowerShell.SDK (>= 7.2.7)
-
net7.0
- AutomationIoC.PSCmdlets (>= 2.1.0-alpha2)
- Microsoft.PowerShell.SDK (>= 7.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
2.1.0-alpha2 | 138 | 8/12/2023 | |
2.1.0-alpha1 | 98 | 6/16/2023 | |
2.0.0-preview1 | 91 | 6/16/2023 | |
2.0.0-alpha1 | 89 | 6/10/2023 |