Пример #1
0
        public void Has_Href_Property_With_Href()
        {
            var crs = new LinkedCRS(Href);

            Assert.IsTrue(crs.Properties.ContainsKey("href"));
            Assert.AreEqual(Href, crs.Properties["href"]);
        }
Пример #2
0
        public void Has_Type_Property()
        {
            const string type = "ogcwkt";
            var crs = new LinkedCRS(Href, type);

            Assert.IsTrue(crs.Properties.ContainsKey("type"));
            Assert.AreEqual(type, crs.Properties["type"]);
        }
Пример #3
0
        /// <summary>
        ///     Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>
        ///     The object value.
        /// </returns>
        /// <exception cref="Newtonsoft.Json.JsonReaderException">
        ///     CRS must be null or a json object
        ///     or
        ///     CRS must have a "type" property
        /// </exception>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return new UnspecifiedCRS();
            }
            if (reader.TokenType != JsonToken.StartObject)
            {
                throw new JsonReaderException("CRS must be null or a json object");
            }

            var jObject = JObject.Load(reader);

            JToken token;
            if (!jObject.TryGetValue("type", StringComparison.OrdinalIgnoreCase, out token))
            {
                throw new JsonReaderException("CRS must have a \"type\" property");
            }

            var crsType = token.Value<string>();

            if (string.Equals("name", crsType, StringComparison.OrdinalIgnoreCase))
            {
                JObject properties = null;
                if (jObject.TryGetValue("properties", out token))
                {
                    properties = token as JObject;
                }

                if (properties != null)
                {
                    var target = new NamedCRS(properties["name"].ToString());
                    serializer.Populate(jObject.CreateReader(), target);
                    return target;
                }
            }
            else if (string.Equals("link", crsType, StringComparison.OrdinalIgnoreCase))
            {
                var linked = new LinkedCRS(string.Empty);
                serializer.Populate(jObject.CreateReader(), linked);
                return linked;
            }

            return new NotSupportedException(string.Format("Type {0} unexpected.", crsType));
        }
Пример #4
0
 public void Ctor_Throws_ArgumentNullExpection_When_Name_Is_Empty()
 {
     Assert.Throws<ArgumentException>(() => { var crs = new LinkedCRS(string.Empty); });
 }
Пример #5
0
 public void Ctor_Does_Not_Throw_When_Href_Is_Dereferencable_Uri()
 {
     Assert.DoesNotThrow(() => { var crs = new LinkedCRS("data.crs"); });
 }
Пример #6
0
        public void Ctor_Throws_ArgumentExpection_When_Href_Is_Not_Dereferencable_Uri()
        {
            var argumentExpection = Assert.Throws<ArgumentException>(() => { var crs = new LinkedCRS("http://not-a-valid-<>-url"); });

            Assert.AreEqual("must be a dereferenceable URI\r\nParameter name: href", argumentExpection.Message);
        }
Пример #7
0
 public void Ctor_Throws_ArgumentNullExpection_When_Href_Uri_Is_Null()
 {
     Assert.Throws<ArgumentNullException>(() => { var crs = new LinkedCRS((Uri)null); });
 }
Пример #8
0
 public void Has_Correct_Type()
 {
     var crs = new LinkedCRS(Href);
     Assert.AreEqual(CRSType.Link, crs.Type);
 }