示例#1
0
        public void InternalValidation_PayloadConverter_ExtractIntrinsicSettingsValue()
        {
            // During serialization\deserialization it loses ms precission. Therefore using ms-less times 
            DateTime time1 = TruncateMiliseconds(DateTime.UtcNow), time2 = TruncateMiliseconds(DateTime.Now);

            // Creates a response
            var res = new Resource();
            res.OutputItems = new OutputItemList();
            var intrinsicSettings = new List<KeyValuePair<string, string>>()
            {
                new KeyValuePair<string,string>("boolean", "true"),
                new KeyValuePair<string,string>("time1", time1.ToString(CultureInfo.InvariantCulture)),
                new KeyValuePair<string,string>("time2", time2.ToString(CultureInfo.InvariantCulture)),
                new KeyValuePair<string,string>("string", "value"),
                new KeyValuePair<string,string>("number", "7")
            };

            XElement resourceElement = ServerSerializer.SerializeResource(res, intrinsicSettings);

            // Validates nonexisting properties
            var payloadConverter = new PayloadConverter();
            Assert.AreEqual(DateTime.MinValue, payloadConverter.ExtractClusterPropertyDateTimeValue(resourceElement, intrinsicSettings, "nonexist"));
            Assert.AreEqual(null, payloadConverter.GetClusterProperty(resourceElement, intrinsicSettings, "nonexist"));
            Assert.AreEqual(0, payloadConverter.ExtractClusterPropertyIntValue(resourceElement, intrinsicSettings, "nonexist"));

            // Validates existing properties
            Assert.AreEqual(time1, payloadConverter.ExtractClusterPropertyDateTimeValue(resourceElement, intrinsicSettings, "time1"));
            Assert.AreEqual(time2, payloadConverter.ExtractClusterPropertyDateTimeValue(resourceElement, intrinsicSettings, "time2"));
            Assert.AreEqual("value", payloadConverter.GetClusterProperty(resourceElement, intrinsicSettings, "string"));
            Assert.AreEqual(7, payloadConverter.ExtractClusterPropertyIntValue(resourceElement, intrinsicSettings, "number"));
        }