public void LinkedCrsSerialization() { LinkedCrs testObj = new LinkedCrs("href", "hrefType"); string result = ContractObjectToXml(testObj); Assert.IsTrue(VerifySerialization(result, testObj)); }
public void LinkedCrsConstructor() { LinkedCrs crs = Crs.Linked("http://foo.com"); Assert.AreEqual("http://foo.com", crs.Href); Assert.IsNull(crs.HrefType); crs = Crs.Linked("http://foo.com", "link"); Assert.AreEqual("http://foo.com", crs.Href); Assert.AreEqual("link", crs.HrefType); }
public void LinkedCrsSerialization() { LinkedCrs linkedCrs = (LinkedCrs)JsonConvert.DeserializeObject <Crs>(@"{'type':'link', 'properties':{'href':'http://foo', 'type':'link'}}"); Assert.AreEqual("http://foo", linkedCrs.Href); Assert.AreEqual(CoordinateReferenceScheme.Linked, linkedCrs.Type); string json = JsonConvert.SerializeObject(linkedCrs); LinkedCrs linkedCrs1 = (LinkedCrs)JsonConvert.DeserializeObject <Crs>(json); Assert.AreEqual(linkedCrs1, linkedCrs); }
/// <summary> /// Writes the JSON representation of the object. /// </summary> /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter" /> to write to.</param> /// <param name="value">The value.</param> /// <param name="serializer">The calling serializer.</param> public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { Crs crs = (Crs)value; switch (crs.Type) { case CrsType.Linked: LinkedCrs linkedCrs = (LinkedCrs)crs; writer.WriteStartObject(); writer.WritePropertyName("type"); writer.WriteValue("link"); writer.WritePropertyName("properties"); writer.WriteStartObject(); writer.WritePropertyName("href"); writer.WriteValue(linkedCrs.Href); if (linkedCrs.HrefType != null) { writer.WritePropertyName("type"); writer.WriteValue(linkedCrs.HrefType); } writer.WriteEndObject(); writer.WriteEndObject(); break; case CrsType.Named: NamedCrs namedCrs = (NamedCrs)crs; writer.WriteStartObject(); writer.WritePropertyName("type"); writer.WriteValue("name"); writer.WritePropertyName("properties"); writer.WriteStartObject(); writer.WritePropertyName("name"); writer.WriteValue(namedCrs.Name); writer.WriteEndObject(); writer.WriteEndObject(); break; case CrsType.Unspecified: writer.WriteNull(); break; } }
public void LinkedCrsEquals() { LinkedCrs namedCrs1 = Crs.Linked("AName", "type"); LinkedCrs namedCrs2 = Crs.Linked("AName", "type"); LinkedCrs namedCrs3 = Crs.Linked("AnotherName", "type"); LinkedCrs namedCrs4 = Crs.Linked("AName", "anotherType"); LinkedCrs namedCrs5 = Crs.Linked("AName"); Assert.AreEqual(namedCrs1, namedCrs2); Assert.AreEqual(namedCrs1.GetHashCode(), namedCrs2.GetHashCode()); Assert.AreNotEqual(namedCrs1, namedCrs3); Assert.AreNotEqual(namedCrs1.GetHashCode(), namedCrs3.GetHashCode()); Assert.AreNotEqual(namedCrs1, namedCrs4); Assert.AreNotEqual(namedCrs1.GetHashCode(), namedCrs4.GetHashCode()); Assert.AreNotEqual(namedCrs1, namedCrs5); Assert.AreNotEqual(namedCrs1.GetHashCode(), namedCrs5.GetHashCode()); }