public void WriteAutoCompleteResultTest( string indexName, int numDocs, Dictionary <string, string> commitUserData, int topDocsTotalHits, float topDocsMaxScore, int skip, int take, bool includeExplanation, string expected) { var searcher = new MockSearcher(indexName, numDocs, commitUserData); var topDocs = new TopDocs(topDocsTotalHits, Constants.ScoreDocs, topDocsMaxScore); var sb = new StringBuilder(); var sw = new StringWriter(sb); using (var writer = new JsonTextWriter(sw)) { ResponseFormatter.WriteAutoCompleteResult(writer, searcher, topDocs, skip, take, includeExplanation, NuGetQuery.MakeQuery("test")); Assert.Equal(string.Format(expected, searcher.LastReopen, Constants.MockBase, Constants.LucenePropertyId, Constants.MockExplanationBase), sb.ToString()); } }
public void WriteDiagStatsResultTest( string indexName, int numDocs, Dictionary <string, string> commitUserData, Dictionary <string, DateTime?> auxFileData, string expected) { var currentTime = DateTime.UtcNow; var searcher = new MockSearcher(indexName, numDocs, commitUserData, versions: null, reloadTime: currentTime, lastModifiedTimeForAuxFiles: auxFileData, machineName: "TestMachineX"); var sb = new StringBuilder(); var sw = new StringWriter(sb); using (var writer = new JsonTextWriter(sw)) { ResponseFormatter.WriteStatsResult(writer, searcher); var expectedResult = string.Format( expected, searcher.Manager.MachineName.ToString(), searcher.LastReopen.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'FFFFFFFK"), searcher.Manager.LastIndexReloadTime.Value.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'FFFFFFFK"), searcher.Manager.LastAuxiliaryDataLoadTime.Value.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'FFFFFFFK") ); Assert.Equal(expectedResult, sb.ToString()); } }
public void WriteSearchResultTest( string indexName, int numDocs, Dictionary <string, string> commitUserData, int topDocsTotalHits, float topDocsMaxScore, int skip, int take, bool includePrerelease, bool includeExplanation, NuGetVersion semVerlLevel, string scheme, string expectedBaseUrl, string expected) { var searcher = new MockSearcher(indexName, numDocs, commitUserData, versions: Constants.VersionResults); var topDocs = new TopDocs(topDocsTotalHits, Constants.ScoreDocs, topDocsMaxScore); var sb = new StringBuilder(); var sw = new StringWriter(sb); using (var writer = new JsonTextWriter(sw)) { ResponseFormatter.WriteSearchResult(writer, searcher, scheme, topDocs, skip, take, includePrerelease, includeExplanation, semVerlLevel, NuGetQuery.MakeQuery("test")); Assert.Equal(string.Format(expected, expectedBaseUrl, searcher.LastReopen, Constants.MockBase.ToLower(), Constants.LucenePropertyId.ToLower(), Constants.MockBase, Constants.LucenePropertyId, Constants.LucenePropertyFullVersion, Constants.LucenePropertyDescription, Constants.LucenePropertySummary, Constants.LucenePropertyTitle, Constants.LucenePropertyIconUrl, Constants.LucenePropertyLicenseUrl, Constants.LucenePropertyProjectUrl), sb.ToString()); } }
public void WriteAutoCompleteVersionResultTest( string indexName, int numDocs, Dictionary <string, string> commitUserData, int topDocsTotalHits, float topDocsMaxScore, bool includePrerelease, string expected) { var searcher = new MockSearcher(indexName, numDocs, commitUserData, versions: Constants.VersionResults); var topDocs = new TopDocs(topDocsTotalHits, Constants.ScoreDocs, topDocsMaxScore); var sb = new StringBuilder(); var sw = new StringWriter(sb); using (var writer = new JsonTextWriter(sw)) { ResponseFormatter.WriteAutoCompleteVersionResult(writer, searcher, includePrerelease, SemVerHelpers.SemVer2Level, topDocs); Assert.Equal(string.Format(expected, searcher.LastReopen), sb.ToString()); } }
public void WriteV2ResultTest( string indexName, int numDocs, Dictionary <string, string> commitUserData, int topDocsTotalHits, float topDocsMaxScore, int skip, int take, string expected) { var searcher = new MockSearcher(indexName, numDocs, commitUserData, versions: Constants.VersionResults); var topDocs = new TopDocs(topDocsTotalHits, Constants.ScoreDocs, topDocsMaxScore); var sb = new StringBuilder(); var sw = new StringWriter(sb); using (var writer = new JsonTextWriter(sw)) { ResponseFormatter.WriteV2Result(writer, searcher, topDocs, skip, take, SemVerHelpers.SemVer2Level); var result = sb.ToString(); Assert.Equal(expected, result); } }