Skip to content

Commit 2c3177a

Browse files
adityapatwardhandaxian-dbw
authored andcommitted
Add tests for PowerShell hosting API to verify MyGet packages (PowerShell#6737)
1 parent c5415d3 commit 2c3177a

3 files changed

Lines changed: 88 additions & 0 deletions

File tree

test/hosting/NuGet.Config

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<clear />
5+
<add key="powershell-core" value="https://powershell.myget.org/F/powershell-core/api/v3/index.json" />
6+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
7+
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
8+
</packageSources>
9+
</configuration>

test/hosting/hosting.tests.csproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Import Project="../Test.Common.props"/>
4+
5+
<PropertyGroup>
6+
<Description>PowerShell hosting SDK xUnit Tests</Description>
7+
<AssemblyName>powershell-hosting-tests</AssemblyName>
8+
<!--RuntimeIdentifiers>win7-x86;win7-x64;osx.10.12-x64;linux-x64</RuntimeIdentifiers-->
9+
</PropertyGroup>
10+
11+
<PropertyGroup>
12+
<DelaySign>true</DelaySign>
13+
<AssemblyOriginatorKeyFile>../../src/signing/visualstudiopublic.snk</AssemblyOriginatorKeyFile>
14+
<SignAssembly>true</SignAssembly>
15+
</PropertyGroup>
16+
17+
<ItemGroup>
18+
<PackageReference Include="xunit" Version="2.3.1" />
19+
<!-- DotNetCliToolReference element specifies the CLI tool that the user wants to restore in the context of the project. -->
20+
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
21+
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.0.2" />
22+
</ItemGroup>
23+
24+
</Project>

test/hosting/test_HostingBasic.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Xunit;
5+
using System;
6+
using System.Management.Automation;
7+
8+
namespace PowerShell.Hosting.SDK.Tests
9+
{
10+
public static class HostingTests
11+
{
12+
[Fact]
13+
public static void TestCommandFromUtility()
14+
{
15+
using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create())
16+
{
17+
var results = ps.AddScript("Get-Verb -Verb get").Invoke();
18+
19+
foreach (dynamic item in results)
20+
{
21+
Assert.Equal("Get", item.Verb);
22+
}
23+
}
24+
}
25+
26+
[Fact]
27+
public static void TestCommandFromManagement()
28+
{
29+
using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create())
30+
{
31+
var path = Environment.CurrentDirectory;
32+
var results = ps.AddCommand("Test-Path").AddParameter("Path", path).Invoke<bool>();
33+
34+
foreach (dynamic item in results)
35+
{
36+
Assert.True(item);
37+
}
38+
}
39+
}
40+
41+
[Fact]
42+
public static void TestCommandFromCore()
43+
{
44+
using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create())
45+
{
46+
var results = ps.AddScript(@"$i = 0 ; 1..3 | ForEach-Object { $i += $_} ; $i").Invoke<int>();
47+
48+
foreach (dynamic item in results)
49+
{
50+
Assert.Equal(6,item);
51+
}
52+
}
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)