Test frameworks consolidated (#12672)

This commit is contained in:
Davide Giacometti
2021-08-16 15:25:06 +02:00
committed by GitHub
parent c3a51f9227
commit e96c0da265
53 changed files with 1018 additions and 924 deletions

View File

@@ -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");