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);
        }
        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);
        }
        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);
        }
Пример #4
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,
                ["geoLocation"]        = null,
                ["address"]            = null,
                ["rooms"]              = new[]
                {
                    new SearchDocument
                    {
                        ["baseRate"]       = null,
                        ["bedOptions"]     = null,
                        ["sleepsCount"]    = null,
                        ["smokingAllowed"] = null,
                        ["tags"]           = new object[0]
                    }
                }
            };

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

            await resources.WaitForIndexingAsync();

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

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