Files
PowerToys/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal.UnitTests/TerminalHelperTests.cs

67 lines
3.0 KiB
C#
Raw Normal View History

// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.IO;
using System.Text.Json;
[build]Update to .net 6 framework and VS 2022 (#15741) * Update release.yml * Update ColorPickerUI.csproj * Update release.yml adding in .net6 sdk and moving stuff sooner * Update release.yml * Update release.yml * fixing test * Forcing vs17 and adding in .net 6 sdk * forcing pool * fixing issues in each pipeline * moving release .net up * fixing diff on agent version for nuget installer * Removing system.text.json.dll as included now * getting unit tests it looks like to work * updating everythign to .net 6 minus wxs for runtime * unit test still have * getting 6.0 stuff up and going. Terminal Unit tests have file max length issue .... * found i think the last .net 5 issue * looks like i wasn't aggressive enough with the 6.0 upgrade * Getting stuff .net 6 buildable again * tweaking with new stuff for installer * Update newly added merged projects to .net 6 * Fix HeatDirectory bug on VS 2022 * Settings still needs JSON dependency * Revert "getting 6.0 stuff up and going. Terminal Unit tests have file max length issue ...." This reverts commit b9cb4586dcaf693272b8bd895fc19783421262cc. * Update sln version * supress obsolete warning, since this is not a new development * Partially Revert "Getting stuff .net 6 buildable again" This reverts commit 42b4201c6bb36354fb9d7d7935403dcb5b45a17c. * supress another obsolete warning, since this is not a new development * Reduce the unit test project name to avoid MAX PATH in CI * Upgrade project's toolset in the main solution * Some TODOs to review HttpClient usage * Upgrade project toolsets from other solutions * Install .net 6 instead of .net 5 * Fix issue when disabling PowerToys Run on .net framework 6 * Update docs for Visual Studio 2022 * PR comments: manually upgrade missing VS 2019 references * Discard no discard values to solve compiler warnings Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
2022-02-07 06:08:30 -08:00
using Microsoft.PowerToys.Run.Plugin.WindowsTerminal;
using Microsoft.PowerToys.Run.Plugin.WindowsTerminal.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[build]Update to .net 6 framework and VS 2022 (#15741) * Update release.yml * Update ColorPickerUI.csproj * Update release.yml adding in .net6 sdk and moving stuff sooner * Update release.yml * Update release.yml * fixing test * Forcing vs17 and adding in .net 6 sdk * forcing pool * fixing issues in each pipeline * moving release .net up * fixing diff on agent version for nuget installer * Removing system.text.json.dll as included now * getting unit tests it looks like to work * updating everythign to .net 6 minus wxs for runtime * unit test still have * getting 6.0 stuff up and going. Terminal Unit tests have file max length issue .... * found i think the last .net 5 issue * looks like i wasn't aggressive enough with the 6.0 upgrade * Getting stuff .net 6 buildable again * tweaking with new stuff for installer * Update newly added merged projects to .net 6 * Fix HeatDirectory bug on VS 2022 * Settings still needs JSON dependency * Revert "getting 6.0 stuff up and going. Terminal Unit tests have file max length issue ...." This reverts commit b9cb4586dcaf693272b8bd895fc19783421262cc. * Update sln version * supress obsolete warning, since this is not a new development * Partially Revert "Getting stuff .net 6 buildable again" This reverts commit 42b4201c6bb36354fb9d7d7935403dcb5b45a17c. * supress another obsolete warning, since this is not a new development * Reduce the unit test project name to avoid MAX PATH in CI * Upgrade project's toolset in the main solution * Some TODOs to review HttpClient usage * Upgrade project toolsets from other solutions * Install .net 6 instead of .net 5 * Fix issue when disabling PowerToys Run on .net framework 6 * Update docs for Visual Studio 2022 * PR comments: manually upgrade missing VS 2019 references * Discard no discard values to solve compiler warnings Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
2022-02-07 06:08:30 -08:00
namespace Microsoft.Plugin.WindowsTerminal.UnitTests
{
[TestClass]
public class TerminalHelperTests
{
[DataTestMethod]
[DataRow("Windows PowerShell", true, true, "--window _quake --profile \"Windows PowerShell\"")]
[DataRow("Windows PowerShell", false, true, "--window _quake --profile \"Windows PowerShell\"")]
[DataRow("Windows PowerShell", true, false, "--window 0 nt --profile \"Windows PowerShell\"")]
[DataRow("Windows PowerShell", false, false, " --profile \"Windows PowerShell\"")]
public void ArgumentsTest(string profile, bool openNewTab, bool openQuake, string expectedArguments)
{
var arguments = TerminalHelper.GetArguments(profile, openNewTab, openQuake);
Assert.AreEqual(arguments, expectedArguments);
}
[DataTestMethod]
[DataRow("settings 1.11.2421.0.json")]
[DataRow("settings 1.11.2421.0_2.json")]
public void ParseSettingsTest(string file)
{
var terminal = new TerminalPackage(string.Empty, new Version(), string.Empty, string.Empty, string.Empty);
var settingsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, file);
var settings = File.ReadAllText(settingsPath);
var profiles = TerminalHelper.ParseSettings(terminal, settings);
Assert.AreEqual(profiles.Count, 4);
}
[DataTestMethod]
[DataRow(
@"{""guid"":""{61c54bbd-c2c6-5271-96e7-009a87ff44bf}"",""name"":""Windows PowerShell"",""commandline"":""powershell.exe"",""hidden"":true}",
"61c54bbd-c2c6-5271-96e7-009a87ff44bf",
"Windows PowerShell",
true)]
[DataRow(
@"{""name"":""Windows PowerShell"",""commandline"":""powershell.exe"",""hidden"":false}",
null,
"Windows PowerShell",
false)]
public void ParseProfilesTest(string json, string identifier, string name, bool hidden)
{
var profileElement = JsonDocument.Parse(json).RootElement;
var terminal = new TerminalPackage(string.Empty, new Version(), string.Empty, string.Empty, string.Empty);
var profile = TerminalHelper.ParseProfile(terminal, profileElement);
var expectedIdentifier = identifier != null ? new Guid(identifier) : null as Guid?;
Assert.AreEqual(profile.Terminal, terminal);
Assert.AreEqual(profile.Identifier, expectedIdentifier);
Assert.AreEqual(profile.Name, name);
Assert.AreEqual(profile.Hidden, hidden);
}
}
}