Ejemplo n.º 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);
            });
        }
Ejemplo n.º 2
0
        public override bool Equals(object obj)
        {
            LoudHotel other = obj as LoudHotel;

            if (other == null)
            {
                return(false);
            }

            return
                (HOTELID == other.HOTELID &&
                 BASERATE == other.BASERATE &&
                 DESCRIPTION == other.DESCRIPTION &&
                 DESCRIPTIONFRENCH == other.DESCRIPTIONFRENCH &&
                 HOTELNAME == other.HOTELNAME &&
                 CATEGORY == other.CATEGORY &&
                 ((TAGS == null) ? (other.TAGS == null || other.TAGS.Length == 0) : TAGS.SequenceEqual(other.TAGS ?? new string[0])) &&
                 PARKINGINCLUDED == other.PARKINGINCLUDED &&
                 SMOKINGALLOWED == other.SMOKINGALLOWED &&
                 LASTRENOVATIONDATE == other.LASTRENOVATIONDATE &&
                 RATING == other.RATING &&
                 ((LOCATION == null) ? other.LOCATION == null : LOCATION.Equals(other.LOCATION)));
        }
Ejemplo n.º 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);
            });
        }