コード例 #1
0
        public object Visit(GeolocationField field)
        {
            var geolocation = (JObject)Value;

            foreach (var property in geolocation.Properties())
            {
                if (!string.Equals(property.Name, "latitude", StringComparison.OrdinalIgnoreCase) &&
                    !string.Equals(property.Name, "longitude", StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidCastException("Geolocation can only have latitude and longitude property.");
                }
            }

            var lat = (double)geolocation["latitude"];
            var lon = (double)geolocation["longitude"];

            if (!lat.IsBetween(-90, 90))
            {
                throw new InvalidCastException("Latitude must be between -90 and 90.");
            }

            if (!lon.IsBetween(-180, 180))
            {
                throw new InvalidCastException("Longitude must be between -180 and 180.");
            }

            return(Value);
        }
コード例 #2
0
        public JsonProperty Visit(GeolocationField field)
        {
            return(CreateProperty(field, jsonProperty =>
            {
                var geolocationSchema = new JsonSchema4
                {
                    AllowAdditionalProperties = false
                };

                geolocationSchema.Properties.Add("latitude", new JsonProperty
                {
                    Type = JsonObjectType.Number,
                    Minimum = -90,
                    Maximum = 90,
                    IsRequired = true
                });

                geolocationSchema.Properties.Add("longitude", new JsonProperty
                {
                    Type = JsonObjectType.Number,
                    Minimum = -180,
                    Maximum = 180,
                    IsRequired = true
                });

                var schemaReference = schemaResolver("GeolocationDto", geolocationSchema);

                jsonProperty.Type = JsonObjectType.Object;
                jsonProperty.Reference = schemaReference;
            }));
        }
コード例 #3
0
        public void Should_get_default_value_from_geolocation_field()
        {
            var field =
                new GeolocationField(1, "1", Partitioning.Invariant,
                                     new GeolocationFieldProperties());

            Assert.Equal(JValue.CreateNull(), DefaultValueFactory.CreateDefaultValue(field, Now));
        }
コード例 #4
0
ファイル: GeolocationFieldTests.cs プロジェクト: ifle/squidex
        public async Task Should_not_add_error_if_geolocation_is_valid_null()
        {
            var sut = new GeolocationField(1, "my-geolocation", Partitioning.Invariant);

            await sut.ValidateAsync(CreateValue(JValue.CreateNull()), errors);

            Assert.Empty(errors);
        }
コード例 #5
0
ファイル: GeolocationFieldTests.cs プロジェクト: ifle/squidex
        public async Task Should_add_errors_if_geolocation_is_required()
        {
            var sut = new GeolocationField(1, "my-geolocation", Partitioning.Invariant, new GeolocationFieldProperties {
                IsRequired = true
            });

            await sut.ValidateAsync(CreateValue(JValue.CreateNull()), errors);

            errors.ShouldBeEquivalentTo(
                new[] { "<FIELD> is required." });
        }
コード例 #6
0
ファイル: GeolocationFieldTests.cs プロジェクト: ifle/squidex
        public async Task Should_not_add_error_if_geolocation_is_valid()
        {
            var sut = new GeolocationField(1, "my-geolocation", Partitioning.Invariant);

            var geolocation = new JObject(
                new JProperty("latitude", 0),
                new JProperty("longitude", 0));

            await sut.ValidateAsync(CreateValue(geolocation), errors);

            Assert.Empty(errors);
        }
コード例 #7
0
ファイル: GeolocationFieldTests.cs プロジェクト: ifle/squidex
        public async Task Should_add_errors_if_geolocation_has_invalid_longitude()
        {
            var sut = new GeolocationField(1, "my-geolocation", Partitioning.Invariant, new GeolocationFieldProperties {
                IsRequired = true
            });

            var geolocation = new JObject(
                new JProperty("latitude", 0),
                new JProperty("longitude", 200));

            await sut.ValidateAsync(CreateValue(geolocation), errors);

            errors.ShouldBeEquivalentTo(
                new[] { "<FIELD> is not a valid value." });
        }
コード例 #8
0
 public IEdmTypeReference Visit(GeolocationField field)
 {
     return(null);
 }
コード例 #9
0
ファイル: GeolocationFieldTests.cs プロジェクト: ifle/squidex
        public void Should_instantiate_field()
        {
            var sut = new GeolocationField(1, "my-geolocation", Partitioning.Invariant);

            Assert.Equal("my-geolocation", sut.Name);
        }