mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
We have the public API `JsonObject.ConvertFromJson` to convert from JSON string in the PowerShell context. It would be good to have a public API for conversion to JSON. This PR refactors the `ConvertTo-Json` cmdlet to move the core implementation to `JsonObject.ConvertToJson`, and make `ConvertTo-Json` call that public method. This would help the Azure Function PowerShell worker. Currently, we depends on [calling the cmdlet](https://github.com/Azure/azure-functions-powershell-worker/blob/729710d2595b4b96abd4fa5a5547fe880e98bfa6/src/PowerShell/PowerShellManager.cs#L198-L205) to convert object to JSON which is expensive. Once we have the public method `JsonObject.ConvertToJson` exposed, we can call the API directly to avoid a command invocation. # Conflicts: # test/Test.Common.props
xUnit Tests
The folder contains xUnit tests for PowerShell Core project.
Running xUnit Tests
Go to the top level of the PowerShell repository and run full set of tests:
Start-PSxUnit inside a self-hosted copy of PowerShell.
Go to the test project folder and run dotnet test -c Release.
Use filter parameter to run only needed tests:
dotnet test -c Release --filter "FullyQualifiedName~UnitTest1 # Runs tests which have UnitTest1 in FullyQualifiedName
dotnet test --filter Name~TestMethod1 # Runs tests whose name contains TestMethod1
Creating xUnit Tests
Keep the folder structure that is for Pester ../../test/powershell and C# files ../../src.
Use namespace names started with PSTests.
namespace PSTests.YourNameSpace
{
}