public void WindowsSearchAPI_ShouldReturnResults_WhenSearchWasExecuted() { // Arrange OleDBResult unHiddenFile = new OleDBResult(new List <object>() { "C:/test/path/file1.txt", "file1.txt" }); OleDBResult hiddenFile = new OleDBResult(new List <object>() { "C:/test/path/file2.txt", "file2.txt" }); List <OleDBResult> results = new List <OleDBResult>() { hiddenFile, unHiddenFile }; var mock = new Mock <ISearch>(); mock.Setup(x => x.Query(It.IsAny <string>(), It.IsAny <string>())).Returns(results); WindowsSearchAPI api = new WindowsSearchAPI(mock.Object, true); // Act var windowsSearchAPIResults = api.Search("FilePath"); // Assert Assert.IsTrue(windowsSearchAPIResults.Count() == 2); Assert.IsTrue(windowsSearchAPIResults.Any(x => x.Title == "file1.txt")); Assert.IsTrue(windowsSearchAPIResults.Any(x => x.Title == "file2.txt")); }
public void WindowsSearchAPI_ShouldReturnEmptyResults_WhenIsFullQueryIsTrueAndTheQueryDoesNotRequireLIKESyntax() { // Arrange OleDBResult file1 = new OleDBResult(new List <object>() { "C:/test/path/file1.txt", DBNull.Value }); OleDBResult file2 = new OleDBResult(new List <object>() { "C:/test/path/file2.txt", "file2.txt" }); List <OleDBResult> results = new List <OleDBResult>() { file1, file2 }; var mock = new Mock <ISearch>(); mock.Setup(x => x.Query(It.IsAny <string>(), It.IsAny <string>())).Returns(results); WindowsSearchAPI api = new WindowsSearchAPI(mock.Object, false); var searchManager = GetMockSearchManager(); // Act var windowsSearchAPIResults = api.Search("file", searchManager, true); // Assert Assert.IsTrue(windowsSearchAPIResults.Count() == 0); }
public void WindowsSearchAPI_ShouldNotReturnResultsWithNullValue_WhenDbResultHasANullColumn() { // Arrange OleDBResult unHiddenFile = new OleDBResult(new List <object>() { "C:/test/path/file1.txt", DBNull.Value }); OleDBResult hiddenFile = new OleDBResult(new List <object>() { "C:/test/path/file2.txt", "file2.txt" }); List <OleDBResult> results = new List <OleDBResult>() { hiddenFile, unHiddenFile }; var mock = new Mock <ISearch>(); mock.Setup(x => x.Query(It.IsAny <string>(), It.IsAny <string>())).Returns(results); WindowsSearchAPI api = new WindowsSearchAPI(mock.Object, false); var mockSearchManager = GetMockSearchManager(); // Act var windowsSearchAPIResults = api.Search("FilePath", mockSearchManager); // Assert Assert.IsTrue(windowsSearchAPIResults.Count() == 1); Assert.IsFalse(windowsSearchAPIResults.Any(x => x.Title == "file1.txt")); Assert.IsTrue(windowsSearchAPIResults.Any(x => x.Title == "file2.txt")); }
public void WindowsSearchAPI_ShouldNotReturnResultsWithNullValue_WhenDbResultHasANullColumn() { // Arrange OleDBResult file1 = new OleDBResult(new List <object>() { "C:/test/path/file1.txt", DBNull.Value, (Int64)0x0 }); OleDBResult file2 = new OleDBResult(new List <object>() { "C:/test/path/file2.txt", "file2.txt", (Int64)0x0 }); List <OleDBResult> results = new List <OleDBResult>() { file1, file2 }; var mock = new Mock <ISearch>(); mock.Setup(x => x.Query(It.IsAny <string>(), It.IsAny <string>())).Returns(results); WindowsSearchAPI _api = new WindowsSearchAPI(mock.Object, false); // Act var windowsSearchAPIResults = _api.Search("FilePath"); // Assert Assert.IsTrue(windowsSearchAPIResults.Count() == 1); Assert.IsFalse(windowsSearchAPIResults.Any(x => x.Title == "file1.txt")); Assert.IsTrue(windowsSearchAPIResults.Any(x => x.Title == "file2.txt")); }
public void WindowsSearchAPI_ShouldNotShowHiddenFiles_WhenDisplayHiddenFilesIsFalse() { // Arrange OleDBResult unHiddenFile = new OleDBResult(new List <object>() { "C:/test/path/file1.txt", "file1.txt", (Int64)0x0 }); OleDBResult hiddenFile = new OleDBResult(new List <object>() { "C:/test/path/file2.txt", "file2.txt", (Int64)0x2 }); List <OleDBResult> results = new List <OleDBResult>() { hiddenFile, unHiddenFile }; var mock = new Mock <ISearch>(); mock.Setup(x => x.Query(It.IsAny <string>(), It.IsAny <string>())).Returns(results); WindowsSearchAPI _api = new WindowsSearchAPI(mock.Object, false); // Act var windowsSearchAPIResults = _api.Search("FilePath"); // Assert Assert.IsTrue(windowsSearchAPIResults.Count() == 1); Assert.IsTrue(windowsSearchAPIResults.Any(x => x.Title == "file1.txt")); Assert.IsFalse(windowsSearchAPIResults.Any(x => x.Title == "file2.txt")); }
public void SimplifyQueryShouldReturnArgumentWhenSQLQueryDoesNotUseLIKESyntax() { // Arrange string sqlQuery = "SELECT TOP 30 \"System.ItemUrl\", \"System.FileName\", \"System.FileAttributes\" FROM \"SystemIndex\" WHERE CONTAINS(System.FileName,'\"abcd*\"',1033) AND scope='file:' ORDER BY System.DateModified DESC"; // Act var simplifiedSqlQuery = WindowsSearchAPI.SimplifyQuery(sqlQuery); // Assert Assert.IsTrue(simplifiedSqlQuery.Equals(sqlQuery, StringComparison.InvariantCultureIgnoreCase)); }
public void ExecuteQuery_ShouldDisposeAllConnections_AfterFunctionCall() { // Arrange OleDBSearch oleDbSearch = new OleDBSearch(); WindowsSearchAPI _api = new WindowsSearchAPI(oleDbSearch); // Act _api.Search("FilePath"); // Assert Assert.IsTrue(oleDbSearch.HaveAllDisposableItemsBeenDisposed()); }
public void SimplifyQueryShouldRemoveAllOccurrencesOfLikeQueryWhenSQLQueryUsesLIKESyntaxMultipleTimes() { // Arrange string sqlQuery = "SELECT TOP 30 \"System.ItemUrl\", \"System.FileName\", \"System.FileAttributes\", \"System.FileExtension\" FROM \"SystemIndex\" WHERE (System.FileName LIKE 'ab.%' OR CONTAINS(System.FileName,'\"ab.*\"',1033)) AND (System.FileExtension LIKE '.cd%' OR CONTAINS(System.FileName,'\".cd*\"',1033)) AND scope='file:' ORDER BY System.DateModified DESC"; // Act var simplifiedSqlQuery = WindowsSearchAPI.SimplifyQuery(sqlQuery); // Assert string expectedSqlQuery = "SELECT TOP 30 \"System.ItemUrl\", \"System.FileName\", \"System.FileAttributes\", \"System.FileExtension\" FROM \"SystemIndex\" WHERE (CONTAINS(System.FileName,'\"ab.*\"',1033)) AND (CONTAINS(System.FileName,'\".cd*\"',1033)) AND scope='file:' ORDER BY System.DateModified DESC"; Assert.IsFalse(simplifiedSqlQuery.Equals(sqlQuery, StringComparison.InvariantCultureIgnoreCase)); Assert.IsTrue(simplifiedSqlQuery.Equals(expectedSqlQuery, StringComparison.InvariantCultureIgnoreCase)); }
public void InitQueryHelper_ShouldInitialize_WhenFunctionIsCalled() { // Arrange int maxCount = 10; WindowsSearchAPI _api = GetWindowsSearchAPI(); ISearchQueryHelper queryHelper = null; // Act _api.InitQueryHelper(out queryHelper, maxCount); // Assert Assert.IsNotNull(queryHelper); Assert.AreEqual(queryHelper.QueryMaxResults, maxCount); }
public void SimplifyQueryShouldRemoveLikeQueryWhenSQLQueryUsesLIKESyntaxAndContainsEscapedSingleQuotationMarks() { // Arrange string sqlQuery = "SELECT TOP 30 \"System.ItemUrl\", \"System.FileName\", \"System.FileAttributes\" FROM \"SystemIndex\" WHERE (System.FileName LIKE '''ab.cd''%' OR CONTAINS(System.FileName,'\"'ab.cd'*\"',1033)) AND scope='file:' ORDER BY System.DateModified DESC"; // Act var simplifiedSqlQuery = WindowsSearchAPI.SimplifyQuery(sqlQuery); // Assert string expectedSqlQuery = "SELECT TOP 30 \"System.ItemUrl\", \"System.FileName\", \"System.FileAttributes\" FROM \"SystemIndex\" WHERE (CONTAINS(System.FileName,'\"'ab.cd'*\"',1033)) AND scope='file:' ORDER BY System.DateModified DESC"; Assert.IsFalse(simplifiedSqlQuery.Equals(sqlQuery, StringComparison.InvariantCultureIgnoreCase)); Assert.IsTrue(simplifiedSqlQuery.Equals(expectedSqlQuery, StringComparison.InvariantCultureIgnoreCase)); }
public void InitQueryHelperShouldInitializeWhenFunctionIsCalled() { // Arrange int maxCount = 10; WindowsSearchAPI api = GetWindowsSearchAPI(); ISearchQueryHelper queryHelper = null; var mockSearchManager = GetMockSearchManager(); // Act WindowsSearchAPI.InitQueryHelper(out queryHelper, mockSearchManager, maxCount, api.DisplayHiddenFiles); // Assert Assert.IsNotNull(queryHelper); Assert.AreEqual(maxCount, queryHelper.QueryMaxResults); }
public void SimplifyQueryShouldRemoveLikeQueryWhenSQLQueryUsesLIKESyntax() { // Arrange string sqlQuery = "SELECT TOP 30 \"System.ItemUrl\", \"System.FileName\", \"System.FileAttributes\" FROM \"SystemIndex\" WHERE (System.FileName LIKE 'abcd.%' OR CONTAINS(System.FileName,'\"abcd.*\"',1033)) AND scope='file:' ORDER BY System.DateModified DESC"; // Act var simplifiedSqlQuery = WindowsSearchAPI.SimplifyQuery(sqlQuery); // Assert string expectedSqlQuery = "SELECT TOP 30 \"System.ItemUrl\", \"System.FileName\", \"System.FileAttributes\" FROM \"SystemIndex\" WHERE (CONTAINS(System.FileName,'\"abcd.*\"',1033)) AND scope='file:' ORDER BY System.DateModified DESC"; // Using InvariantCultureIgnoreCase since this relates to sql code in string form Assert.IsFalse(simplifiedSqlQuery.Equals(sqlQuery, StringComparison.InvariantCultureIgnoreCase)); Assert.IsTrue(simplifiedSqlQuery.Equals(expectedSqlQuery, StringComparison.InvariantCultureIgnoreCase)); }
public void ModifyQueryHelper_ShouldSetQueryHelper_WhenPatternContainsUnderScore() { // Arrange ISearchQueryHelper queryHelper; String pattern = "tt_^&)"; WindowsSearchAPI _api = GetWindowsSearchAPI(); WindowsSearchAPI.InitQueryHelper(out queryHelper, 10); // Act WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern); // Assert Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("LIKE")); Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains")); }
public void WindowsSearchAPI_ShouldRequestFilteredRequest_WhenDisplayHiddenFilesIsFalse() { ISearchQueryHelper queryHelper; String pattern = "notepad"; WindowsSearchAPI _api = GetWindowsSearchAPI(); _api.DisplayHiddenFiles = false; // Act WindowsSearchAPI.InitQueryHelper(out queryHelper, 10, _api.DisplayHiddenFiles); WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern); // Assert Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("AND System.FileAttributes <> SOME BITWISE 2")); }
public void ModifyQueryHelper_ShouldSetQueryHelper_WhenPatternContainsPercent() { // Arrange ISearchQueryHelper queryHelper; string pattern = "tt%^&)"; WindowsSearchAPI api = GetWindowsSearchAPI(); WindowsSearchAPI.InitQueryHelper(out queryHelper, 10, api.DisplayHiddenFiles); // Act WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern); // Assert Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("LIKE")); Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains")); }
public void WindowsSearchAPI_ShouldRequestNormalRequest_WhenDisplayHiddenFilesIsTrue() { ISearchQueryHelper queryHelper; string pattern = "notepad"; WindowsSearchAPI api = GetWindowsSearchAPI(); api.DisplayHiddenFiles = true; var mockSearchManager = GetMockSearchManager(); // Act WindowsSearchAPI.InitQueryHelper(out queryHelper, mockSearchManager, 10, api.DisplayHiddenFiles); WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern); // Assert Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("AND System.FileAttributes <> SOME BITWISE 2")); }
public void ModifyQueryHelper_ShouldSetQueryHelper_WhenPatternIsAsterisk() { // Arrange ISearchQueryHelper queryHelper; String pattern = "*"; WindowsSearchAPI _api = GetWindowsSearchAPI(); _api.InitQueryHelper(out queryHelper, 10); // Act _api.ModifyQueryHelper(ref queryHelper, pattern); // Assert Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("LIKE")); Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains")); }
public void ModifyQueryHelper_ShouldSetQueryHelper_WhenPatternDoesNotContainSplSymbols() { // Arrange ISearchQueryHelper queryHelper; string pattern = "tt^&)bc"; WindowsSearchAPI api = GetWindowsSearchAPI(); WindowsSearchAPI.InitQueryHelper(out queryHelper, 10); // Act WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern); // Assert Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("LIKE")); Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("Contains")); }
public void WindowsSearchAPIShouldRequestFilteredRequestWhenDisplayHiddenFilesIsFalse() { ISearchQueryHelper queryHelper; string pattern = "notepad"; WindowsSearchAPI api = GetWindowsSearchAPI(); api.DisplayHiddenFiles = false; var mockSearchManager = GetMockSearchManager(); // Act WindowsSearchAPI.InitQueryHelper(out queryHelper, mockSearchManager, 10, api.DisplayHiddenFiles); WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern); // Assert // Using Ordinal since this is used internally Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("AND System.FileAttributes <> SOME BITWISE 2", StringComparison.Ordinal)); }
public void ModifyQueryHelper_ShouldSetQueryHelper_WhenPatternIsAsterisk() { // Arrange ISearchQueryHelper queryHelper; string pattern = "*"; WindowsSearchAPI api = GetWindowsSearchAPI(); var mockSearchManager = GetMockSearchManager(); WindowsSearchAPI.InitQueryHelper(out queryHelper, mockSearchManager, 10, api.DisplayHiddenFiles); // Act WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern); // Assert Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("LIKE")); Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains")); }
public void ModifyQueryHelperShouldSetQueryHelperWhenPatternContainsAsterisk() { // Arrange ISearchQueryHelper queryHelper; string pattern = "tt*^&)"; WindowsSearchAPI api = GetWindowsSearchAPI(); var mockSearchManager = GetMockSearchManager(); WindowsSearchAPI.InitQueryHelper(out queryHelper, mockSearchManager, 10, api.DisplayHiddenFiles); // Act WindowsSearchAPI.ModifyQueryHelper(ref queryHelper, pattern); // Assert // Using Ordinal since this is used internally Assert.IsTrue(queryHelper.QueryWhereRestrictions.Contains("LIKE", StringComparison.Ordinal)); Assert.IsFalse(queryHelper.QueryWhereRestrictions.Contains("Contains", StringComparison.Ordinal)); }