Ejemplo n.º 1
0
        public void NamedCrsSerialization()
        {
            NamedCrs testObj = new NamedCrs("name");
            string   result  = ContractObjectToXml(testObj);

            Assert.IsTrue(VerifySerialization(result, testObj));
        }
Ejemplo n.º 2
0
        public void NamedCrsEquals()
        {
            NamedCrs namedCrs1 = Crs.Named("AName");
            NamedCrs namedCrs2 = Crs.Named("AName");
            NamedCrs namedCrs3 = Crs.Named("AnotherName");

            Assert.AreEqual(namedCrs1, namedCrs2);
            Assert.AreEqual(namedCrs1.GetHashCode(), namedCrs2.GetHashCode());
            Assert.AreNotEqual(namedCrs1, namedCrs3);
            Assert.AreNotEqual(namedCrs1.GetHashCode(), namedCrs3.GetHashCode());
        }
Ejemplo n.º 3
0
        public void NamedCrsSerialization()
        {
            NamedCrs namedCrs = (NamedCrs)JsonConvert.DeserializeObject <Crs>(@"{'type':'name', 'properties':{'name':'AName'}}");

            Assert.AreEqual("AName", namedCrs.Name);

            string   json      = JsonConvert.SerializeObject(namedCrs);
            NamedCrs namedCrs1 = (NamedCrs)JsonConvert.DeserializeObject <Crs>(json);

            Assert.AreEqual(namedCrs1, namedCrs);
        }
        /// <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;
            }
        }
Ejemplo n.º 5
0
        public void NamedCrsConstructor()
        {
            NamedCrs namedCrs = Crs.Named("NamedCrs");

            Assert.AreEqual("NamedCrs", namedCrs.Name);
        }