Exemple #1
0
        public void CanIndexAndRetrieveWithCustomContractResolver()
        {
            Run(() =>
            {
                SearchIndexClient client = Data.GetSearchIndexClient();
                var resolver             = new MyCustomContractResolver();
                client.SerializationSettings.ContractResolver   = resolver;
                client.DeserializationSettings.ContractResolver = resolver;

                var expectedHotel =
                    new LoudHotel()
                {
                    HOTELID           = "1",
                    BASERATE          = 0,
                    DESCRIPTION       = "Best hotel in town",
                    DESCRIPTIONFRENCH = "Meilleur hôtel en ville",
                    HOTELNAME         = "Fancy Stay",
                    CATEGORY          = "Luxury",
                    TAGS               = new[] { "pool", "view", "wifi", "concierge" },
                    PARKINGINCLUDED    = true,
                    SMOKINGALLOWED     = false,
                    LASTRENOVATIONDATE = new DateTimeOffset(2010, 6, 27, 0, 0, 0, TimeSpan.FromHours(-8)),
                    RATING             = 5,
                    LOCATION           = GeographyPoint.Create(47.678581, -122.131577)
                };

                DocumentIndexResult result = client.Documents.Index(IndexBatch.Upload(new[] { expectedHotel }));

                Assert.Equal(1, result.Results.Count);
                AssertIndexActionSucceeded("1", result.Results[0], 201);

                SearchTestUtilities.WaitForIndexing();

                Assert.Equal(1, client.Documents.Count());

                LoudHotel actualHotel = client.Documents.Get <LoudHotel>(expectedHotel.HOTELID);

                Assert.Equal(expectedHotel, actualHotel);
            });
        }
Exemple #2
0
        public void CanIndexAndRetrieveModelWithExtraProperties()
        {
            Run(() =>
            {
                SearchServiceClient serviceClient = Data.GetSearchServiceClient();

                Index index = Book.DefineIndex();
                serviceClient.Indexes.Create(index);

                SearchIndexClient client = Data.GetSearchIndexClient(index.Name);
                var resolver             = new MyCustomContractResolver();
                client.SerializationSettings.ContractResolver   = resolver;
                client.DeserializationSettings.ContractResolver = resolver;

                string bookJson =
                    @"{ ""ISBN"": ""123"", ""Title"": ""The Hobbit"", ""Author"": ""J.R.R.Tolkien"", ""Rating"": 5 }";

                // Real customers would just use JsonConvert, but that would break the test.
                var expectedBook = SafeJsonConvert.DeserializeObject <ReviewedBook>(bookJson);

                DocumentIndexResult result = client.Documents.Index(IndexBatch.Upload(new[] { expectedBook }));

                Assert.Equal(1, result.Results.Count);
                AssertIndexActionSucceeded("123", result.Results[0], 201);

                SearchTestUtilities.WaitForIndexing();

                Assert.Equal(1, client.Documents.Count());

                ReviewedBook actualBook = client.Documents.Get <ReviewedBook>(expectedBook.ISBN);

                Assert.Equal(0, actualBook.Rating);
                actualBook.Rating = 5;
                Assert.Equal(expectedBook, actualBook);
            });
        }
Exemple #3
0
        public void CanSetExplicitNullsInStaticallyTypedDocuments()
        {
            Run(() =>
            {
                SearchIndexClient client = Data.GetSearchIndexClient();

                // This is just so we can use the LoudHotel class instead of Hotel since it has per-property
                // NullValueHandling set.
                var resolver = new MyCustomContractResolver();
                client.SerializationSettings.ContractResolver   = resolver;
                client.DeserializationSettings.ContractResolver = resolver;

                var originalDoc =
                    new LoudHotel()
                {
                    HOTELID           = "1",
                    BASERATE          = 199.0,
                    DESCRIPTION       = "Best hotel in town",
                    DESCRIPTIONFRENCH = "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)
                };

                var updatedDoc =
                    new LoudHotel()
                {
                    HOTELID            = "1",
                    BASERATE           = 99.0,
                    DESCRIPTION        = null,
                    CATEGORY           = null, // This property doesn't have NullValueHandling.Include, so this should have no effect.
                    TAGS               = new[] { "pool", "view", "wifi" },
                    PARKINGINCLUDED    = true,
                    LASTRENOVATIONDATE = new DateTimeOffset(2010, 6, 27, 0, 0, 0, TimeSpan.FromHours(-8)),
                    RATING             = 4,
                    LOCATION           = null
                };

                var expectedDoc =
                    new LoudHotel()
                {
                    HOTELID           = "1",
                    BASERATE          = 99.0,
                    DESCRIPTION       = null,
                    DESCRIPTIONFRENCH = "Meilleur hôtel en ville",
                    HOTELNAME         = "Fancy Stay",
                    CATEGORY          = "Luxury",
                    TAGS               = new[] { "pool", "view", "wifi" },
                    PARKINGINCLUDED    = true,
                    SMOKINGALLOWED     = false,
                    LASTRENOVATIONDATE = new DateTimeOffset(2010, 6, 27, 0, 0, 0, TimeSpan.FromHours(-8)),
                    RATING             = 4,
                    LOCATION           = null
                };

                client.Documents.Index(IndexBatch.Upload(new[] { originalDoc }));
                SearchTestUtilities.WaitForIndexing();

                client.Documents.Index(IndexBatch.Merge(new[] { updatedDoc }));
                SearchTestUtilities.WaitForIndexing();

                LoudHotel actualDoc = client.Documents.Get <LoudHotel>("1");

                Assert.Equal(expectedDoc, actualDoc);

                client.Documents.Index(IndexBatch.Upload(new[] { originalDoc }));
                SearchTestUtilities.WaitForIndexing();

                actualDoc = client.Documents.Get <LoudHotel>("1");

                Assert.Equal(originalDoc, actualDoc);
            });
        }