Exemplo n.º 1
0
        public void InternalValidation_PayloadConverter_ExtractResourceOutputValue()
        {
            // 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
            {
                new OutputItem { Key = "boolean", Value = "true" },
                new OutputItem { Key = "time1", Value = time1.ToString(CultureInfo.InvariantCulture) },
                new OutputItem { Key = "time2", Value = time2.ToString(CultureInfo.InvariantCulture) },
                new OutputItem { Key = "string", Value = "value" },
                new OutputItem { Key = "number", Value = "7" },
                new OutputItem { Key = "uri", Value = new Uri("https://some/long/uri/").AbsoluteUri },
            };

            XElement resourceElement = ServerSerializer.SerializeResource(res);

            // Validates nonexisting properties
            var payloadConverter = new PayloadConverter();
            Assert.AreEqual(DateTime.MinValue, payloadConverter.ExtractClusterPropertyDateTimeValue(resourceElement, Enumerable.Empty<KeyValuePair<string, string>>(), "nonexist"));
            Assert.AreEqual(null, payloadConverter.ExtractResourceOutputStringValue(resourceElement, "nonexist"));
            Assert.AreEqual(0, payloadConverter.ExtractClusterPropertyIntValue(resourceElement, Enumerable.Empty<KeyValuePair<string, string>>(), "nonexist"));

            // Validates existing properties
            Assert.AreEqual(time1, payloadConverter.ExtractClusterPropertyDateTimeValue(resourceElement, Enumerable.Empty<KeyValuePair<string, string>>(), "time1"));
            Assert.AreEqual(time2, payloadConverter.ExtractClusterPropertyDateTimeValue(resourceElement, Enumerable.Empty<KeyValuePair<string, string>>(), "time2"));
            Assert.AreEqual("value", payloadConverter.ExtractResourceOutputStringValue(resourceElement, "string"));
            Assert.AreEqual(7, payloadConverter.ExtractClusterPropertyIntValue(resourceElement, Enumerable.Empty<KeyValuePair<string, string>>(), "number"));
        }
Exemplo n.º 2
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"));
        }