From 2c3177a08d141a426eebefd9712644bdfd430dd9 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Fri, 27 Apr 2018 13:25:33 -0700 Subject: [PATCH] Add tests for PowerShell hosting API to verify MyGet packages (#6737) --- test/hosting/NuGet.Config | 9 +++++ test/hosting/hosting.tests.csproj | 24 ++++++++++++++ test/hosting/test_HostingBasic.cs | 55 +++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 test/hosting/NuGet.Config create mode 100644 test/hosting/hosting.tests.csproj create mode 100644 test/hosting/test_HostingBasic.cs diff --git a/test/hosting/NuGet.Config b/test/hosting/NuGet.Config new file mode 100644 index 0000000000..c2c6e1b7c2 --- /dev/null +++ b/test/hosting/NuGet.Config @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/test/hosting/hosting.tests.csproj b/test/hosting/hosting.tests.csproj new file mode 100644 index 0000000000..a8f232860d --- /dev/null +++ b/test/hosting/hosting.tests.csproj @@ -0,0 +1,24 @@ + + + + + + PowerShell hosting SDK xUnit Tests + powershell-hosting-tests + + + + + true + ../../src/signing/visualstudiopublic.snk + true + + + + + + + + + + diff --git a/test/hosting/test_HostingBasic.cs b/test/hosting/test_HostingBasic.cs new file mode 100644 index 0000000000..90fb8c2f28 --- /dev/null +++ b/test/hosting/test_HostingBasic.cs @@ -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(); + + 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(); + + foreach (dynamic item in results) + { + Assert.Equal(6,item); + } + } + } + } +}