Esempio n. 1
0
        public void TestModuleMessageSource()
        {
            Assert.True(ModuleMessageSource.IsTelemetry());

            Assert.False(ModuleMessageSource.Match(TelemetryMessageSource.Instance));
            Assert.False(ModuleMessageSource.Match(TwinChangeEventMessageSource.Instance));

            ModuleMessageSource matchingModuleMessageSource = ModuleMessageSource.Create("ModId1", "Op1");

            Assert.True(ModuleMessageSource.Match(matchingModuleMessageSource));
            Assert.True(matchingModuleMessageSource.Match(ModuleMessageSource));

            ModuleMessageSource unmatchedModuleMessageSource = ModuleMessageSource.Create("ModId2", "Op2");

            Assert.False(ModuleMessageSource.Match(unmatchedModuleMessageSource));
            Assert.False(unmatchedModuleMessageSource.Match(ModuleMessageSource));
        }
        public static IEnumerable <object[]> GetMessageSourceSystemProperties()
        {
            var theoryData = new List <object[]>();

            theoryData.Add(
                new object[]
            {
                new Dictionary <string, string>
                {
                    [SystemProperties.MessageType] = Constants.TwinChangeNotificationMessageType
                },
                TwinChangeEventMessageSource.Instance
            });

            theoryData.Add(
                new object[]
            {
                new Dictionary <string, string>
                {
                    [SystemProperties.ConnectionModuleId] = "module1",
                    [SystemProperties.OutputName]         = "output1"
                },
                ModuleMessageSource.Create("module1", "output1")
            });

            theoryData.Add(
                new object[]
            {
                new Dictionary <string, string>
                {
                    [SystemProperties.ConnectionModuleId] = "module1",
                    [SystemProperties.OutputName]         = "output1"
                },
                ModuleMessageSource.Create("module1", "output1")
            });

            theoryData.Add(
                new object[]
            {
                new Dictionary <string, string>
                {
                    [SystemProperties.ConnectionModuleId] = "module1",
                },
                ModuleMessageSource.Create("module1")
            });

            theoryData.Add(
                new object[]
            {
                new Dictionary <string, string>(),
                TelemetryMessageSource.Instance
            });

            return(theoryData);
        }
Esempio n. 3
0
 internal IMessageSource GetMessageSource(IDictionary <string, string> systemProperties)
 {
     if (systemProperties.TryGetValue(SystemProperties.MessageType, out string messageType) &&
         messageType.Equals(Constants.TwinChangeNotificationMessageType, StringComparison.OrdinalIgnoreCase))
     {
         return(TwinChangeEventMessageSource.Instance);
     }
     else if (systemProperties.TryGetValue(SystemProperties.ConnectionModuleId, out string moduleId))
     {
         return(systemProperties.TryGetValue(SystemProperties.OutputName, out string outputName)
             ? ModuleMessageSource.Create(moduleId, outputName)
             : ModuleMessageSource.Create(moduleId));
     }
     else
     {
         return(TelemetryMessageSource.Instance);
     }
 }