mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add tests for PowerShell hosting API to verify MyGet packages (#6737)
This commit is contained in:
committed by
Dongbo Wang
parent
c5415d31a6
commit
2c3177a08d
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<clear />
|
||||
<add key="powershell-core" value="https://powershell.myget.org/F/powershell-core/api/v3/index.json" />
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
|
||||
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="../Test.Common.props"/>
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>PowerShell hosting SDK xUnit Tests</Description>
|
||||
<AssemblyName>powershell-hosting-tests</AssemblyName>
|
||||
<!--RuntimeIdentifiers>win7-x86;win7-x64;osx.10.12-x64;linux-x64</RuntimeIdentifiers-->
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<DelaySign>true</DelaySign>
|
||||
<AssemblyOriginatorKeyFile>../../src/signing/visualstudiopublic.snk</AssemblyOriginatorKeyFile>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="xunit" Version="2.3.1" />
|
||||
<!-- DotNetCliToolReference element specifies the CLI tool that the user wants to restore in the context of the project. -->
|
||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
|
||||
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,55 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using Xunit;
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
|
||||
namespace PowerShell.Hosting.SDK.Tests
|
||||
{
|
||||
public static class HostingTests
|
||||
{
|
||||
[Fact]
|
||||
public static void TestCommandFromUtility()
|
||||
{
|
||||
using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create())
|
||||
{
|
||||
var results = ps.AddScript("Get-Verb -Verb get").Invoke();
|
||||
|
||||
foreach (dynamic item in results)
|
||||
{
|
||||
Assert.Equal("Get", item.Verb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestCommandFromManagement()
|
||||
{
|
||||
using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create())
|
||||
{
|
||||
var path = Environment.CurrentDirectory;
|
||||
var results = ps.AddCommand("Test-Path").AddParameter("Path", path).Invoke<bool>();
|
||||
|
||||
foreach (dynamic item in results)
|
||||
{
|
||||
Assert.True(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestCommandFromCore()
|
||||
{
|
||||
using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create())
|
||||
{
|
||||
var results = ps.AddScript(@"$i = 0 ; 1..3 | ForEach-Object { $i += $_} ; $i").Invoke<int>();
|
||||
|
||||
foreach (dynamic item in results)
|
||||
{
|
||||
Assert.Equal(6,item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user