Пример #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"));
        }