public void ConvertToSearchResultRaisesArgumentNullExceptionForMissingResult()
        {
            // Arrange
            DocumentSearchResult <JobProfileIndex> result = null;
            var searchProperties       = A.Fake <SearchProperties>();
            var azSearchQueryConverter = new AzSearchQueryConverter();

            // Act
            var exceptionResult = Assert.Throws <ArgumentNullException>(() => azSearchQueryConverter.ConvertToSearchResult(result, searchProperties));

            // assert
            Assert.Equal("Value cannot be null. (Parameter 'result')", exceptionResult.Message);
        }
        public void ConvertToSearchResultReturnsSearchResultForSearchProperties()
        {
            // Arrange
            var searchResults          = A.Fake <IList <Microsoft.Azure.Search.Models.SearchResult <JobProfileIndex> > >();
            var facets                 = A.Fake <IDictionary <string, IList <FacetResult> > >();
            var result                 = new DocumentSearchResult <JobProfileIndex>(searchResults, 0, 0, facets, null);
            var searchProperties       = A.Fake <SearchProperties>();
            var azSearchQueryConverter = new AzSearchQueryConverter();

            // Act
            var results = azSearchQueryConverter.ConvertToSearchResult(result, searchProperties);

            // Assert
            Assert.NotNull(results);
        }
        public void ConvertToSearchResultRaisesArgumentNullExceptionForMissingSearchProperties()
        {
            // Arrange
            var searchResults = A.Fake <IList <Microsoft.Azure.Search.Models.SearchResult <JobProfileIndex> > >();
            var facets        = A.Fake <IDictionary <string, IList <FacetResult> > >();
            var result        = new DocumentSearchResult <JobProfileIndex>(searchResults, 0, 0, facets, null);
            SearchProperties searchProperties = null;
            var azSearchQueryConverter        = new AzSearchQueryConverter();

            // Act
            var exceptionResult = Assert.Throws <ArgumentNullException>(() => azSearchQueryConverter.ConvertToSearchResult(result, searchProperties));

            // assert
            Assert.Equal("Value cannot be null. (Parameter 'properties')", exceptionResult.Message);
        }
        public void ConvertResultTest()
        {
            var properties = new SearchProperties
            {
                Count            = 2,
                FilterBy         = "filterby",
                Page             = 3,
                SearchFields     = new[] { "Field1", "Field2" },
                UseRawSearchTerm = true
            };

            var indexResult = new DocumentSearchResult <JobProfileIndex>
            {
                Count   = 101,
                Results = new List <Microsoft.Azure.Search.Models.SearchResult <JobProfileIndex> >
                {
                    new Microsoft.Azure.Search.Models.SearchResult <JobProfileIndex>
                    {
                        Score    = 1,
                        Document = DummyJobProfileIndex.GenerateJobProfileIndexDummy("one")
                    },
                    new Microsoft.Azure.Search.Models.SearchResult <JobProfileIndex>
                    {
                        Score    = 1.2,
                        Document = DummyJobProfileIndex.GenerateJobProfileIndexDummy("two")
                    },
                }
            };

            var queryConverter = new AzSearchQueryConverter();
            var result         = queryConverter.ConvertToSearchResult(indexResult, properties);

            result.Count.Should().Be(indexResult.Count);                                            //Count = result.Count,
            result.Results.First().Rank.Should().Be(5);                                             //Results = result.ToSearchResultItems(properties)
            result.Results.First().ResultItem
            .Should().BeEquivalentTo(DummyJobProfileIndex.GenerateJobProfileIndexDummy("one"));     //Results = result.ToSearchResultItems(properties)

            result.Results.Last().Rank.Should().Be(6);                                              //Results = result.ToSearchResultItems(properties)
            result.Results.Last().ResultItem
            .Should().BeEquivalentTo(DummyJobProfileIndex.GenerateJobProfileIndexDummy("two"));     //Results = result.ToSearchResultItems(properties)
        }