Serialize() public méthode

public Serialize ( ) : string
Résultat string
Exemple #1
0
        public void TestMsgQuerySerialization()
        {
            var msgQuery = new MsgQuery();
            msgQuery.Id = "uuid";
            msgQuery.Capability = "weather";
            msgQuery.Action = "get_temperature";
            var instanceIds = new List<string>();
            instanceIds.Add("xxxx");
            instanceIds.Add("xx2");
            msgQuery.InstanceId = instanceIds;
            var data = new Dictionary<string, object>();
            data["scale"] = "fahrenheit";
            var inner = new Dictionary<string, object>();
            inner["k"] = "v";
            data["other"] = inner;
            msgQuery.Data = data;

            string json = msgQuery.Serialize();
            Debug.WriteLine(json);

            Assert.IsFalse(json.IndexOf("\"data\":null") >= 0, "Sould not contain null for data");
            Assert.IsFalse(json.IndexOf("KeyValuePairOf") >= 0, "Should not have strange toString");
            Assert.IsFalse(json.IndexOf("\"data\":[]") >= 0, "Should not have empty array for data");
        }