PlayNicely.Projects 1.0.4-prerelease-20240226-104112

This is a prerelease version of PlayNicely.Projects.
There is a newer version of this package available.
See the version list below for details.
dotnet add package PlayNicely.Projects --version 1.0.4-prerelease-20240226-104112
                    
NuGet\Install-Package PlayNicely.Projects -Version 1.0.4-prerelease-20240226-104112
                    
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.Projects" Version="1.0.4-prerelease-20240226-104112">
  <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.
<PackageVersion Include="PlayNicely.Projects" Version="1.0.4-prerelease-20240226-104112" />
                    
Directory.Packages.props
<PackageReference Include="PlayNicely.Projects">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PlayNicely.Projects --version 1.0.4-prerelease-20240226-104112
                    
#r "nuget: PlayNicely.Projects, 1.0.4-prerelease-20240226-104112"
                    
#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.
#:package PlayNicely.Projects@1.0.4-prerelease-20240226-104112
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PlayNicely.Projects&version=1.0.4-prerelease-20240226-104112&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=PlayNicely.Projects&version=1.0.4-prerelease-20240226-104112&prerelease
                    
Install as a Cake Tool

Play Nicely Case Packer

The Play Nicely Case Packer project supports the definition and packaging (for reading or writing) of MSBuild Projects for use in release test cases. While this NuGet package can be used independently its development is a result of the Play Nicely MSBuild tools packages, e.g. NpmNpx or Sass.

Getting Started

This base package supports the definition of a TestCaseProject via a generic FileSystem interface. This interface allows for the definition of directories and files, and also the contents of those files.

The other artefacts support reading or writing of a TestCaseProject to media. At time of writing, the project supports reading from .NET assembly resources and writing to the physical file system. Implement concrete versions of IProjectPackageReader and IProjectPackageWriter if you have a specific media that you wish to support.

Defining Projects

The TestCaseProject class represents a virtual project, you can create a FileSystem by adding directories and files via the FileSystem object using it's fluent interface. You can also specify the ProjectFile from the same file system. Once defined the TestCaseProject doesn't do much on its own, but it is used by the PlayNicely.Executor package to run test cases.

var testCaseProject = new TestCaseProject("my-project");
var projectFile = testCaseProject.AddDirectory("project1")
                                 .AddFile("proj.csproj");

testCaseProject.ProjectFile = projectFile;

using(var writer = new StreamWriter(projectFile.OpenWriteStream()))
{
    writer.WriteLine("<Project Sdk=\"Microsoft.NET.Sdk\">");
    writer.WriteLine("  <PropertyGroup>");
    writer.WriteLine("    <TargetFramework>netstandard2.0</TargetFramework>");
    writer.WriteLine("  </PropertyGroup>");
    writer.WriteLine("</Project>");
}

Using Resource (resx) files

Building test case projects in code is fine, but there is already a tool to easily define and edit MSBuild projects, the IDE. To support this, Case Packer provides a IProjectPackageReader implementation for .NET resources. The basic idea is to add file resources to the resx file with names equivalent to the project file structure. The ResourceSetPackageReader can then be used to read a package into a test case project, including the file contents.

Example

If you have the following project structure...

solution-dir
|-- my-project.Specs           # BDD Specifications for your project
|   |-- TestCases.Projects     # Define your test case 'packages' in resx files
|       |-- Project1.resx
|-- TestCase.Projects          # Define your test case projects in here using familiar tools.
|   |-- Project1
|       |-- Project1.csproj
|       |-- Program.cs
|-- my-solution.sln

The .resx file should have the following resources defined

<?xml version="1.0" encoding="utf-8"?>
<root>
  <data name="Project1/Project1.csproj" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>Project1/Project1.csproj;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
  </data>
  <data name="Project1/Program.cs" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>Project1/Program.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
  </data>
</root>

And then to load these resources into a TestCaseProject you can...

internal static class TestCases
{
    // Where projectName is the same as the resx file name without the extension
    public static async Task<TestCaseProject> LoadAsync(string projectName, CancellationToken cancel)
    {
        ArgumentException.ThrowIfNullOrEmpty(projectName);
        cancel.ThrowIfCancellationRequested();

        var resourceManager = new ResourceManager($"{ResourceNamespace}.{projectName}", ResourceAssembly);

        using var resourceSet = resourceManager.GetResourceSet(CultureInfo.InvariantCulture, true, true)
            ?? throw new TestCaseException(string.Format(ContentRes.Error_ProjectNameDoesNotExist, projectName));
        using var reader = new ResourceSetBlobReader(resourceSet);

        var result = new TestCaseProject(projectName);

        await result.LoadFromAsync(reader, cancel);
        cancel.ThrowIfCancellationRequested();

        return result;
    }

    public static Assembly ResourceAssembly => _resourceAssembly.Value;
    public static string ResourceNamespace => _resourceNamespace.Value;

    private static readonly Lazy<Assembly> _resourceAssembly = new(() => typeof(TestCases).Assembly);
    private static readonly Lazy<string> _resourceNamespace = new(() => typeof(TestCases).Namespace ?? string.Empty);
}
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on PlayNicely.Projects:

Package Downloads
PlayNicely.Executor

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

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.3-beta-550 117 10/4/2024
1.1.3-beta-543 131 9/28/2024
1.1.3-beta-535 129 9/28/2024
1.1.3-beta-529 116 9/23/2024
1.1.3-beta-518 131 9/21/2024
1.1.3-beta-511 114 9/20/2024
1.1.3-beta-509 117 9/20/2024
1.1.3-beta-507 122 9/20/2024
1.1.3-beta-505 116 9/19/2024
1.1.3-beta-501 142 9/18/2024
1.1.3-beta-499 128 9/18/2024
1.1.3-beta-496 130 9/18/2024
1.1.2 194 9/17/2024
1.1.2-beta-494 123 9/18/2024
1.1.2-beta-492 135 9/18/2024
1.1.2-beta-487 133 9/17/2024
1.1.1 234 6/1/2024
1.1.1-beta-479 137 9/14/2024
1.1.1-beta-472 131 9/14/2024
1.1.1-beta-465 145 9/7/2024
1.1.1-beta-450 129 7/14/2024
1.1.1-beta-442 119 7/12/2024
1.1.1-beta-432 121 7/11/2024
1.1.1-beta-418 116 6/1/2024
1.1.1-beta-398 129 6/1/2024
1.1.0 140 5/6/2024
1.1.0-beta-393 139 5/31/2024
1.1.0-beta-382 147 5/21/2024
1.1.0-beta-370 145 5/8/2024
1.1.0-beta-355 149 5/7/2024
1.1.0-beta-349 149 5/7/2024
1.1.0-beta-346 152 5/7/2024
1.1.0-beta-340 146 5/7/2024
1.1.0-beta-323 137 5/6/2024
1.0.7 359 4/11/2024
1.0.7-beta-312 144 4/26/2024
1.0.7-beta-299 164 4/14/2024
1.0.7-beta-296 140 4/14/2024
1.0.7-beta-287 133 4/11/2024
1.0.7-beta-282 138 4/11/2024
1.0.7-beta-280 147 4/10/2024
1.0.7-beta-278 138 4/10/2024
1.0.7-beta-276 142 4/10/2024
1.0.7-beta-274 158 4/9/2024
1.0.7-beta-272 146 4/9/2024
1.0.6 184 3/21/2024
1.0.6-beta-266 142 3/21/2024
1.0.6-beta-260 140 3/21/2024
1.0.5 232 3/10/2024
1.0.5-prerelease-20240301-0... 126 3/1/2024
1.0.5-beta-227 145 3/10/2024
1.0.5-beta-221 154 3/9/2024
1.0.5-beta-214 151 3/9/2024
1.0.5-beta-208 146 3/1/2024
1.0.5-beta-206 139 3/1/2024
1.0.4 151 2/29/2024
1.0.4-prerelease-20240229-1... 102 2/29/2024
1.0.4-prerelease-20240228-0... 101 2/28/2024
1.0.4-prerelease-20240226-1... 133 2/26/2024