예제 #1
0
        public void MessageSourceRoundtripTest()
        {
            string         json = JsonConvert.SerializeObject(TelemetryMessageSource.Instance);
            IMessageSource deserializedMessageSource = JsonConvert.DeserializeObject <CustomMessageSource>(json);

            Assert.NotNull(deserializedMessageSource);
            Assert.True(TelemetryMessageSource.Instance.Match(deserializedMessageSource));

            json = JsonConvert.SerializeObject(ModuleMessageSource.Create("module1"));
            deserializedMessageSource = JsonConvert.DeserializeObject <CustomMessageSource>(json);
            Assert.NotNull(deserializedMessageSource);
            Assert.True(TelemetryMessageSource.Instance.Match(deserializedMessageSource));

            json = JsonConvert.SerializeObject(ModuleMessageSource.Create("module1", "output1"));
            deserializedMessageSource = JsonConvert.DeserializeObject <CustomMessageSource>(json);
            Assert.NotNull(deserializedMessageSource);
            Assert.True(TelemetryMessageSource.Instance.Match(deserializedMessageSource));

            json = JsonConvert.SerializeObject(TwinChangeEventMessageSource.Instance);
            deserializedMessageSource = JsonConvert.DeserializeObject <CustomMessageSource>(json);
            Assert.NotNull(deserializedMessageSource);
            Assert.True(TwinChangeEventMessageSource.Instance.Match(deserializedMessageSource));

            IMessageSource customMessageSource = CustomMessageSource.Create("/messages/modules/ModId1/outputs/Op1");

            json = JsonConvert.SerializeObject(customMessageSource);
            deserializedMessageSource = JsonConvert.DeserializeObject <CustomMessageSource>(json);
            Assert.NotNull(deserializedMessageSource);
            Assert.True(customMessageSource.Match(deserializedMessageSource));
        }