Example #1
0
 public void Can_roundtrip_SearchResult_with_empty_string() {
     var item = new SearchResultItem(1, SearchResultType.Page, "", 0.5, DateTime.UtcNow.WithoutMilliseconds());
     var result = new SearchResult("foo", new[] { item });
     using(var ms = new MemoryStream()) {
         _serializer.Serialize(ms, result);
         ms.Position = 0;
         var result2 = _serializer.Deserialize<SearchResult>(ms);
         Assert.AreEqual(result.ExecutedQuery, result2.ExecutedQuery);
         Assert.AreEqual(result.Count, result2.Count);
         Assert.AreEqual(result.First().Title, result2.First().Title);
     }
 }
        public void FormatResultSet_generates_special_output_for_tracked_searches() {

            // Arrange
            var item = new SearchResultItem(1, SearchResultType.Page, "page", 1,  DateTime.Parse("2010/10/10").ToSafeUniversalTime());
            var detail = new SearchResultDetail(Pairs(
                "id.page", 1,
                "path","path",
                "uri","http://uri",
                "title", "foo",
                "author", "bob",
                "preview", "preview"
            ));
            var set = new SearchResult("parsed", new[] { item });
            var discriminator = new SetDiscriminator() { Ascending = true, Limit = 100, Offset = 0, SortField = "rank" };
            var explain = false;
            TrackingInfo trackingInfo = new TrackingInfo() { QueryId = 123, PreviousQueryId = 456 };
            _cache.Setup(x => x.TryGet(item.DetailKey, out detail)).Returns(true).AtMostOnce().Verifiable();

            // Act
            var xml = Search.FormatResultSet(set, discriminator, explain, trackingInfo, new Result<XDoc>()).Wait();

            // Assert
            _cache.VerifyAll();
            var expectedXml = XDocFactory.From(@"
<search querycount=""1"" ranking=""adaptive"" queryid=""123"" count=""1"">
  <parsedQuery>parsed</parsedQuery>
  <result>
    <id>1</id>
    <uri>http://uri</uri>
    <uri.track>mock://api/site/query/123?pageid=1&amp;rank=1&amp;type=page&amp;position=1</uri.track>
    <rank>1</rank>
    <title>foo</title>
    <page>
      <title>foo</title>
      <path>path</path>
    </page>
    <author>bob</author>
    <date.modified>2010-10-10T00:00:00Z</date.modified>
    <content>preview</content>
    <type>page</type>
  </result>
</search>", MimeType.TEXT_XML);
            Assert.AreEqual(expectedXml.ToCompactString(), xml.ToCompactString());
        }