public void Test() { var service = new Mock <Service>(); var job = new Mock <Job>(); service.Setup(s => s.LogOnAsync( It.IsAny <string>(), It.IsAny <string>())) .Returns(Task.FromResult(true)); service.Setup(s => s.LogOffAsync()).Returns(Task.FromResult(true)); service.Setup(s => s.SearchAsync( It.IsAny <string>(), // search It.IsAny <int>(), // count It.IsAny <ExecutionMode>(), // mode It.IsAny <JobArgs>(), // args It.IsAny <CustomJobArgs>())) // customArgs .Returns(Task.FromResult(job.Object)); var message = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(new FileStream("search-results.xml", FileMode.Open)), }; var resultStream = SearchResultStream.CreateAsync(message); job.Setup(j => j.GetSearchResultsAsync(It.IsAny <int>())).Returns(resultStream); Run(service.Object).Wait(); }
async Task CanHandleInFlightErrorsReportedBySplunk() { var path = Path.Combine(TestAtomFeed.Directory, "Service.ExportSearchResults-failure.xml"); var message = new HttpResponseMessage(HttpStatusCode.OK); message.Content = new StreamContent(new FileStream(path, FileMode.Open, FileAccess.Read)); SearchResultStream stream = null; try { stream = await SearchResultStream.CreateAsync(message); int count = 0; foreach (var result in stream) { ++count; } Assert.False(true, "Expected RequestException"); } catch (RequestException e) { Assert.Equal(e.Message, "Fatal: JournalSliceDirectory: Cannot seek to 0"); } finally { if (stream != null) { stream.Dispose(); } } }
async Task CanSkipEmptyResults() { var baseFileName = Path.Combine(TestAtomFeed.Directory, "DVPL-5873"); var message = new HttpResponseMessage(HttpStatusCode.OK); message.Content = new StreamContent(new FileStream(baseFileName + ".xml", FileMode.Open, FileAccess.Read)); using (var stream = await SearchResultStream.CreateAsync(message)) { int count = 0; foreach (var observedResult in stream) { ++count; } Assert.Equal(count, stream.ReadCount); } }
async Task CanHandleBlankAndEmptyValues() { var builder = ImmutableSortedSet.CreateBuilder <string>(); builder.Add(""); var blankTaggedTextElement = new TaggedFieldValue("text", builder.ToImmutableSortedSet <string>()); builder.Clear(); builder.Add("tag"); var taggedBlankTextElement = new TaggedFieldValue("", builder.ToImmutableSortedSet <string>()); var path = Path.Combine(TestAtomFeed.Directory, "BlankAndEmptySearchResults.xml"); var message = new HttpResponseMessage(HttpStatusCode.OK); message.Content = new StreamContent(new FileStream(path, FileMode.Open, FileAccess.Read)); using (var stream = await SearchResultStream.CreateAsync(message)) { int count = 0; foreach (dynamic observedResult in stream) { Assert.Equal(observedResult._raw, string.Empty); Assert.Null(observedResult.SegmentedRaw); Assert.Equal(observedResult.blank_tagged_text_element, blankTaggedTextElement); Assert.Equal(observedResult.empty_tagged_text_element, blankTaggedTextElement); Assert.Equal(observedResult.blank_text_element, string.Empty); Assert.Equal(observedResult.blank_value_element, string.Empty); Assert.Equal(observedResult.empty_text_element, string.Empty); Assert.Equal(observedResult.tagged_blank_text_element, taggedBlankTextElement); Assert.Equal(observedResult.tagged_empty_text_element, taggedBlankTextElement); ++count; } } }
async Task CanEnumerateResults() { var baseFileName = Path.Combine(TestAtomFeed.Directory, "TaggedSearchResults"); using (var expectedResults = new StreamReader(baseFileName + ".expected.text", encoding: Encoding.UTF8)) { var message = new HttpResponseMessage(HttpStatusCode.OK); message.Content = new StreamContent(new FileStream(baseFileName + ".xml", FileMode.Open, FileAccess.Read)); using (var stream = await SearchResultStream.CreateAsync(message)) { int count = 0; foreach (var observedResult in stream) { string expectedResult = null; ++count; try { expectedResult = await expectedResults.ReadLineAsync(); continue; } catch (Exception e) { Assert.False(true, string.Format("Error while reading expected results: {0}", e.Message)); } Assert.NotNull(expectedResult); Assert.Equal(expectedResult, observedResult.ToString()); } Assert.Null(expectedResults.ReadLine()); Assert.Equal(count, stream.ReadCount); } } }