mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
Test frameworks consolidated (#12672)
This commit is contained in:
committed by
GitHub
parent
c3a51f9227
commit
e96c0da265
@@ -4,26 +4,29 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Plugin.Folder.Sources;
|
||||
using Microsoft.Plugin.Folder.Sources.Result;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.Plugin.Folder.UnitTests
|
||||
{
|
||||
[TestClass]
|
||||
public class DriveOrSharedFolderTests
|
||||
{
|
||||
[TestCase(@"\\test-server\testdir", true)]
|
||||
[TestCase(@"c:", true)]
|
||||
[TestCase(@"c:\", true)]
|
||||
[TestCase(@"C:\", true)]
|
||||
[TestCase(@"d:\", true)]
|
||||
[TestCase(@"z:\", false)]
|
||||
[TestCase(@"nope.exe", false)]
|
||||
[TestCase(@"win32\test.dll", false)]
|
||||
[TestCase(@"a\b\c\d", false)]
|
||||
[TestCase(@"D", false)]
|
||||
[TestCase(@"ZZ:\test", false)]
|
||||
[DataTestMethod]
|
||||
[DataRow(@"\\test-server\testdir", true)]
|
||||
[DataRow(@"c:", true)]
|
||||
[DataRow(@"c:\", true)]
|
||||
[DataRow(@"C:\", true)]
|
||||
[DataRow(@"d:\", true)]
|
||||
[DataRow(@"z:\", false)]
|
||||
[DataRow(@"nope.exe", false)]
|
||||
[DataRow(@"win32\test.dll", false)]
|
||||
[DataRow(@"a\b\c\d", false)]
|
||||
[DataRow(@"D", false)]
|
||||
[DataRow(@"ZZ:\test", false)]
|
||||
public void IsDriveOrSharedFolder_WhenCalled(string search, bool expectedSuccess)
|
||||
{
|
||||
// Setup
|
||||
@@ -42,15 +45,16 @@ namespace Microsoft.Plugin.Folder.UnitTests
|
||||
Assert.AreEqual(expectedSuccess, isDriveOrSharedFolder);
|
||||
}
|
||||
|
||||
[TestCase('A', true)]
|
||||
[TestCase('C', true)]
|
||||
[TestCase('c', true)]
|
||||
[TestCase('Z', true)]
|
||||
[TestCase('z', true)]
|
||||
[TestCase('ª', false)]
|
||||
[TestCase('α', false)]
|
||||
[TestCase('Ω', false)]
|
||||
[TestCase('ɀ', false)]
|
||||
[DataTestMethod]
|
||||
[DataRow('A', true)]
|
||||
[DataRow('C', true)]
|
||||
[DataRow('c', true)]
|
||||
[DataRow('Z', true)]
|
||||
[DataRow('z', true)]
|
||||
[DataRow('ª', false)]
|
||||
[DataRow('α', false)]
|
||||
[DataRow('Ω', false)]
|
||||
[DataRow('ɀ', false)]
|
||||
public void ValidDriveLetter_WhenCalled(char letter, bool expectedSuccess)
|
||||
{
|
||||
// Setup
|
||||
@@ -61,10 +65,11 @@ namespace Microsoft.Plugin.Folder.UnitTests
|
||||
Assert.AreEqual(expectedSuccess, isDriveOrSharedFolder);
|
||||
}
|
||||
|
||||
[TestCase("C:", true)]
|
||||
[TestCase("C:\test", true)]
|
||||
[TestCase("D:", false)]
|
||||
[TestCase("INVALID", false)]
|
||||
[DataTestMethod]
|
||||
[DataRow("C:", true)]
|
||||
[DataRow("C:\test", true)]
|
||||
[DataRow("D:", false)]
|
||||
[DataRow("INVALID", false)]
|
||||
public void GenerateMaxFiles_WhenCalled(string search, bool hasValues)
|
||||
{
|
||||
// Setup
|
||||
@@ -88,11 +93,11 @@ namespace Microsoft.Plugin.Folder.UnitTests
|
||||
// Assert
|
||||
if (hasValues)
|
||||
{
|
||||
CollectionAssert.IsNotEmpty(results);
|
||||
Assert.IsTrue(results.Count() > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
CollectionAssert.IsEmpty(results);
|
||||
Assert.IsTrue(results.Count() == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,22 +4,21 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions.TestingHelpers;
|
||||
using System.Linq;
|
||||
using Microsoft.Plugin.Folder.Sources;
|
||||
using Microsoft.Plugin.Folder.Sources.Result;
|
||||
using NUnit.Framework;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Microsoft.Plugin.Folder.UnitTests
|
||||
{
|
||||
[TestFixture]
|
||||
[TestClass]
|
||||
public class InternalQueryFolderTests
|
||||
{
|
||||
private static IQueryFileSystemInfo _queryFileSystemInfoMock;
|
||||
private static MockFileSystem _fileSystem;
|
||||
|
||||
[SetUp]
|
||||
[TestInitialize]
|
||||
public void SetupMock()
|
||||
{
|
||||
// Note: This mock filesystem adds a 'c:\temp' directory.
|
||||
@@ -35,23 +34,24 @@ namespace Microsoft.Plugin.Folder.UnitTests
|
||||
_queryFileSystemInfoMock = new QueryFileSystemInfo(_fileSystem.DirectoryInfo);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestMethod]
|
||||
public void Query_ThrowsException_WhenCalledNull()
|
||||
{
|
||||
// Setup
|
||||
var queryInternalDirectory = new QueryInternalDirectory(new FolderSettings(), _queryFileSystemInfoMock, _fileSystem.Directory);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<ArgumentNullException>(() => queryInternalDirectory.Query(null).ToArray());
|
||||
Assert.ThrowsException<ArgumentNullException>(() => queryInternalDirectory.Query(null).ToArray());
|
||||
}
|
||||
|
||||
[TestCase(@"c", 0, 0, false, Reason = "String empty is nothing")]
|
||||
[TestCase(@"c:", 2, 1, false, Reason = "Root without \\")]
|
||||
[TestCase(@"c:\", 2, 1, false, Reason = "Normal root")]
|
||||
[TestCase(@"c:\Test", 2, 2, false, Reason = "Select yourself")]
|
||||
[TestCase(@"c:\not-exist", 2, 1, false, Reason = "Folder not exist, return root")]
|
||||
[TestCase(@"c:\not-exist\not-exist2", 0, 0, false, Reason = "Folder not exist, return root")]
|
||||
[TestCase(@"c:\bla.t", 2, 1, false, Reason = "Partial match file")]
|
||||
[DataTestMethod]
|
||||
[DataRow(@"c", 0, 0, false, DisplayName = "String empty is nothing")]
|
||||
[DataRow(@"c:", 2, 1, false, DisplayName = "Root without \\")]
|
||||
[DataRow(@"c:\", 2, 1, false, DisplayName = "Normal root")]
|
||||
[DataRow(@"c:\Test", 2, 2, false, DisplayName = "Select yourself")]
|
||||
[DataRow(@"c:\not-exist", 2, 1, false, DisplayName = "Folder not exist, return root")]
|
||||
[DataRow(@"c:\not-exist\not-exist2", 0, 0, false, DisplayName = "Folder not exist, return root")]
|
||||
[DataRow(@"c:\bla.t", 2, 1, false, DisplayName = "Partial match file")]
|
||||
public void Query_WhenCalled(string search, int folders, int files, bool truncated)
|
||||
{
|
||||
const int maxFolderSetting = 3;
|
||||
@@ -74,8 +74,8 @@ namespace Microsoft.Plugin.Folder.UnitTests
|
||||
Assert.AreEqual(folders, isDriveOrSharedFolder[typeof(FolderItemResult)].Count(), "folder count doesn't match");
|
||||
|
||||
// Always check if there is less than max folders
|
||||
Assert.LessOrEqual(isDriveOrSharedFolder[typeof(FileItemResult)].Count(), maxFolderSetting, "Files are not limited");
|
||||
Assert.LessOrEqual(isDriveOrSharedFolder[typeof(FolderItemResult)].Count(), maxFolderSetting, "Folders are not limited");
|
||||
Assert.IsTrue(isDriveOrSharedFolder[typeof(FileItemResult)].Count() <= maxFolderSetting, "Files are not limited");
|
||||
Assert.IsTrue(isDriveOrSharedFolder[typeof(FolderItemResult)].Count() <= maxFolderSetting, "Folders are not limited");
|
||||
|
||||
// Checks if CreateOpenCurrentFolder is displayed
|
||||
Assert.AreEqual(Math.Min(folders + files, 1), isDriveOrSharedFolder[typeof(CreateOpenCurrentFolderResult)].Count(), "CreateOpenCurrentFolder displaying is incorrect");
|
||||
@@ -83,10 +83,11 @@ namespace Microsoft.Plugin.Folder.UnitTests
|
||||
Assert.AreEqual(truncated, isDriveOrSharedFolder[typeof(TruncatedItemResult)].Count() == 1, "CreateOpenCurrentFolder displaying is incorrect");
|
||||
}
|
||||
|
||||
[TestCase(@"c:\>", 3, 3, true, Reason = "Max Folder test recursive")]
|
||||
[TestCase(@"c:\Test>", 3, 3, true, Reason = "2 Folders recursive")]
|
||||
[TestCase(@"c:\not-exist>", 3, 3, true, Reason = "Folder not exist, return root recursive")]
|
||||
[TestCase(@"c:\not-exist\not-exist2>", 0, 0, false, Reason = "Folder not exist, return root recursive")]
|
||||
[DataTestMethod]
|
||||
[DataRow(@"c:\>", 3, 3, true, DisplayName = "Max Folder test recursive")]
|
||||
[DataRow(@"c:\Test>", 3, 3, true, DisplayName = "2 Folders recursive")]
|
||||
[DataRow(@"c:\not-exist>", 3, 3, true, DisplayName = "Folder not exist, return root recursive")]
|
||||
[DataRow(@"c:\not-exist\not-exist2>", 0, 0, false, DisplayName = "Folder not exist, return root recursive")]
|
||||
public void Query_Recursive_WhenCalled(string search, int folders, int files, bool truncated)
|
||||
{
|
||||
const int maxFolderSetting = 3;
|
||||
@@ -109,8 +110,8 @@ namespace Microsoft.Plugin.Folder.UnitTests
|
||||
Assert.AreEqual(folders, isDriveOrSharedFolder[typeof(FolderItemResult)].Count(), "folder count doesn't match");
|
||||
|
||||
// Always check if there is less than max folders
|
||||
Assert.LessOrEqual(isDriveOrSharedFolder[typeof(FileItemResult)].Count(), maxFolderSetting, "Files are not limited");
|
||||
Assert.LessOrEqual(isDriveOrSharedFolder[typeof(FolderItemResult)].Count(), maxFolderSetting, "Folders are not limited");
|
||||
Assert.IsTrue(isDriveOrSharedFolder[typeof(FileItemResult)].Count() <= maxFolderSetting, "Files are not limited");
|
||||
Assert.IsTrue(isDriveOrSharedFolder[typeof(FolderItemResult)].Count() <= maxFolderSetting, "Folders are not limited");
|
||||
|
||||
// Checks if CreateOpenCurrentFolder is displayed
|
||||
Assert.AreEqual(Math.Min(folders + files, 1), isDriveOrSharedFolder[typeof(CreateOpenCurrentFolderResult)].Count(), "CreateOpenCurrentFolder displaying is incorrect");
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Moq" Version="4.16.1" />
|
||||
<PackageReference Include="nunit" Version="3.13.1" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
|
||||
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="12.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user