public void PASS_CreateFilter()
        {
            GeoHashCellFilter filter = new GeoHashCellFilter("field",
                new CoordinatePoint(1.1, 2.2),
                3,
                true);

            Assert.IsNotNull(filter);
            Assert.AreEqual("field", filter.Field);
            Assert.AreEqual(1.1, filter.GeoHash.Latitude);
            Assert.AreEqual(2.2, filter.GeoHash.Longitude);
            Assert.AreEqual((int)3, (int)filter.GeoHashPrecision.Value);
            Assert.AreEqual(true, filter.AllowNeighbors);
        }
 public void FAIL_CreateFilter_GeoHashPrecision()
 {
     try
     {
         GeoHashCellFilter filter = new GeoHashCellFilter("field",
                 new CoordinatePoint(1.1, 2.2),
                 0,
                 true);
         Assert.Fail();
     }
     catch (ArgumentOutOfRangeException ex)
     {
         Assert.AreEqual("geoHashPrecision", ex.ParamName);
     }
 }
 public void FAIL_CreateFilter_GeoHash()
 {
     try
     {
         GeoHashCellFilter filter = new GeoHashCellFilter("field",
                 null,
                 3,
                 true);
         Assert.Fail();
     }
     catch (ArgumentNullException ex)
     {
         Assert.AreEqual("geoHash", ex.ParamName);
     }
 }
 public void FAIL_CreateFilter_Field()
 {
     try
     {
         GeoHashCellFilter filter = new GeoHashCellFilter(null,
                 new CoordinatePoint(1.1, 2.2),
                 3,
                 true);
         Assert.Fail();
     }
     catch (ArgumentNullException ex)
     { 
         Assert.AreEqual("field", ex.ParamName);
     }
 }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Dictionary<string, object> fieldDict = serializer.Deserialize<Dictionary<string, object>>(reader);
            if (fieldDict.ContainsKey(FilterTypeEnum.GeoHashCell.ToString()))
                fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.First().Value.ToString());

            KeyValuePair<string, object> fieldKvp = fieldDict.FirstOrDefault(x => !_KnownFields.Contains(x.Key, StringComparer.OrdinalIgnoreCase));

            if (string.IsNullOrWhiteSpace(fieldKvp.Key))
                throw new RequiredPropertyMissingException("GeoPointProperty");

            GeoHashCellFilter filter = null;
            CoordinatePoint geoHash = CoordinatePointSerializer.DeserializeCoordinatePoint(fieldDict.GetString(fieldKvp.Key));
            bool useNeighbors = fieldDict.GetBool(_NEIGHBORS);

            // try to create the geo hash cell filter with standard precision, if that fails use distance precision
            try
            {
                filter = new GeoHashCellFilter(
                                    fieldKvp.Key, 
                                    geoHash, 
                                    fieldDict.GetInt32(_PRECISION), 
                                    useNeighbors);
            }
            catch(ParsingException<Int32> ex)
            {
                filter = new GeoHashCellFilter(
                                    fieldKvp.Key,
                                    geoHash,
                                    new DistanceValue(fieldDict.GetString(_PRECISION)),
                                    useNeighbors);
            }

            FilterSerializer.DeserializeBaseValues(filter, _CACHE_DEFAULT, fieldDict);

            return filter;
        }
        public void PASS_Serializer()
        {
            GeoHashCellFilter filter = new GeoHashCellFilter("field",
                new CoordinatePoint(1.1, 2.2),
                3,
                true);

            string json = JsonConvert.SerializeObject(filter);
            Assert.IsNotNull(json);

            string expectedJson = "{\"geohash_cell\":{\"field\":{\"lat\":1.1,\"lon\":2.2},\"precision\":3,\"neighbors\":true}}";
            Assert.AreEqual(expectedJson, json);
        }