public void CanIndexDynamicDocuments() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClient(); var batch = new IndexBatch(new[] { new IndexAction( IndexActionType.Upload, new Document() { { "hotelId", "1" }, { "baseRate", 199.0 }, { "description", "Best hotel in town" }, { "descriptionFr", "Meilleur hôtel en ville" }, { "hotelName", "Fancy Stay" }, { "category", "Luxury" }, { "tags", new[] { "pool", "view", "wifi", "concierge" } }, { "parkingIncluded", false }, { "smokingAllowed", false }, { "lastRenovationDate", new DateTimeOffset(2010, 6, 27, 0, 0, 0, TimeSpan.FromHours(-8)) }, { "rating", 5 }, { "location", GeographyPoint.Create(47.678581, -122.131577) } }), new IndexAction( IndexActionType.Upload, new Document() { { "hotelId", "2" }, { "baseRate", 79.99 }, { "description", "Cheapest hotel in town" }, { "descriptionFr", "Hôtel le moins cher en ville" }, { "hotelName", "Roach Motel" }, { "category", "Budget" }, { "tags", new[] { "motel", "budget" } }, { "parkingIncluded", true }, { "smokingAllowed", true }, { "lastRenovationDate", new DateTimeOffset(1982, 4, 28, 0, 0, 0, TimeSpan.Zero) }, { "rating", 1 }, { "location", GeographyPoint.Create(49.678581, -122.131577) } }), new IndexAction( IndexActionType.Merge, new Document() { { "hotelId", "3" }, { "baseRate", 279.99 }, { "description", "Surprisingly expensive" }, { "lastRenovationDate", null } }), new IndexAction(IndexActionType.Delete, new Document() { { "hotelId", "4" } }), new IndexAction( IndexActionType.MergeOrUpload, new Document() { { "hotelId", "5" }, { "baseRate", Double.NaN }, { "hotelName", null }, { "tags", new string[0] } }) }); IndexBatchException e = Assert.Throws <IndexBatchException>(() => client.Documents.Index(batch)); AssertIsPartialFailure(e, batch, "3"); Assert.Equal(5, e.IndexResponse.Results.Count); AssertIndexActionSucceeded("1", e.IndexResponse.Results[0]); AssertIndexActionSucceeded("2", e.IndexResponse.Results[1]); AssertIndexActionFailed("3", e.IndexResponse.Results[2], "Document not found."); AssertIndexActionSucceeded("4", e.IndexResponse.Results[3]); AssertIndexActionSucceeded("5", e.IndexResponse.Results[4]); SearchTestUtilities.WaitForIndexing(); DocumentCountResponse countResponse = client.Documents.Count(); Assert.Equal(HttpStatusCode.OK, countResponse.StatusCode); Assert.Equal(3, countResponse.DocumentCount); }); }
public void CanIndexStaticallyTypedDocuments() { Run(() => { SearchIndexClient client = Data.GetSearchIndexClient(); var batch = IndexBatch.Create(new[] { IndexAction.Create( IndexActionType.Upload, new Hotel() { HotelId = "1", BaseRate = 199.0, Description = "Best hotel in town", DescriptionFr = "Meilleur hôtel en ville", HotelName = "Fancy Stay", Category = "Luxury", Tags = new[] { "pool", "view", "wifi", "concierge" }, ParkingIncluded = false, SmokingAllowed = false, LastRenovationDate = new DateTimeOffset(2010, 6, 27, 0, 0, 0, TimeSpan.FromHours(-8)), Rating = 5, Location = GeographyPoint.Create(47.678581, -122.131577) }), IndexAction.Create( IndexActionType.Upload, new Hotel() { HotelId = "2", BaseRate = 79.99, Description = "Cheapest hotel in town", DescriptionFr = "Hôtel le moins cher en ville", HotelName = "Roach Motel", Category = "Budget", Tags = new[] { "motel", "budget" }, ParkingIncluded = true, SmokingAllowed = true, LastRenovationDate = new DateTimeOffset(1982, 4, 28, 0, 0, 0, TimeSpan.Zero), Rating = 1, Location = GeographyPoint.Create(49.678581, -122.131577) }), IndexAction.Create( IndexActionType.Merge, new Hotel() { HotelId = "3", BaseRate = 279.99, Description = "Surprisingly expensive", LastRenovationDate = null }), IndexAction.Create(IndexActionType.Delete, new Hotel() { HotelId = "4" }), IndexAction.Create( IndexActionType.MergeOrUpload, new Hotel() { HotelId = "5", BaseRate = Double.NaN, HotelName = null, Tags = new string[0] }) }); IndexBatchException e = Assert.Throws <IndexBatchException>(() => client.Documents.Index(batch)); AssertIsPartialFailure(e, batch, "3"); Assert.Equal(5, e.IndexResponse.Results.Count); AssertIndexActionSucceeded("1", e.IndexResponse.Results[0]); AssertIndexActionSucceeded("2", e.IndexResponse.Results[1]); AssertIndexActionFailed("3", e.IndexResponse.Results[2], "Document not found."); AssertIndexActionSucceeded("4", e.IndexResponse.Results[3]); AssertIndexActionSucceeded("5", e.IndexResponse.Results[4]); SearchTestUtilities.WaitForIndexing(); DocumentCountResponse countResponse = client.Documents.Count(); Assert.Equal(HttpStatusCode.OK, countResponse.StatusCode); Assert.Equal(3, countResponse.DocumentCount); }); }