PlayNicely.Executor 1.0.0-prerelease-20240209-141858

This is a prerelease version of PlayNicely.Executor.
There is a newer version of this package available.
See the version list below for details.
dotnet add package PlayNicely.Executor --version 1.0.0-prerelease-20240209-141858                
NuGet\Install-Package PlayNicely.Executor -Version 1.0.0-prerelease-20240209-141858                
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="PlayNicely.Executor" Version="1.0.0-prerelease-20240209-141858">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PlayNicely.Executor --version 1.0.0-prerelease-20240209-141858                
#r "nuget: PlayNicely.Executor, 1.0.0-prerelease-20240209-141858"                
#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 PlayNicely.Executor as a Cake Addin
#addin nuget:?package=PlayNicely.Executor&version=1.0.0-prerelease-20240209-141858&prerelease

// Install PlayNicely.Executor as a Cake Tool
#tool nuget:?package=PlayNicely.Executor&version=1.0.0-prerelease-20240209-141858&prerelease                

Play Nicely Executor

The Play Nicely Executor project supports the execution of MSBuild test case projects within a pre-defined test case environment. Where you can define required commands, or exclude commands from the path (so you can force things to fail). This package is published independently having a solution that supports the creation of a reliable and clean environment, to run tool testing seems like a use case for many scenarios.

The main artefacts are the ITestEnvironment, which defines the environment and project that are available for testing. You create (build) an ITestEnvironment using the fluent interface TestEnvironmentBuilder. With this class you can define what can, and can't run, plus the target test case project. After building your ITestEnvironment you can pass it to a concrete implementation of the ITestEnvironmentRunner which executes the test and returns the outcome.

The current concrete ITestEnvironmentRunners are a basic ProcessRunner which excepts a command and arguments, much like a command line, and returns a basic IExecutionResult. And the DotNetRunner which executes a dotnet subcommand, with arguments, and returns a IExecutionResult<DotNetExecutionContext> which includes the dotnet command results context, targets ran, projects built, lists of errors, etc.

You can also define your own runners derived from ITestEnvironmentRunner.

This project came about to support the use of NodeJS packages within .NET projects in a .NET first way. You can acheive the integration of NodeJS tools using plugins or other tooling. The problem with this is, these can often become out of date or stale. Most of the NodeJS packages are actively developed by a community, so accessing the latest npm packages directly makes the most sense.

Getting Started

This getting started is provided in the context, for which, this package was developed. To support the testing of a NodeJS tools package within a MSBuild project.

The basic setup involves having a tools project, and an accompanying test project, I currently use SpecFlow. Develop your tools and targets in your tools project. The test project includes

Below here is not done.

If you are going to use this package, you probably want to define test cases for a NodeJS tool package. Before you start, it's a good idea to consider the best layout for your project so that you can use a familar development experience for test cases, i.e. Visual Studio, while also making the maintenance of the test case packages as simple as possible.

Our recommended project structure is (if you're using SpecFlow for testing):

solution-dir
|-- my-project	               # This is the project you are developing
|   |-- *
|-- my-project.Specs           # BDD Specifications for your project
|   |-- Features
|   |   |-- *.features
|   |-- TestCases.Projects     # Define your test case 'packages' in resx files
|       |-- Project1.resx
|       |-- Project2.resx
|       |-- TestCases.cs       # Helper class to load local test case projects from embedded resources
|-- TestCase.Projects          # Define your test case projects in here using familiar tools.
|   |-- Project1
|   |   |-- Project1.csproj
|   |-- Project2
|       |-- Project2.csproj
|-- my-solution.sln

We'll refer to this structure in the rest of this document.

Create your test case projects

Use visual studio to create you test case projects, as you would any other C# project. Add them to the solution-dir/TestCase.Projects directory. Add code files, define properties, etc. Typically, you do not want to build your test cases as part of the normal Visual Studio build command. To disable build use the solution Configuration Manager... to disable build on your test cases.

Define test case packages as embedded (resx) resources

For consistency, when running test cases, a clean temporary directory is created for each test run. This means build artefacts like obj or cached NuGet packages are not available, and ensures consistent test behaviour.

So a clean version of the project can be created, they need to be explicitly defined in embedded resource (resx) files.

  1. In your BDD project, my-project.Specs, under the TestCase.Projects directory, add a new resx file. It is not required, but is better for consistency, to name your resx the same as your actual project. In the example, above, Project1.resx matches Project1.csproj
  2. Disable code generation in your resx file.
  3. Add the relevant files from your test case project to your resx.
    1. In the resource editor, Add existing file...
    2. The default naming for added files, mangles the names and removes the extension. As we are trying to define files in a file system like format, you need to re-add the extension and also any directories, using / as a separator.
  4. If you have multiple projects in your test case, like you would in a solution, you can specify the target build project by adding a resource string to the resx called ProjectFile with the value being the path (within the context of the resx) to the project file. In the example above, for Project1.resx, the ProjectFile value would be Project1.csproj.

Add a test case helper

This might be simpler than you think, once we bring over the TestEnvironment stuff.

Use steps in your BDD project

This should probably be centralized also.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on PlayNicely.Executor:

Package Downloads
PlayNicely.Executor.DotNet

A framework that facilitates testing of Play Nicely functionality. Provides capability to execute dotnet commands, in a controlled environment, against test case projects.

PlayNicely.SpecFlow.Executor

SpecFlow bindings that allow you to run tests by executing programs against a pre-configured test environment.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.2-beta-550 87 10/4/2024
1.3.2-beta-543 90 9/28/2024
1.3.2-beta-535 94 9/28/2024
1.3.2-beta-529 84 9/23/2024
1.3.2-beta-518 100 9/21/2024
1.3.2-beta-511 83 9/20/2024
1.3.2-beta-509 87 9/20/2024
1.3.2-beta-507 78 9/20/2024
1.3.2-beta-505 85 9/19/2024
1.3.2-beta-501 96 9/18/2024
1.3.2-beta-499 89 9/18/2024
1.3.2-beta-496 87 9/18/2024
1.3.2-beta-494 96 9/18/2024
1.3.2-beta-492 102 9/18/2024
1.3.1 128 9/17/2024
1.3.1-beta-487 98 9/17/2024
1.3.0 126 9/14/2024
1.3.0-beta-479 102 9/14/2024
1.3.0-beta-472 106 9/14/2024
1.2.0 108 7/12/2024
1.2.0-beta-465 114 9/7/2024
1.2.0-beta-450 101 7/14/2024
1.2.0-beta-442 101 7/12/2024
1.1.1 132 6/1/2024
1.1.1-beta-432 98 7/11/2024
1.1.1-beta-418 111 6/1/2024
1.1.1-beta-398 109 6/1/2024
1.1.0 270 4/14/2024
1.1.0-beta-393 111 5/31/2024
1.1.0-beta-382 125 5/21/2024
1.1.0-beta-370 96 5/8/2024
1.1.0-beta-355 115 5/7/2024
1.1.0-beta-349 115 5/7/2024
1.1.0-beta-346 119 5/7/2024
1.1.0-beta-340 126 5/7/2024
1.1.0-beta-323 117 5/6/2024
1.1.0-beta-312 119 4/26/2024
1.1.0-beta-299 114 4/14/2024
1.1.0-beta-296 125 4/14/2024
1.0.4 165 4/11/2024
1.0.4-beta-287 118 4/11/2024
1.0.4-beta-282 125 4/11/2024
1.0.4-beta-280 124 4/10/2024
1.0.4-beta-278 123 4/10/2024
1.0.4-beta-276 109 4/10/2024
1.0.4-beta-274 134 4/9/2024
1.0.4-beta-272 125 4/9/2024
1.0.3 166 3/21/2024
1.0.3-beta-266 125 3/21/2024
1.0.3-beta-260 121 3/21/2024
1.0.2 185 3/10/2024
1.0.2-prerelease-20240301-0... 107 3/1/2024
1.0.2-beta-227 121 3/10/2024
1.0.2-beta-221 135 3/9/2024
1.0.2-beta-214 125 3/9/2024
1.0.2-beta-208 131 3/1/2024
1.0.2-beta-206 121 3/1/2024
1.0.1 119 2/29/2024
1.0.1-prerelease-20240229-1... 86 2/29/2024
1.0.1-prerelease-20240228-0... 88 2/28/2024
1.0.1-prerelease-20240226-1... 46 2/26/2024
1.0.1-prerelease-20240225-0... 52 2/25/2024
1.0.1-prerelease-20240225-0... 50 2/25/2024
1.0.0 483 2/10/2024
1.0.0-prerelease-20240210-1... 245 2/10/2024
1.0.0-prerelease-20240210-1... 225 2/10/2024
1.0.0-prerelease-20240209-1... 209 2/9/2024
1.0.0-prerelease-20240209-1... 230 2/9/2024
1.0.0-prerelease-20240209-1... 226 2/9/2024