public void LinkedCRSConstructorTest1() { const string href = "http://www.compass.ie/"; const string type = "Testtype"; LinkedCRS target = new LinkedCRS(href, type); Assert.AreEqual(href, target.Properties["href"]); Assert.AreEqual(type, target.Properties["type"]); Assert.AreEqual(CRSTypes.Link, target.Type); }
public void LinkedCRSConstructorTest() { Uri href = new Uri("http://www.compass.ie/"); const string type = "Testtype"; LinkedCRS target = new LinkedCRS(href, type); Assert.AreEqual(href.AbsoluteUri, target.Properties["href"]); Assert.AreEqual(type, target.Properties["type"]); Assert.AreEqual(CRSTypes.Link, target.Type); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) { reader.Read(); return null; } if (reader.TokenType != JsonToken.StartObject) throw new ArgumentException("Expected token '{' not found."); reader.Read(); if (!(reader.TokenType == JsonToken.PropertyName && (string) reader.Value == "type")) throw new ArgumentException("Expected token 'type' not found."); reader.Read(); if (reader.TokenType != JsonToken.String) throw new ArgumentException("Expected string value not found."); string crsType = (string)reader.Value; reader.Read(); if (!(reader.TokenType == JsonToken.PropertyName && (string) reader.Value == "properties")) throw new ArgumentException("Expected token 'properties' not found."); reader.Read(); if (reader.TokenType != JsonToken.StartObject) throw new ArgumentException("Expected token '{' not found."); Dictionary<string, object> dictionary = serializer.Deserialize<Dictionary<string, object>>(reader); CRSBase result = null; switch (crsType) { case "link": object href = dictionary["href"]; object type = dictionary["type"]; result = new LinkedCRS((string)href, type != null ? (string)type : ""); break; case "name": object name = dictionary["name"]; result = new NamedCRS((string)name); break; } if (reader.TokenType != JsonToken.EndObject) throw new ArgumentException("Expected token '}' not found."); reader.Read(); if (reader.TokenType != JsonToken.EndObject) throw new ArgumentException("Expected token '}' not found."); reader.Read(); return result; }
private LinkedCRS ParseLinkedCRS() { AssertRead(JsonToken.PropertyName); AssertValue("properties"); AssertRead(JsonToken.StartObject); AssertRead(JsonToken.PropertyName); AssertValue("href"); AssertRead(JsonToken.String); var href = (string)Reader.Value; AssertRead(JsonToken.PropertyName); AssertValue("type"); AssertRead(JsonToken.String); var type = (string)Reader.Value; AssertRead(JsonToken.EndObject); var linkedCrs = new LinkedCRS(href, type); return linkedCrs; }