From 96b2c83c59014bfa060532e9457edca6d88d0e74 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Thu, 16 Aug 2018 15:56:15 -0700 Subject: [PATCH] Update reference to use packages from NuGet.org (#7525) Update psrp and libpsl reference to Microsoft.PowerShell.Native Keep the reference to powershell.myget.org in nuget.config for PSDesiredStateConfiguration and PowerShellHelpFiles Update hosting tests Update hosting.tests.csproj in preparation on next release with version 6.1.0-rc.1 Update Microsoft.Management.Infrastructure to version 1.0.0 --- .../System.Management.Automation.csproj | 4 +- src/powershell-unix/powershell-unix.csproj | 2 - .../powershell-win-core.csproj | 9 +- test/hosting/NuGet.Config | 1 - test/hosting/hosting.tests.csproj | 4 +- test/hosting/test_HostingBasic.cs | 90 ++++++++++++++++++- 6 files changed, 98 insertions(+), 12 deletions(-) diff --git a/src/System.Management.Automation/System.Management.Automation.csproj b/src/System.Management.Automation/System.Management.Automation.csproj index 676781b770..2c8fec7681 100644 --- a/src/System.Management.Automation/System.Management.Automation.csproj +++ b/src/System.Management.Automation/System.Management.Automation.csproj @@ -21,8 +21,8 @@ - - + + diff --git a/src/powershell-unix/powershell-unix.csproj b/src/powershell-unix/powershell-unix.csproj index 3d59eb197b..f6b16e80d7 100644 --- a/src/powershell-unix/powershell-unix.csproj +++ b/src/powershell-unix/powershell-unix.csproj @@ -31,8 +31,6 @@ - - diff --git a/src/powershell-win-core/powershell-win-core.csproj b/src/powershell-win-core/powershell-win-core.csproj index 2e36ddb147..49e815b2e2 100644 --- a/src/powershell-win-core/powershell-win-core.csproj +++ b/src/powershell-win-core/powershell-win-core.csproj @@ -24,10 +24,10 @@ PreserveNewest PreserveNewest - - preview\pwsh-preview.cmd - PreserveNewest - + + preview\pwsh-preview.cmd + PreserveNewest + @@ -40,7 +40,6 @@ - diff --git a/test/hosting/NuGet.Config b/test/hosting/NuGet.Config index c2c6e1b7c2..c7d7696898 100644 --- a/test/hosting/NuGet.Config +++ b/test/hosting/NuGet.Config @@ -2,7 +2,6 @@ - diff --git a/test/hosting/hosting.tests.csproj b/test/hosting/hosting.tests.csproj index dfe9a9706f..a63fe941a9 100644 --- a/test/hosting/hosting.tests.csproj +++ b/test/hosting/hosting.tests.csproj @@ -18,7 +18,9 @@ - + + + diff --git a/test/hosting/test_HostingBasic.cs b/test/hosting/test_HostingBasic.cs index 90fb8c2f28..164f1f02aa 100644 --- a/test/hosting/test_HostingBasic.cs +++ b/test/hosting/test_HostingBasic.cs @@ -1,9 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using Xunit; using System; +using System.IO; using System.Management.Automation; +using System.Security; +using Microsoft.Management.Infrastructure; +using Xunit; namespace PowerShell.Hosting.SDK.Tests { @@ -51,5 +54,90 @@ namespace PowerShell.Hosting.SDK.Tests } } } + + [SkippableFact] + public static void TestCommandFromMMI() + { + // Test is disabled since we do not have a CimCmdlets module released in the SDK. + Skip.IfNot(Platform.IsWindows); + using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create()) + { + var results = ps.AddScript("[Microsoft.Management.Infrastructure.CimInstance]::new('Win32_Process')").Invoke(); + Assert.True(results.Count > 0); + } + } + + [SkippableFact] + public static void TestCommandFromDiagnostics() + { + Skip.IfNot(Platform.IsWindows); + using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create()) + { + var results = ps.AddScript("Get-WinEvent -ListLog Application").Invoke(); + + foreach (dynamic item in results) + { + Assert.Equal("Application", item.LogName); + } + } + } + + [SkippableFact] + public static void TestCommandFromSecurity() + { + Skip.IfNot(Platform.IsWindows); + using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create()) + { + var results = ps.AddScript("ConvertTo-SecureString -String test -AsPlainText -Force").Invoke(); + Assert.IsType(results[0]); + } + } + + [SkippableFact] + public static void TestCommandFromWSMan() + { + Skip.IfNot(Platform.IsWindows); + using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create()) + { + var results = ps.AddScript("Test-WSMan").Invoke(); + + foreach (dynamic item in results) + { + Assert.Equal("Microsoft Corporation", item.ProductVendor); + } + } + } + + [Fact] + public static void TestCommandFromNative() + { + var fs = File.Create(Path.GetTempFileName()); + fs.Close(); + + string target = fs.Name; + string path = Path.GetTempFileName(); + + using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create()) + { + // New-Item -ItemType SymbolicLink uses libpsl-native, hence using it for validating native dependencies. + string command = $"New-Item -ItemType SymbolicLink -Path {path} -Target {target}"; + var results = ps.AddScript(command).Invoke(); + + foreach (var item in results) + { + Assert.Equal(path, item.FullName); + } + } + + if (File.Exists(path)) + { + File.Delete(path); + } + + if (File.Exists(target)) + { + File.Delete(target); + } + } } }