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
7 changes: 6 additions & 1 deletion src/code/InternalHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@ public static void SetTestHook(string property, object value)
var fieldInfo = typeof(InternalHooks).GetField(property, BindingFlags.Static | BindingFlags.NonPublic);
fieldInfo?.SetValue(null, value);
}

public static string GetUserString()
{
return Microsoft.PowerShell.PSResourceGet.Cmdlets.UserAgentInfo.UserAgentString();
}
}
}
}
6 changes: 1 addition & 5 deletions src/code/ServerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ internal static class UserAgentInfo
{
static UserAgentInfo()
{
using (System.Management.Automation.PowerShell ps = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace))
{
_psVersion = ps.AddScript("$PSVersionTable").Invoke<Hashtable>()[0]["PSVersion"].ToString();
}

_psVersion = System.Management.Automation.Runspaces.Runspace.DefaultRunspace.Version.ToString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we potentially need the null coalescing operator for any of these properties?

_psResourceGetVersion = typeof(UserAgentInfo).Assembly.GetName().Version.ToString();
_distributionChannel = System.Environment.GetEnvironmentVariable("POWERSHELL_DISTRIBUTION_CHANNEL") ?? "unknown";
}
Expand Down
10 changes: 10 additions & 0 deletions test/ConstrainedLanguageMode.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

# In future, we will add more tests to be executed in Constrained Language Mode.
Describe "Test UserAgentInfo" {
It "GetUserString returns a non-null, non-empty string" {
$userAgentString = [Microsoft.PowerShell.PSResourceGet.InternalHooks]::GetUserString()
$userAgentString | Should -Not -BeNullOrEmpty
}
}