public async Task GetAnalyzedSearch_False()
        {
            // Arrange
            var viewCriteria = new List <ViewCriteria> {
            };
            var searchAudit  = new Audit {
                ArtifactID = 1
            };
            var searchAuditGroup = new SearchAuditGroup {
                Audits = new List <SearchAudit> {
                    new SearchAudit {
                        Audit = searchAudit
                    }
                }
            };
            var searchText = "";

            this.viewCriteriaRepositoryMock.Setup(m => m.ReadViewCriteriasForSearch(searchAudit.WorkspaceId, searchAudit.ArtifactID))
            .Returns(viewCriteria);
            this.viewRepositoryMock.Setup(
                m => m.ReadById(searchAudit.WorkspaceId, searchAudit.ArtifactID)).Returns(new Search {
                ArtifactId = 1, SearchText = searchText
            });
            this.searchFolderRepositoryMock.Setup(
                m => m.GetSearchFolderCountForSearch(It.IsAny <int>(), It.IsAny <int>()))
            .Returns(0);

            // Act
            var result = await this.searchAnalysisService.AnalyzeSearchAudit(searchAuditGroup);

            // Assert
            Assert.That(result.IsComplex, Is.False);
        }
예제 #2
0
        /// <inheritdoc />
        public async Task <SearchAuditGroup> AnalyzeSearchAudit(SearchAuditGroup searchAuditGroup)
        {
            // Get the details of the search from SQL
            foreach (var searchAudit in searchAuditGroup.Audits)
            {
                if (this.IsAdHocSearch(searchAudit.Audit))
                {
                    // Search the queryText for like
                    var queryText = !string.IsNullOrEmpty(searchAudit.Audit.Details) ? this.auditParsingService.ParseRawQueryText(searchAudit.Audit.Details) : this.auditParsingService.ParseQueryText(searchAudit.Audit.ParsedDetails);
                    searchAudit.IsComplex = this.IsSearchComplex(queryText);
                }
                else
                {
                    // Get the saved search details that we can
                    searchAudit.Search = await this.GetSearchDetails(searchAudit.Audit.ArtifactID, searchAudit.Audit.WorkspaceId);

                    searchAudit.IsComplex = this.IsSearchComplex(searchAudit.Search);
                }
            }

            return(searchAuditGroup);
        }
예제 #3
0
 public static bool IsLongRunning(SearchAuditGroup searchAuditGroup) =>
 IsLongRunning(searchAuditGroup.IsComplex, searchAuditGroup.ExecutionTime);
예제 #4
0
        public async Task ProcessBatch()
        {
            // Arrange
            var batchId    = 1;
            var batchSize  = 50;
            var batchStart = 0;
            var batch      = new SearchAuditBatch
            {
                Id          = batchId,
                WorkspaceId = workspaceId,
                BatchSize   = batchSize,
                BatchStart  = batchStart,
                ServerId    = 123,
                HourId      = this.hourId
            };

            this.searchAuditBatchRepositoryMock.Setup(m => m.ReadBatch(batch.Id))
            .Returns(batch);

            this.serverRepositoryMock.Setup(m => m.ReadWorkspaceExistsAsync(workspaceId)).ReturnsAsync(true);
            this.hourRepositoryMock.Setup(m => m.ReadAsync(batch.HourId)).ReturnsAsync(hour);

            var audit  = new Audit();
            var audits = new List <Audit> {
                audit
            };

            this.workspaceAuditServiceMock.Setup(
                m => m.ReadAuditsAsync(
                    batch.WorkspaceId,
                    hour.Id,
                    It.Is <IList <AuditActionId> >(a => a.Contains(AuditActionId.DocumentQuery)),
                    batch.BatchSize,
                    batch.BatchStart))
            .ReturnsAsync(audits);

            var queryId = (string)null;

            this.auditParsingServiceMock.Setup(m => m.ParseQueryId(audit.Details)).Returns(queryId);

            var searchAudit = new SearchAudit {
                Search = new Search(), IsComplex = true
            };
            var startSearchAudits = new SearchAuditGroup {
                Audits = new List <SearchAudit> {
                    searchAudit
                }
            };
            var endSearchAudits = new SearchAuditGroup {
                Audits = new List <SearchAudit> {
                    searchAudit
                }
            };
            var expectedSearchAudits = new List <SearchAudit> {
                searchAudit
            };
            var expectedSearchAuditGroups = new List <SearchAuditGroup> {
                new SearchAuditGroup {
                    Audits = expectedSearchAudits
                }
            };

            this.searchAnalysisServiceMock.Setup(m => m.AnalyzeSearchAudit(startSearchAudits)).ReturnsAsync(endSearchAudits);
            expectedSearchAudits[0].IsComplex = searchAudit.IsComplex;

            var auditResult = new SearchAuditBatchResult {
                BatchId = batchId
            };
            var auditResults = new List <SearchAuditBatchResult> {
                auditResult
            };

            this.auditBatchAnalyzerMock.Setup(m => m.GetBatchResults(It.IsAny <IList <SearchAuditGroup> >(), batchId)).Returns(auditResults);

            this.workspaceAuditReporter.Setup(r => r.ReportWorkspaceAudits(It.IsAny <IList <SearchAuditGroup> >(), It.IsAny <Hour>(), It.IsAny <int>()))
            .Returns(Task.FromResult(1));

            this.searchAuditBatchRepositoryMock.Setup(r => r.CreateBatchResults(It.IsAny <IList <SearchAuditBatchResult> >()))
            .Returns(new[] { 123456 });

            this.searchAuditBatchRepositoryMock.Setup(r => r.UpdateAsync(batch))
            .Returns(Task.FromResult(1));

            this.workspaceService.Setup(s => s.WorkspaceIsAvailableAsync(workspaceId))
            .ReturnsAsync(true);

            // Act
            var result = await this.auditBatchProcessor.ProcessBatch(batchId);

            // Assert
            Assert.That(result, Is.Not.Empty);
            Assert.That(result.Count, Is.EqualTo(auditResults.Count));
        }