Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions test/hosting/NuGet.Config
Original file line number Diff line number Diff line change
@@ -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>
24 changes: 24 additions & 0 deletions test/hosting/hosting.tests.csproj
Original file line number Diff line number Diff line change
@@ -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>
55 changes: 55 additions & 0 deletions test/hosting/test_HostingBasic.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
}