Ejemplo n.º 1
0
        /// <summary>
        /// Create a hotels index with the standard test documents and as many
        /// extra empty documents needed to test.
        /// </summary>
        /// <param name="size">The total number of documents in the index.</param>
        /// <returns>SearchResources for testing.</returns>
        public async Task <SearchResources> CreateLargeHotelsIndexAsync(int size)
        {
            // Start with the standard test hotels
            SearchResources resources = await SearchResources.CreateWithHotelsIndexAsync(this);

            // Create empty hotels with just an ID for the rest
            int existingDocumentCount     = SearchResources.TestDocuments.Length;
            IEnumerable <string> hotelIds =
                Enumerable.Range(
                    existingDocumentCount + 1,
                    size - existingDocumentCount)
                .Select(id => id.ToString());
            List <SearchDocument> hotels = hotelIds.Select(id => new SearchDocument {
                ["hotelId"] = id
            }).ToList();

            // Upload the empty hotels in batches of 1000 until we're complete
            SearchIndexClient client = resources.GetIndexClient();

            for (int i = 0; i < hotels.Count; i += 1000)
            {
                IEnumerable <SearchDocument> nextHotels = hotels.Skip(i).Take(1000);
                if (!nextHotels.Any())
                {
                    break;
                }
                await client.IndexDocumentsAsync(IndexDocumentsBatch.Upload(nextHotels));

                await resources.WaitForIndexingAsync();
            }

            return(resources);
        }
Ejemplo n.º 2
0
        public async Task RecentlyIndexedDynamicDocument()
        {
            await using SearchResources resources = await SearchResources.CreateWithEmptyHotelsIndexAsync(this);

            Hotel document = SearchResources.TestDocuments[0];

            await resources.GetIndexClient().IndexDocumentsAsync(
                IndexDocumentsBatch.Upload(new[] { document.AsDocument() }));

            await resources.WaitForIndexingAsync();

            Response <Hotel> response = await resources.GetQueryClient().GetDocumentAsync <Hotel>(document.HotelId);

            Assert.AreEqual(document.HotelId, response.Value.HotelId);
        }
Ejemplo n.º 3
0
        public async Task VerifyRoundtrip <T>(
            Func <T, string> getKey,
            T document,
            T expected = default,
            GetDocumentOptions options = null)
        {
            await using SearchResources resources = await SearchResources.CreateWithEmptyHotelsIndexAsync(this);

            await resources.GetIndexClient().IndexDocumentsAsync <T>(
                IndexDocumentsBatch.Upload <T>(new[] { document }));

            await resources.WaitForIndexingAsync();

            Response <T> response = await resources.GetQueryClient().GetDocumentAsync <T>(getKey(document), options);

            // Only validate expected properties
            AssertApproximate(expected ?? document, response.Value);
        }
Ejemplo n.º 4
0
        public async Task Structs()
        {
            await using SearchResources resources = await SearchResources.CreateWithEmptyHotelsIndexAsync(this);

            SimpleStructHotel document = new SimpleStructHotel
            {
                HotelId   = "4",
                HotelName = "Value Inn"
            };

            await resources.GetIndexClient().IndexDocumentsAsync(
                IndexDocumentsBatch.Upload(new[] { document }));

            await resources.WaitForIndexingAsync();

            SearchIndexClient            client   = resources.GetQueryClient();
            Response <SimpleStructHotel> response = await client.GetDocumentAsync <SimpleStructHotel>(document.HotelId);

            Assert.AreEqual(document, response.Value);
        }
Ejemplo n.º 5
0
        public async Task EmptyValuesDynamicDocument()
        {
            await using SearchResources resources = await SearchResources.CreateWithEmptyHotelsIndexAsync(this);

            SearchDocument document =
                new SearchDocument
            {
                ["hotelId"]            = "1",
                ["hotelName"]          = null,
                ["tags"]               = new object[0],
                ["parkingIncluded"]    = null,
                ["lastRenovationDate"] = null,
                ["rating"]             = null,
                ["location"]           = null,
                ["address"]            = null,
                ["rooms"]              = new[]
                {
                    new SearchDocument
                    {
                        ["baseRate"]       = null,
                        ["bedOptions"]     = null,
                        ["sleepsCount"]    = null,
                        ["smokingAllowed"] = null,
                        ["tags"]           = new object[0]
                    }
                }
            };

            await resources.GetIndexClient().IndexDocumentsAsync(
                IndexDocumentsBatch.Upload(new[] { document }));

            await resources.WaitForIndexingAsync();

            Response <SearchDocument> response = await resources.GetQueryClient().GetDocumentAsync((string)document["hotelId"]);

            Assert.AreEqual(document["hotelId"], response.Value["hotelId"]);
        }