mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[PT Run] [Folder Plugin] Environment Variables With Autocomplete (#13811)
* search environment variables folders with autocomplete * refactoring and tests * fix
This commit is contained in:
committed by
GitHub
parent
15f3c2ff66
commit
64cc6b7af7
@@ -0,0 +1,67 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.IO.Abstractions.TestingHelpers;
|
||||
using System.Linq;
|
||||
using Microsoft.Plugin.Folder.Sources;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
|
||||
namespace Microsoft.Plugin.Folder.UnitTests
|
||||
{
|
||||
[TestClass]
|
||||
public class QueryEnvironmentVariableTests
|
||||
{
|
||||
private static IQueryEnvironmentVariable _queryEnvironmentVariable;
|
||||
private static MockFileSystem _fileSystem;
|
||||
|
||||
[TestInitialize]
|
||||
public void SetupMock()
|
||||
{
|
||||
var environmentHelperMock = new Mock<IEnvironmentHelper>();
|
||||
|
||||
environmentHelperMock
|
||||
.Setup(h => h.GetEnvironmentVariables())
|
||||
.Returns(() => new Dictionary<string, string>
|
||||
{
|
||||
{ "OS", "Windows_NT" },
|
||||
{ "WINDIR", @"C:\Windows" },
|
||||
{ "PROGRAMDATA", @"C:\ProgramData" },
|
||||
{ "PROGRAMFILES", @"C:\Program Files" },
|
||||
});
|
||||
|
||||
_fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>()
|
||||
{
|
||||
{ @"C:\Windows", new MockDirectoryData() },
|
||||
{ @"C:\ProgramData", new MockDirectoryData() },
|
||||
{ @"C:\Program Files", new MockDirectoryData() },
|
||||
});
|
||||
|
||||
_queryEnvironmentVariable = new QueryEnvironmentVariable(_fileSystem.Directory, environmentHelperMock.Object);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(@"%OS%")] // Not a directory
|
||||
[DataRow(@"%CUSTOM%")] // Directory doesn't exist
|
||||
[DataRow(@"WINDIR")] // Not an environment variable
|
||||
public void QueryWithEmptyResults(string search)
|
||||
{
|
||||
var results = _queryEnvironmentVariable.Query(search);
|
||||
Assert.AreEqual(results.Count(), 0);
|
||||
}
|
||||
|
||||
[DataTestMethod]
|
||||
[DataRow(@"", 3)]
|
||||
[DataRow(@"%", 3)]
|
||||
[DataRow(@"%WIN", 1)]
|
||||
[DataRow(@"%WINDIR%", 1)]
|
||||
[DataRow(@"%PROGRAM", 2)]
|
||||
public void QueryWithResults(string search, int numberOfResults)
|
||||
{
|
||||
var results = _queryEnvironmentVariable.Query(search);
|
||||
Assert.AreEqual(results.Count(), numberOfResults);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user